Skip to content

Commit

Permalink
Revert "features: Remove stage symlinks (spack#12072)"
Browse files Browse the repository at this point in the history
This reverts commit 0ea6e0f.
  • Loading branch information
scheibelp committed Aug 20, 2019
1 parent aebc44a commit 6dac08a
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 417 deletions.
26 changes: 8 additions & 18 deletions etc/spack/defaults/config.yaml
Expand Up @@ -37,28 +37,18 @@ config:

# Temporary locations Spack can try to use for builds.
#
# Recommended options are given below.
# Spack will use the first one it finds that exists and is writable.
# You can use $tempdir to refer to the system default temp directory
# (as returned by tempfile.gettempdir()).
#
# Builds can be faster in temporary directories on some (e.g., HPC) systems.
# Specifying `$tempdir` will ensure use of the system default temporary
# directory (as returned by `tempfile.gettempdir()`). Spack will append
# `spack-stage` and, if the username is not already in the path, the value
# of `$user` to the path. The latter is used to avoid conflicts between
# users in shared temporary spaces.
#
# Another option that prevents conflicts and potential permission issues is
# to specify `~/.spack/stage`, which ensures each user builds in their home
# directory.
#
# A more traditional path uses the value of `$spack/var/spack/stage`, which
# builds directly inside Spack's instance without staging them in a
# A value of $spack/var/spack/stage indicates that Spack should run
# builds directly inside its install directory without staging them in
# temporary space.
#
# The build stage can be purged with `spack clean --stage` and
# `spack clean -a`, so it is important that the specified directory uniquely
# identifies Spack staging to avoid accidentally wiping out non-Spack work.
# The build stage can be purged with `spack clean --stage`.
build_stage:
- $tempdir/spack-stage
- $tempdir
- $spack/var/spack/stage


# Cache directory for already downloaded source tarballs and archived
Expand Down
31 changes: 15 additions & 16 deletions lib/spack/docs/config_yaml.rst
Expand Up @@ -85,39 +85,38 @@ See :ref:`modules` for details.

Spack is designed to run out of a user home directory, and on many
systems the home directory is a (slow) network file system. On most systems,
building in a temporary file system is faster. Usually, there is also more
space available in the temporary location than in the home directory. If the
username is not already in the path, Spack will also append the value of
`$user` to the path.

.. warning:: We highly recommend appending `spack-stage` to `$tempdir` in order
to ensure `spack clean` does not delete everything in `$tempdir`.
building in a temporary file system results in faster builds than building
in the home directory. Usually, there is also more space available in
the temporary location than in the home directory. So, Spack tries to
create build stages in temporary space.

By default, Spack's ``build_stage`` is configured like this:

.. code-block:: yaml
build_stage:
- $tempdir/spack-stage
- $tempdir
- $spack/var/spack/stage
This can be an ordered list of paths that Spack should search when trying to
This is an ordered list of paths that Spack should search when trying to
find a temporary directory for the build stage. The list is searched in
order, and Spack will use the first directory to which it has write access.
Specifying `~/.spack/stage` first will ensure each user builds in their home
directory. The historic Spack stage path `$spack/var/spack/stage` will build
directly inside the Spack instance. See :ref:`config-file-variables` for more
on ``$tempdir`` and ``$spack``.
See :ref:`config-file-variables` for more on ``$tempdir`` and ``$spack``.

When Spack builds a package, it creates a temporary directory within the
``build_stage``. After the package is successfully installed, Spack deletes
``build_stage``, and it creates a symbolic link to that directory in
``$spack/var/spack/stage``. This is used to track the temporary
directory. After the package is successfully installed, Spack deletes
the temporary directory it used to build. Unsuccessful builds are not
deleted, but you can manually purge them with :ref:`spack clean --stage
<cmd-spack-clean>`.

.. note::

The build will fail if there is no writable directory in the ``build_stage``
list.
The last item in the list is ``$spack/var/spack/stage``. If this is the
only writable directory in the ``build_stage`` list, Spack will build
*directly* in ``$spack/var/spack/stage`` and will not link to temporary
space.

--------------------
``source_cache``
Expand Down
20 changes: 5 additions & 15 deletions lib/spack/llnl/util/filesystem.py
Expand Up @@ -347,22 +347,12 @@ def copy_tree(src, dest, symlinks=True, ignore=None, _permissions=False):
else:
tty.debug('Copying {0} to {1}'.format(src, dest))

