Snap fails to build with "Bad Variable Name"

Bug #1524374 reported by Chris Wayne
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Snapcraft
Status tracked in Trunk
1.x
Fix Released
High
Jonathan Cave
Trunk
Fix Released
High
Jonathan Cave

Bug Description

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

Revision history for this message
Jonathan Cave (jocave) wrote :

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()) + '"',

Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

I tried to build a snap with the factory-diag-test branch today on 14.04, and encountered the very same issue.

For this bug, Jonathan's patch works like a charm.

After that, I got blocked with another issue, it returns non-zero value because of a command in the end:
    which "factory-diag-test"

And this does not exist, thus the return value is not 0. (I think this will be another issue)

Revision history for this message
Sergio Schvezov (sergiusens) wrote :
Changed in snapcraft:
status: New → Fix Committed
importance: Undecided → High
assignee: nobody → Jonathan Cave (jocave)
milestone: none → 2.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.