Use global licenses with local symlinks
This commit is contained in:
parent
6906911e85
commit
2a11cb8b76
@ -898,6 +898,11 @@ def do_install(self,
|
|||||||
def build_process():
|
def build_process():
|
||||||
"""Forked for each build. Has its own process and python
|
"""Forked for each build. Has its own process and python
|
||||||
module space set up by build_environment.fork()."""
|
module space set up by build_environment.fork()."""
|
||||||
|
|
||||||
|
# Set up a global license if one is required
|
||||||
|
if self.license_required:
|
||||||
|
self.set_up_license()
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
if not fake:
|
if not fake:
|
||||||
if not skip_patch:
|
if not skip_patch:
|
||||||
@ -960,9 +965,9 @@ def build_process():
|
|||||||
self._total_time = time.time() - start_time
|
self._total_time = time.time() - start_time
|
||||||
build_time = self._total_time - self._fetch_time
|
build_time = self._total_time - self._fetch_time
|
||||||
|
|
||||||
# Set up license information
|
# Symlink local license to global license if one is required
|
||||||
if self.license_required:
|
if self.license_required and self.license_files:
|
||||||
self.set_up_license()
|
self.symlink_license()
|
||||||
|
|
||||||
tty.msg("Successfully installed %s" % self.name,
|
tty.msg("Successfully installed %s" % self.name,
|
||||||
"Fetch: %s. Build: %s. Total: %s." %
|
"Fetch: %s. Build: %s. Total: %s." %
|
||||||
@ -1014,16 +1019,38 @@ def check_paths(path_list, filetype, predicate):
|
|||||||
"Install failed for %s. Nothing was installed!" % self.name)
|
"Install failed for %s. Nothing was installed!" % self.name)
|
||||||
|
|
||||||
|
|
||||||
|
def global_license_file(self):
|
||||||
|
"""Returns the path where a global license file should be stored."""
|
||||||
|
if not self.license_files:
|
||||||
|
return
|
||||||
|
spack_root = ancestor(__file__, 4)
|
||||||
|
global_license_dir = join_path(spack_root, 'etc', 'spack', 'licenses')
|
||||||
|
return join_path(global_license_dir, self.name,
|
||||||
|
os.path.basename(self.license_files[0]))
|
||||||
|
|
||||||
|
|
||||||
|
def local_license_symlink(self):
|
||||||
|
"""Returns the path where a local license file is searched for."""
|
||||||
|
if not self.license_files:
|
||||||
|
return
|
||||||
|
return join_path(self.prefix, self.license_files[0])
|
||||||
|
|
||||||
|
|
||||||
def set_up_license(self):
|
def set_up_license(self):
|
||||||
"""Prompt the user, letting them know that a license is required."""
|
"""Prompt the user, letting them know that a license is required."""
|
||||||
|
|
||||||
# If the license can be stored in a file, create one
|
# If the license can be stored in a file, create one
|
||||||
if self.license_files:
|
if self.license_files:
|
||||||
# Use the first file listed in license_files
|
license_path = self.global_license_file()
|
||||||
license_path = self.prefix + '/' + self.license_files[0]
|
if not os.path.exists(license_path):
|
||||||
self.write_license_file(license_path)
|
# Create a new license file
|
||||||
# Open up file in user's favorite $EDITOR for editing
|
self.write_license_file(license_path)
|
||||||
spack.editor(license_path)
|
# Open up file in user's favorite $EDITOR for editing
|
||||||
tty.msg("Added license file %s" % license_path)
|
spack.editor(license_path)
|
||||||
|
tty.msg("Added global license file %s" % license_path)
|
||||||
|
else:
|
||||||
|
# Use already existing license file
|
||||||
|
tty.msg("Found already existing license %s" % license_path)
|
||||||
|
|
||||||
# If not a file, what about an environment variable?
|
# If not a file, what about an environment variable?
|
||||||
elif self.license_vars:
|
elif self.license_vars:
|
||||||
@ -1045,12 +1072,17 @@ def set_up_license(self):
|
|||||||
def write_license_file(self, license_path):
|
def write_license_file(self, license_path):
|
||||||
"""Writes empty license file.
|
"""Writes empty license file.
|
||||||
|
|
||||||
Comments give suggestions on alternative methods of installing
|
Comments give suggestions on alternative methods of
|
||||||
a license."""
|
installing a license."""
|
||||||
|
|
||||||
comment = self.license_comment
|
comment = self.license_comment
|
||||||
|
|
||||||
|
# Global license directory may not already exist
|
||||||
|
if not os.path.exists(os.path.dirname(license_path)):
|
||||||
|
os.makedirs(os.path.dirname(license_path))
|
||||||
license = open(license_path, 'w')
|
license = open(license_path, 'w')
|
||||||
|
|
||||||
|
# License files
|
||||||
license.write("""\
|
license.write("""\
|
||||||
{0} A license is required to use {1}.
|
{0} A license is required to use {1}.
|
||||||
{0}
|
{0}
|
||||||
@ -1065,6 +1097,7 @@ def write_license_file(self, license_path):
|
|||||||
|
|
||||||
license.write("{0}\n".format(comment))
|
license.write("{0}\n".format(comment))
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
if self.license_vars:
|
if self.license_vars:
|
||||||
license.write("""\
|
license.write("""\
|
||||||
{0} Alternatively, use one of the following environment variable(s):
|
{0} Alternatively, use one of the following environment variable(s):
|
||||||
@ -1084,6 +1117,7 @@ def write_license_file(self, license_path):
|
|||||||
{0}
|
{0}
|
||||||
""".format(comment, self.name))
|
""".format(comment, self.name))
|
||||||
|
|
||||||
|
# Documentation
|
||||||
if self.license_url:
|
if self.license_url:
|
||||||
license.write("""\
|
license.write("""\
|
||||||
{0} For further information on how to acquire a license, please refer to:
|
{0} For further information on how to acquire a license, please refer to:
|
||||||
@ -1100,6 +1134,15 @@ def write_license_file(self, license_path):
|
|||||||
license.close()
|
license.close()
|
||||||
|
|
||||||
|
|
||||||
|
def symlink_license(self):
|
||||||
|
"""Create a local symlink that points to the global license file."""
|
||||||
|
target = self.global_license_file()
|
||||||
|
link_name = self.local_license_symlink()
|
||||||
|
if os.path.exists(target):
|
||||||
|
os.symlink(target, link_name)
|
||||||
|
tty.msg("Added local symlink %s to global license file" % link_name)
|
||||||
|
|
||||||
|
|
||||||
def do_install_dependencies(self, **kwargs):
|
def do_install_dependencies(self, **kwargs):
|
||||||
# Pass along paths of dependencies here
|
# Pass along paths of dependencies here
|
||||||
for dep in self.spec.dependencies.values():
|
for dep in self.spec.dependencies.values():
|
||||||
|
Loading…
Reference in New Issue
Block a user