Commit 9ca803bb authored by Jérome Perrin's avatar Jérome Perrin

Do not set any TMP environment variables

This reverts daa833ea ( !3 ) and extend it to not set `$TMP` either.

De facto, setting only `$TMP` was never effective ( see also [#20120530-132221B](https://nexedi.erp5.net/bug_module/20120530-132221B) ) and as we saw in !3 (comment 67059) it causes more harm than good.

The conclusion so far is that environment variables related to temporary files should be handled by the parent process. The parent process is responsible for providing a directory short enough so that we can create unix sockets in `$TMPDIR`  and to clean up this directory afterwards.


In a pure buildout it could be:

```bash
tmpdir=$(mktemp -d)
trap 'rm -rf $tmpdir' SIGINT SIGTERM
TEMP=$tmpdir TMPDIR=$tmpdir TMP=$tmpdir buildout
rm -rf $tmpdir
```

/reviewed-on !8
parents c42c6aee f101b03b
......@@ -269,10 +269,6 @@ will add it to environmet variables as the following:
CXXFLAGS=-I${buildout:prefix} $CXXFLAGS
LDFLAGS=-L${buildout:prefix}/lib
Besides, the recipe changes environment variables ``TMP``, ``TMPDIR`` and
``TEMP`` when building and installing, and make a corresponding directory 'tmp'
in the ``location``. This temporary directory will be removed after installing
finished.
Example usage
=============
......@@ -308,9 +304,6 @@ default build options.
>>> print(system(buildout)) #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
configure --prefix=/sample_buildout/parts/package
building package
installing package
......@@ -336,9 +329,6 @@ default build options.
>>> print system(buildout)
Uninstalling package.
Installing packagex.
packagex: [ENV] TEMP = /sample_buildout/parts/packagex/tmp
packagex: [ENV] TMP = /sample_buildout/parts/packagex/tmp
packagex: [ENV] TMPDIR = /sample_buildout/parts/packagex/tmp
configure --prefix=/sample_buildout/parts/packagex
building package
installing package
......@@ -375,9 +365,6 @@ a custom location within the buildout::
>>> print(system(buildout))
Uninstalling packagex.
Installing foobar.
foobar: [ENV] TEMP = /sample_buildout/parts/foobar/tmp
foobar: [ENV] TMP = /sample_buildout/parts/foobar/tmp
foobar: [ENV] TMPDIR = /sample_buildout/parts/foobar/tmp
building package
installing package
......@@ -416,9 +403,6 @@ Makefile and using explicit ``make`` options to control the build process.
>>> print(system(buildout))
Uninstalling foobar.
Installing haproxy.
haproxy: [ENV] TEMP = /sample_buildout/parts/haproxy/tmp
haproxy: [ENV] TMP = /sample_buildout/parts/haproxy/tmp
haproxy: [ENV] TMPDIR = /sample_buildout/parts/haproxy/tmp
Building HAProxy 1.4.8 (dummy package)
TARGET: linux26
CPU: i686
......@@ -459,9 +443,6 @@ and building that.
>>> print(system(buildout))
Uninstalling haproxy.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
package: Using local source directory: /checkout/package-0.0.0
configure --prefix=/sample_buildout/parts/package
building package
......@@ -521,9 +502,6 @@ targets and also patches the source code before the scripts are run.
Installing package.
package: [ENV] CFLAGS = -I/sw/include
package: [ENV] LDFLAGS = -L/sw/lib -L/some/extra/lib
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
package: Applying patches
patching file configure
patching file Makefile.dist
......@@ -606,9 +584,6 @@ and a new buildout to try it out
>>> print(system(buildout))
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
package: Executing pre-configure-hook
hook: This is pre-configure-hook!
configure --prefix=/sample_buildout/parts/package
......@@ -648,9 +623,6 @@ shell command in the corresponding stage.
>>> print system(buildout)
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
package: Executing pre-configure
Configure part: package
configure --prefix=/sample_buildout/parts/package
......@@ -691,9 +663,6 @@ are only ``pre-configure`` and ``post-install``. the output will be
#>>> print system(buildout)
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
package: Executing pre-configure
Configure part: Configure in common platform
configure --prefix=/sample_buildout/parts/package
......@@ -737,9 +706,6 @@ Let's see what happens when set prefix in the buildout section:
>>> print system(buildout)
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
package: Executing pre-configure
configure --prefix=/sample_buildout/mylocal
building package
......@@ -770,9 +736,6 @@ example,
>>> print system(buildout)
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
package: Executing pre-configure
configure --prefix=/sample_buildout/parts/package
building package
......@@ -806,17 +769,11 @@ prefix:
>>> print system(buildout)
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
configure --prefix=/sample_buildout/mylocal
building package
package: Executing pre-install
installing package
Installing package-2.
package-2: [ENV] TEMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMPDIR = /sample_buildout/parts/package-2/tmp
configure --prefix=/sample_buildout/mylocal
building package
package-2: Executing pre-install
......@@ -900,13 +857,7 @@ value in the part section. For example,
>>> print system(buildout)
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
Installing package-2.
package-2: [ENV] TEMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMPDIR = /sample_buildout/parts/package-2/tmp
package-2: Executing post-install
package magic prefix is /mytemp
<BLANKLINE>
......@@ -931,9 +882,6 @@ can display "prefix" value in the stdout.
Uninstalling package-2.
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
configure
building package
package: Executing pre-install
......@@ -959,9 +907,6 @@ replaced with the recipe final prefix.
>>> print system(buildout)
Uninstalling package.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
configure
building package
package: Executing pre-install
......@@ -996,16 +941,10 @@ of "package":
>>> print system(buildout)
Uninstalling package.
Installing package-2.
package-2: [ENV] TEMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMPDIR = /sample_buildout/parts/package-2/tmp
configure --prefix=/sample_buildout/parts/package-2
building package
installing package
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
configure --prefix=/sample_buildout/parts/package
building package
installing package
......@@ -1035,16 +974,10 @@ Look, "package" is reinstalled either:
Uninstalling package.
Uninstalling package-2.
Installing package-2.
package-2: [ENV] TEMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMP = /sample_buildout/parts/package-2/tmp
package-2: [ENV] TMPDIR = /sample_buildout/parts/package-2/tmp
configure
building package
installing package
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
configure --prefix=/sample_buildout/parts/package
building package
installing package
......@@ -1076,9 +1009,6 @@ If no shared-parts is set, and shared is True, shared feature is not used:
Uninstalling package.
Uninstalling package-2.
Installing package.
package: [ENV] TEMP = /sample_buildout/parts/package/tmp
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: [ENV] TMPDIR = /sample_buildout/parts/package/tmp
configure --prefix=/sample_buildout/parts/package
building package
installing package
......@@ -1118,9 +1048,6 @@ process as the recipe tried.
Installing package.
package: Checking whether package is installed at shared path: .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...
package: [ENV] FOO = bar
package: [ENV] TEMP = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: [ENV] TMP = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: [ENV] TMPDIR = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: Command failed with exit code 127: ./configure --prefix=".../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/..."
package: Compilation error. The package is left as is at .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...__compile__ where you can inspect what went wrong.
A shell script slapos.recipe.build.env.sh has been generated. You can source it in your shell to reproduce build environment.
......@@ -1139,9 +1066,6 @@ If shared-parts is set and shared is True, package will be installed in shared_p
package: shared directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... set for package
Installing package.
package: Checking whether package is installed at shared path: .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...
package: [ENV] TEMP = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: [ENV] TMP = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: [ENV] TMPDIR = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: Removing already existing directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...__compile__
configure --prefix=.../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...
building package
......@@ -1189,9 +1113,6 @@ If options change, reinstall in different location:
Uninstalling package.
Installing package.
package: Checking whether package is installed at shared path: .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...
package: [ENV] TEMP = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: [ENV] TMP = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
package: [ENV] TMPDIR = .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/.../tmp
configure --prefix=.../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/...
building package
installing package
......
......@@ -144,10 +144,6 @@ class Recipe(object):
for key in self.environ:
self.environ[key] = self.environ[key] % os.environ
# Always define TMPDIR, TEMP and TMP
for key in ('TMPDIR', 'TEMP', 'TMP'):
self.environ[key] = os.path.join(options['default-location'], 'tmp')
def augmented_environment(self):
"""Returns a dictionary containing the current environment variables
augmented with the part specific overrides.
......@@ -155,6 +151,10 @@ class Recipe(object):
The dictionary is an independent copy of ``os.environ`` and
modifications will not be reflected in back in ``os.environ``.
"""
# Note that we don't set TMPDIR or TMP here as we use to do, because
# this path might be too deep and this will cause problem with some
# software (for example golang) who runs a test suite after build and
# use this TMPDIR to create unix sockets.
env = os.environ.copy()
env.update(self.environ)
return env
......@@ -342,9 +342,6 @@ class Recipe(object):
shutil.rmtree(location)
os.mkdir(location)
os.chdir(compile_dir)
tmp_path = self.environ['TMP']
shutil.rmtree(tmp_path, True)
os.mkdir(tmp_path)
if self.options['shared']:
self._signature.save(self.options["shared"])
......@@ -407,7 +404,7 @@ class Recipe(object):
and self.options['shared'] == ''
and os.path.exists(self.buildout_prefix)):
log.info('Getting installed file lists')
parts.extend(self.get_installed_files(tmp_path))
parts.extend(self.get_installed_files(compile_dir))
except:
with open('slapos.recipe.build.env.sh', 'w') as env_script:
......@@ -433,9 +430,6 @@ class Recipe(object):
raise
finally:
os.chdir(current_dir)
# If in shared mode and have error during installed, tmp_path was already deleted
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)
# Check promises
self.check_promises(log)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment