Skip to content

Separate setting build environment and run environment in packages#11115

Merged
becker33 merged 11 commits intospack:developfrom
epfl-scitas:features/divide_build_from_run_env
Oct 17, 2019
Merged

Separate setting build environment and run environment in packages#11115
becker33 merged 11 commits intospack:developfrom
epfl-scitas:features/divide_build_from_run_env

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Apr 5, 2019

fixes #6143
fixes #2016

refers to #2016 (comment)

As a package maintainer I want different methods to specify the build-time environment and the run-time environment of a package, so that I will know exactly which are the preconditions of the method that is being called.

Rationale

Currently each package can override two methods:

def setup_environment(self, build_env, run_env):
    ...

def setup_dependent_environment(self, build_env, run_env, dependent_spec):
    ...

to modify its build or run environment, or those of a dependent. This has a fundamental issue in that the same method will be called at different times, and will have different preconditions depending when it's called:

  1. If it is called to set-up the build environment the prefix of the spec being installed is not yet there + a few special variables that are needed to build with Spack compiler wrappers will be set
  2. If it is called to set-up the run environment the underlying spec is assumed to be already installed

This in turn might cause issues like #6143 or #2016 (comment). In this PR we split each of the two methods above, e.g. :

def setup_build_environment(self, env):
   ...

def setup_run_environment(self, env):
   ...

so that it will be clear which are the preconditions of each method call.

Description

This PR splits each *_environment method in spack.package.PackageBase into two: one that will be called for the build-time environment and one that wil be called for the run-time. As there are a lot of packages overriding these callbacks the default implementation is such to mimic the legacy behavior, and emit a deprecation warning to tty.debug, e.g.:

$ spack -d install mpich
[...]
==> [2019-04-05-14:13:38.193971] Installing mpich
==> [2019-04-05-14:13:38.194114] Searching for binary cache of mpich
==> [2019-04-05-14:13:38.194407] Reading config file /home/mculpo/.spack/linux/mirrors.yaml
==> [2019-04-05-14:13:38.195858] Finding buildcaches in /home/mculpo/production/mirror/build_cache
==> [2019-04-05-14:13:38.198158] No binary for mpich found: installing from source
==> [2019-04-05-14:13:38.300407] [DEPRECATED METHOD]
"pkgconf" still defines the deprecated method "setup_dependent_environment" [should be split into "setup_dependent_build_environment" and "setup_dependent_run_environment"]
==> [2019-04-05-14:13:38.323784] [DEPRECATED METHOD]
"perl" still defines the deprecated method "setup_dependent_environment" [should be split into "setup_dependent_build_environment" and "setup_dependent_run_environment"]
==> [2019-04-05-14:13:38.344990] [DEPRECATED METHOD]
"libtool" still defines the deprecated method "setup_dependent_environment" [should be split into "setup_dependent_build_environment" and "setup_dependent_run_environment"]
[...]

Additional information

  • Split setup_environment into two methods
  • Split setup_dependent_environment into two methods
  • Add documentation in the "Packaging guide" section of the docs
  • Update the tutorial sections of the docs
  • Add a test that fails if a package under PR still implements the old methods (this can be used to make the community aware of the new methods, can be removed once the old methods are not supported anymore)
  • Add a test that fails if any package implements the old methods, and mark it xfail (it will be useful when all packages are ported, in case of people doing PR based on old behavior)

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Apr 5, 2019

I added this PR as a draft to collect opinions on splitting the two methods before proceeding with docs and tests. If you don't have major concerns on what's being done here we can use the PR also to improve the APIs in build_environment.py and serve cases like #11084. Let me know what you think.

Copy link
Copy Markdown
Member

@becker33 becker33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do a particularly deep review, just the one comment for now.

I think this is probably a good direction to be moving in.

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Apr 16, 2019

No deep review yet, but this is a much cleaner, less confusing direction than the current state of affairs. I'm in favor!

@alalazo alalazo self-assigned this Sep 19, 2019
@alalazo alalazo force-pushed the features/divide_build_from_run_env branch from 6060f2b to 74034f3 Compare September 19, 2019 10:40
@alalazo alalazo marked this pull request as ready for review September 19, 2019 10:40
@alalazo alalazo requested a review from tgamblin September 19, 2019 15:57
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Sep 19, 2019

Ready for a review from my side. The description at the top should be up to date. Unit tests have been added and docs updated.

Copy link
Copy Markdown
Member

@becker33 becker33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alalazo only one comment at the moment. I'm a little concerned about build/link dependency semantics.

Before this commit the `*_environment` methods were setting
modifications to both the build-time and run-time environment
simultaneously. This might cause issues as the two environments
inherently rely on different preconditions:

1. The build-time environment is set before building a package, thus
the package prefix doesn't exist and can't be inspected

2. The run-time environment instead is set assuming the target package
has been already installed

Here we split each of these functions into two: one setting the
build-time environment, one the run-time.

We also adopt a fallback strategy that inspects for old methods and
executes them as before, but prints a deprecation warning to tty. This
permits to port packages to use the new methods in a distributed way,
rather than having to modify all the packages at once.
Also, emit a debug warning to avoid polluting messages on tty.
Marked the test xfail for now as we have a lot of packages in that
state.
This test can be used any time we deprecate a method call to ensure
that during the first modification of the package we update also
the deprecated calls.
@becker33 becker33 merged commit 9ddc98e into spack:develop Oct 17, 2019
@alalazo alalazo deleted the features/divide_build_from_run_env branch October 17, 2019 17:18
jrmadsen pushed a commit to jrmadsen/spack that referenced this pull request Oct 30, 2019
…pack#11115)

* Methods setting the environment now do it separately for build and run

Before this commit the `*_environment` methods were setting
modifications to both the build-time and run-time environment
simultaneously. This might cause issues as the two environments
inherently rely on different preconditions:

1. The build-time environment is set before building a package, thus
the package prefix doesn't exist and can't be inspected

2. The run-time environment instead is set assuming the target package
has been already installed

Here we split each of these functions into two: one setting the
build-time environment, one the run-time.

We also adopt a fallback strategy that inspects for old methods and
executes them as before, but prints a deprecation warning to tty. This
permits to port packages to use the new methods in a distributed way,
rather than having to modify all the packages at once.

* Added a test that fails if any package uses the old API

Marked the test xfail for now as we have a lot of packages in that
state.

* Added a test to check that a package modified by a PR is up to date

This test can be used any time we deprecate a method call to ensure
that during the first modification of the package we update also
the deprecated calls.

* Updated documentation
olesenm added a commit to olesenm/spack that referenced this pull request Nov 8, 2019
- build:
  no special treatment - already addressed in the spack-Allwmake script

- run:
  use environment from the OpenFOAM etc/bashrc
olesenm added a commit to olesenm/spack that referenced this pull request Nov 8, 2019
- build:
  no special treatment - already addressed in the spack-Allwmake script

- run:
  use environment from the OpenFOAM etc/bashrc
adamjstewart pushed a commit that referenced this pull request Nov 8, 2019
…3645)

- build:
  no special treatment - already addressed in the spack-Allwmake script

- run:
  use environment from the OpenFOAM etc/bashrc
ax3l added a commit to psychocoderHPC/spack that referenced this pull request Nov 25, 2019
adamjstewart pushed a commit that referenced this pull request Nov 25, 2019
* add package [email protected]

add CUDA 10.2 support

* CudaPackage: Add 10.2 Conflicts

* CUDA: Modernize Run Environment

See #11115
jasonfenglu added a commit to jasonfenglu/spack that referenced this pull request Mar 24, 2020
jasonfenglu added a commit to jasonfenglu/spack that referenced this pull request Mar 26, 2020
fangohr added a commit to fangohr/oommf-in-spack that referenced this pull request Sep 30, 2021
fangohr added a commit to fangohr/oommf-in-spack that referenced this pull request Sep 30, 2021
alalazo added a commit to alalazo/spack that referenced this pull request Mar 11, 2022
fixes spack#29446

The new setup_*_environment functions have been falling back
to calling the old functions and warn the user since spack#11115.

This commit removes the fallback behavior and any use of:
- setup_environment
- setup_dependent_environment
in the codebase
sethrj pushed a commit that referenced this pull request Mar 13, 2022
fixes #29446

The new setup_*_environment functions have been falling back
to calling the old functions and warn the user since #11115.

This commit removes the fallback behavior and any use of:
- setup_environment
- setup_dependent_environment
in the codebase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error building elpa: AttributeError: 'Spec' object has no attribute 'mpicc' setup_environment() is not mentioned in Packaging Guide

3 participants