abs_src = os.path.abspath(src)
if not abs_src.endswith(os.path.sep):
abs_src += os.path.sep
abs_dest = os.path.abspath(dest)
if not abs_dest.endswith(os.path.sep):
abs_dest += os.path.sep

# Stop early to avoid unnecessary recursion if being asked to copy from a
# parent directory.
if abs_dest.startswith(abs_src):
raise ValueError('Cannot copy ancestor directory {0} into {1}'.
format(abs_src, abs_dest))

mkdirp(dest)

for s, d in traverse_tree(abs_src, abs_dest, order='pre',
src = os.path.abspath(src)
dest = os.path.abspath(dest)

for s, d in traverse_tree(src, dest, order='pre',
follow_symlinks=not symlinks,
ignore=ignore,
follow_nonexisting=True):
Expand All @@ -371,7 +361,7 @@ def copy_tree(src, dest, symlinks=True, ignore=None, _permissions=False):
if symlinks:
target = os.readlink(s)
if os.path.isabs(target):
new_target = re.sub(abs_src, abs_dest, target)
new_target = re.sub(src, dest, target)
if new_target != target:
tty.debug("Redirecting link {0} to {1}"
.format(target, new_target))
Expand Down
3 changes: 1 addition & 2 deletions lib/spack/spack/cmd/location.py
Expand Up @@ -14,7 +14,6 @@
import spack.environment
import spack.paths
import spack.repo
import spack.stage

description = "print out locations of packages and spack directories"
section = "basic"
Expand Down Expand Up @@ -77,7 +76,7 @@ def location(parser, args):
print(spack.repo.path.first_repo().root)

elif args.stages:
print(spack.stage.get_stage_root())
print(spack.paths.stage_path)

else:
specs = spack.cmd.parse_specs(args.spec)
Expand Down
3 changes: 1 addition & 2 deletions lib/spack/spack/compilers/clang.py
Expand Up @@ -12,7 +12,6 @@
import llnl.util.tty as tty

import spack.paths
import spack.stage
from spack.compiler import Compiler, UnsupportedCompilerFlag
from spack.util.executable import Executable
from spack.version import ver
Expand Down Expand Up @@ -280,7 +279,7 @@ def setup_custom_environment(self, pkg, env):
raise OSError(msg)

real_root = os.path.dirname(os.path.dirname(real_root))
developer_root = os.path.join(spack.stage.get_stage_root(),
developer_root = os.path.join(spack.paths.stage_path,
'xcode-select',
self.name,
str(self.version))
Expand Down
1 change: 0 additions & 1 deletion lib/spack/spack/config.py
Expand Up @@ -101,7 +101,6 @@
'checksum': True,
'dirty': False,
'build_jobs': min(16, multiprocessing.cpu_count()),
'build_stage': '$tempdir/spack-stage',
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/spack/spack/package.py
Expand Up @@ -1769,7 +1769,9 @@ def check_for_unfinished_installation(
else:
partial = True

if restage and self.stage.managed_by_spack:
stage_is_managed_in_spack = self.stage.path.startswith(
spack.paths.stage_path)
if restage and stage_is_managed_in_spack:
self.stage.destroy()
self.stage.create()

Expand Down
5 changes: 3 additions & 2 deletions lib/spack/spack/patch.py
Expand Up @@ -192,8 +192,9 @@ def fetch(self, stage):
fetch_digest = self.archive_sha256

fetcher = fs.URLFetchStrategy(self.url, fetch_digest)
mirror = os.path.join(os.path.dirname(stage.mirror_path),
os.path.basename(self.url))
mirror = os.path.join(
os.path.dirname(stage.mirror_path),
os.path.basename(self.url))

self.stage = spack.stage.Stage(fetcher, mirror_path=mirror)
self.stage.create()
Expand Down
1 change: 1 addition & 0 deletions lib/spack/spack/paths.py
Expand Up @@ -38,6 +38,7 @@
test_path = os.path.join(module_path, "test")
hooks_path = os.path.join(module_path, "hooks")
var_path = os.path.join(prefix, "var", "spack")
stage_path = os.path.join(var_path, "stage")
repos_path = os.path.join(var_path, "repos")
share_path = os.path.join(prefix, "share", "spack")

Expand Down

0 comments on commit 6dac08a

Please sign in to comment.