Trying to build a snap with several different parts using different plugins (go, copy, x-plainbox-provider), snapcraft assemble fails with the following:
tmp/tmpod0y7lbt: 5: export: -L/home/cwayne/Projects/factory-diag-exp/snap/usr/lib: bad variable name
Traceback (most recent call last):
File "/usr/local/bin/snapcraft", line 4, in <module>
__import__('pkg_resources').run_script('snapcraft==0.5', 'snapcraft')
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 735, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1652, in run_script
exec(code, namespace, namespace)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/EGG-INFO/scripts/snapcraft", line 33, in <module>
snapcraft.main.main()
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/main.py", line 144, in main
args.func(args)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/cmds.py", line 95, in assemble
snap(args)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/cmds.py", line 88, in snap
meta.create(config.data, arches)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/meta.py", line 61, in create
_write_package_yaml(meta_dir, config_data, arches)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/meta.py", line 72, in _write_package_yaml
package_yaml = _compose_package_yaml(meta_dir, config_data, arches)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/meta.py", line 144, in _compose_package_yaml
binaries = _wrap_binaries(binaries)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/meta.py", line 245, in _wrap_binaries
execwrap = _wrap_exe(execparts[0])
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/meta.py", line 227, in _wrap_exe
common.run(['/bin/sh', tempf.name], cwd=snap_dir)
File "/usr/local/lib/python3.4/dist-packages/snapcraft-0.5-py3.4.egg/snapcraft/common.py", line 50, in run
subprocess.check_call(['/bin/sh', f.name] + cmd, **kwargs)
File "/usr/lib/python3.4/subprocess.py", line 561, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/bin/sh', '/tmp/tmpy9r5h2dw', '/bin/sh', '/tmp/tmpod0y7lbt']' returned non-zero exit status 2
After trying to track down why was causing this symptom I found that where the go plugin creates a custom environment for running commands it adds its own LDFLAGS like this:
env = [
'GOPATH= {}/go'. format( root),
'CGO_ LDFLAGS= $CGO_LDFLAGS" ' + ' '.join([
'-L{0} /lib',
'-L{0} /usr/lib' ,
'-L{0} /lib/{1} ',
'-L{0} /usr/lib/ {1}',
'$LDFLAGS'
]) .format( root, snapcraft. common. get_arch_ triplet( )) + '"',
I think when this added to scripts that are used to configure the environment the fact that the CGO_LDFLAGS is outside the quote marks causes issues in some circumstances. I have found changing this to the following allows these builds to work fine:
env = [
'GOPATH= {}/go'. format( root),
'CGO_ LDFLAGS= "$CGO_LDFLAGS ' + ' '.join([
'-L{0} /lib',
'-L{0} /usr/lib' ,
'-L{0} /lib/{1} ',
'-L{0} /usr/lib/ {1}',
'$LDFLAGS'
]) .format( root, snapcraft. common. get_arch_ triplet( )) + '"',