Commit 88f8884b authored by Julien Muchembled's avatar Julien Muchembled

slapos.recipe.build.env.sh improvements/fixes

parent 3d5cb514
Pipeline #9085 failed with stage
in 0 seconds
...@@ -22,6 +22,23 @@ except: ...@@ -22,6 +22,23 @@ except:
options = Options({}, "options", options) options = Options({}, "options", options)
return options.query_bool(name, defaults) return options.query_bool(name, defaults)
startup_environ = os.environ.copy()
# backport of shlex.quote from Python 3.3
_find_unsafe = re.compile(r'[^\w@%+=:,./-]', 256).search
def quote(s):
"""Return a shell-escaped version of the string *s*."""
if not s:
return "''"
if _find_unsafe(s) is None:
return s
# use single quotes, and put single quotes into double quotes
# the string $'b is then quoted as '$'"'"'b'
return "'" + s.replace("'", "'\"'\"'") + "'"
###
class Recipe(object): class Recipe(object):
"""zc.buildout recipe for compiling and installing software""" """zc.buildout recipe for compiling and installing software"""
...@@ -277,6 +294,10 @@ class Recipe(object): ...@@ -277,6 +294,10 @@ class Recipe(object):
elif make_cmd == 'make' and make_targets == 'install': elif make_cmd == 'make' and make_targets == 'install':
make_targets += ' prefix=\"%s\"' % self.options['prefix'] make_targets += ' prefix=\"%s\"' % self.options['prefix']
configure_cmd = '%s %s' % (configure_cmd, ' '.join(configure_options)) % self.options
install_cmd = '%s %s %s' % (make_cmd, make_options, make_targets) % self.options
make_cmd = '%s %s' % (make_cmd, make_options) % self.options
patch_cmd = self.options.get('patch-binary', 'patch').strip() patch_cmd = self.options.get('patch-binary', 'patch').strip()
patch_options = ' '.join(self.options.get('patch-options', '-p0').split()) patch_options = ' '.join(self.options.get('patch-options', '-p0').split())
patches = self.options.get('patches', '').split() patches = self.options.get('patches', '').split()
...@@ -343,7 +364,7 @@ class Recipe(object): ...@@ -343,7 +364,7 @@ class Recipe(object):
log.info('Executing pre-configure') log.info('Executing pre-configure')
self.run(pre_configure_cmd) self.run(pre_configure_cmd)
self.run(('%s %s' % (configure_cmd, ' '.join(configure_options))) % self.options) self.run(configure_cmd)
if 'pre-make-hook' in self.options and len(self.options['pre-make-hook'].strip()) > 0: if 'pre-make-hook' in self.options and len(self.options['pre-make-hook'].strip()) > 0:
log.info('Executing pre-make-hook') log.info('Executing pre-make-hook')
...@@ -354,14 +375,14 @@ class Recipe(object): ...@@ -354,14 +375,14 @@ class Recipe(object):
log.info('Executing pre-build') log.info('Executing pre-build')
self.run(pre_build_cmd) self.run(pre_build_cmd)
self.run(('%s %s' % (make_cmd, make_options)) % self.options) self.run(make_cmd)
pre_install_cmd = self.options.get('pre-install', '').strip() % self.options pre_install_cmd = self.options.get('pre-install', '').strip() % self.options
if pre_install_cmd != '': if pre_install_cmd != '':
log.info('Executing pre-install') log.info('Executing pre-install')
self.run(pre_install_cmd) self.run(pre_install_cmd)
self.run(('%s %s %s' % (make_cmd, make_options, make_targets)) % self.options) self.run(install_cmd)
if 'post-make-hook' in self.options and len(self.options['post-make-hook'].strip()) > 0: if 'post-make-hook' in self.options and len(self.options['post-make-hook'].strip()) > 0:
log.info('Executing post-make-hook') log.info('Executing post-make-hook')
...@@ -379,16 +400,22 @@ class Recipe(object): ...@@ -379,16 +400,22 @@ class Recipe(object):
except: except:
with open('slapos.recipe.build.env.sh', 'w') as env_script: with open('slapos.recipe.build.env.sh', 'w') as env_script:
for key, v in sorted(self.environ.items()): for key, v in sorted(self.augmented_environment().items()):
if key not in ('TEMP', 'TMP', 'TMPDIR'): if v != startup_environ.get(key):
env_script.write('export %s="%s"\n' % (key, v)) env_script.write('%sexport %s=%s\n' % (
env_script.write('echo "If this recipe does not use pre/post hooks or commands, you can re-run as below."\n') '#'[:key in ('TEMP', 'TMP', 'TMPDIR')],
env_script.write('echo "configure with:"\n') key, quote(v)))
env_script.write('echo " %s %s"\n' % (configure_cmd, ' '.join(configure_options)) % self.options) env_script.write('''\
env_script.write('echo ""\n') echo "If this recipe does not use pre/post hooks or commands, you can re-run as below."
env_script.write('echo "make with:"\n') echo configure with:
env_script.write('echo " %s %s"\n' % (make_cmd, make_options) % self.options) echo %s
echo
echo make with:
echo %s
echo
echo install with:
echo %s
''' % (quote(" " + configure_cmd), quote(" " + make_cmd), quote(" " + install_cmd)))
log.error('Compilation error. The package is left as is at %s where ' log.error('Compilation error. The package is left as is at %s where '
'you can inspect what went wrong.\n' 'you can inspect what went wrong.\n'
......
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