Commit f1f11b5d authored by Jérome Perrin's avatar Jérome Perrin

Generate a shell script with environment variables and commands when build fail

To make it easyier to diagnose build errors.
parent daa833ea
Pipeline #5549 passed with stage
......@@ -1083,7 +1083,10 @@ If no shared-parts is set, and shared is True, shared feature is not used:
building package
installing package
If shared-parts is set and shared is True, build package failed, the build directory is removed, a build directory__complile__ is left for debugging
If shared-parts is set and shared is True, build package failed, the build directory is removed,
a build directory__compile__ is left for debugging.
Also a shell script with the environment variable is created, so that developer can try same build
process as the recipe tried.
>>> _ = system('mv %s/package-0.0.0.tar.gz %s/package-0.0.0.tar.gz.bak' % (src, src))
>>> import tarfile
>>> from io import BytesIO
......@@ -1106,21 +1109,29 @@ If shared-parts is set and shared is True, build package failed, the build direc
... recipe = slapos.recipe.cmmi
... url = file://%s/package-0.0.0.tar.gz
... shared = True
... environment =
... FOO=bar
... """ % (shared_dir, src))
>>> print system(buildout) #doctest:+ELLIPSIS
package: shared directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... set for package
Uninstalling package.
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
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.
/bin/sh: 1: ./configure: not found
While:
Installing package.
Error: System error
>>> import glob
>>> cat(glob.glob(os.path.join(shared_dir, 'package/**__compile__/slapos.recipe.build.env.sh'))[0])
export FOO="bar"
...
If shared-parts is set and shared is True, package will be installed in shared_part/package/a hash of the recipe's configuration options
>>> _ = system('mv %s/package-0.0.0.tar.gz.bak %s/package-0.0.0.tar.gz' % (src, src))
......@@ -1149,7 +1160,9 @@ Do nothing if one package has been installed.
... recipe = slapos.recipe.cmmi
... url = file://%s/package-0.0.0.tar.gz
... shared = True
... """ % (shared_dir, src))
... environment =
... FOO=bar
... """ % (shared_dir, src))
>>> print system(buildout) #doctest:+ELLIPSIS
package: shared directory .../slapos.recipe.cmmi/slapos/recipe/cmmi/shared/package/... set for package
Installing package.
......
......@@ -408,8 +408,24 @@ class Recipe(object):
log.info('Getting installed file lists')
parts.extend(self.get_installed_files(tmp_path))
except:
with open('slapos.recipe.build.env.sh', 'w') as env_script:
for key, v in sorted(self.environ.items()):
if key not in ('TEMP', 'TMP', 'TMPDIR'):
env_script.write('export %s="%s"\n' % (key, v))
env_script.write('echo "If this recipe does not use pre/post hooks or commands, you can re-run as below."\n')
env_script.write('echo "configure with:"\n')
env_script.write('echo " %s %s"\n' % (configure_cmd, ' '.join(configure_options)) % self.options)
env_script.write('echo ""\n')
env_script.write('echo "make with:"\n')
env_script.write('echo " %s %s"\n' % (make_cmd, make_options) % self.options)
log.error('Compilation error. The package is left as is at %s where '
'you can inspect what went wrong' % os.getcwd())
'you can inspect what went wrong.\n'
'A shell script slapos.recipe.build.env.sh has been generated. '
'You can source it in your shell to reproduce build environment.' % os.getcwd())
# Delete shared directory if not correctly installed
if self.options.get('shared'):
shutil.rmtree(self.options['shared'])
......
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