Bug 1224452 - Quote passthru variables. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 20 Nov 2015 17:24:25 +0900
changeset 274295 f8a04f388bf11c708bef77b087f8871f5c10d793
parent 274294 eb94204b1c96191fe9b7ccb4d0481f79dd2b9e5e
child 274296 bc9a43cbbdfad05a533c43dcecb59527e3b22b01
push id29727
push usercbook@mozilla.com
push dateThu, 26 Nov 2015 15:54:54 +0000
treeherdermozilla-central@74c7941a9e22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1224452
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1224452 - Quote passthru variables. r=gps Ideally, we should properly make and shell quote everything we print out in makefiles, but that's a can of worms I don't want to open just yet. So I'll limit myself to just passthru variables.
media/libopus/moz.build
python/mozbuild/mozbuild/backend/recursivemake.py
python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build
python/mozbuild/mozbuild/test/backend/test_recursivemake.py
--- a/media/libopus/moz.build
+++ b/media/libopus/moz.build
@@ -106,9 +106,9 @@ if CONFIG['CPU_ARCH'] == 'arm' and CONFI
     ASFLAGS += [
         '-march=armv7-a',
         '-mfpu=neon',
     ]
 
 # Suppress warnings in third-party code.
 if CONFIG['GNU_CC']:
     if CONFIG['CLANG_CXX']:
-        CFLAGS += ['-Wno-\#pragma-messages']
+        CFLAGS += ['-Wno-#pragma-messages']
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -72,16 +72,17 @@ from ..frontend.data import (
     VariablePassthru,
     XPIDLFile,
 )
 from ..util import (
     ensureParentDir,
     FileAvoidWrite,
 )
 from ..makeutil import Makefile
+from mozbuild.shellutil import quote as shell_quote
 
 MOZBUILD_VARIABLES = [
     b'ANDROID_APK_NAME',
     b'ANDROID_APK_PACKAGE',
     b'ANDROID_ASSETS_DIRS',
     b'ANDROID_EXTRA_PACKAGES',
     b'ANDROID_EXTRA_RES_DIRS',
     b'ANDROID_GENERATED_RESFILES',
@@ -164,16 +165,20 @@ DEPRECATED_VARIABLES = [
 MOZBUILD_VARIABLES_MESSAGE = 'It should only be defined in moz.build files.'
 
 DEPRECATED_VARIABLES_MESSAGE = (
     'This variable has been deprecated. It does nothing. It must be removed '
     'in order to build.'
 )
 
 
+def make_quote(s):
+    return s.replace('#', '\#').replace('$', '$$')
+
+
 class BackendMakeFile(object):
     """Represents a generated backend.mk file.
 
     This is both a wrapper around a file handle as well as a container that
     holds accumulated state.
 
     It's worth taking a moment to explain the make dependencies. The
     generated backend.mk as well as the Makefile.in (if it exists) are in the
@@ -489,17 +494,18 @@ class RecursiveMakeBackend(CommonBackend
             for f in sorted(obj.files):
                 backend_file.write('%s += %s\n' % (
                     var, mozpath.relpath(f, backend_file.srcdir)))
         elif isinstance(obj, VariablePassthru):
             # Sorted so output is consistent and we don't bump mtimes.
             for k, v in sorted(obj.variables.items()):
                 if isinstance(v, list):
                     for item in v:
-                        backend_file.write('%s += %s\n' % (k, item))
+                        backend_file.write(
+                            '%s += %s\n' % (k, make_quote(shell_quote(item))))
                 elif isinstance(v, bool):
                     if v:
                         backend_file.write('%s := 1\n' % k)
                 else:
                     backend_file.write('%s := %s\n' % (k, v))
         elif isinstance(obj, HostDefines):
             self._process_defines(obj, backend_file, which='HOST_DEFINES')
         elif isinstance(obj, Defines):
--- a/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build
+++ b/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build
@@ -12,17 +12,17 @@ DELAYLOAD_DLLS = ['foo.dll', 'bar.dll']
 RCFILE = 'foo.rc'
 RESFILE = 'bar.res'
 RCINCLUDE = 'bar.rc'
 DEFFILE = 'baz.def'
 
 USE_STATIC_LIBS = True
 
 CFLAGS += ['-fno-exceptions', '-w']
-CXXFLAGS += ['-fcxx-exceptions', '-include foo.h']
-LDFLAGS += ['-framework Foo', '-x']
+CXXFLAGS += ['-fcxx-exceptions', '-option with spaces']
+LDFLAGS += ['-ld flag with spaces', '-x']
 HOST_CFLAGS += ['-funroll-loops', '-wall']
 HOST_CXXFLAGS += ['-funroll-loops-harder', '-wall-day-everyday']
 WIN32_EXE_LDFLAGS += ['-subsystem:console']
 
 DISABLE_STL_WRAPPING = True
 
 ALLOW_COMPILER_WARNINGS = True
--- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
+++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
@@ -294,20 +294,20 @@ class TestRecursiveMakeBackend(BackendTe
                 'USE_STATIC_LIBS := 1',
             ],
             'MOZBUILD_CFLAGS': [
                 'MOZBUILD_CFLAGS += -fno-exceptions',
                 'MOZBUILD_CFLAGS += -w',
             ],
             'MOZBUILD_CXXFLAGS': [
                 'MOZBUILD_CXXFLAGS += -fcxx-exceptions',
-                'MOZBUILD_CXXFLAGS += -include foo.h',
+                "MOZBUILD_CXXFLAGS += '-option with spaces'",
             ],
             'MOZBUILD_LDFLAGS': [
-                'MOZBUILD_LDFLAGS += -framework Foo',
+                "MOZBUILD_LDFLAGS += '-ld flag with spaces'",
                 'MOZBUILD_LDFLAGS += -x',
                 'MOZBUILD_LDFLAGS += -DELAYLOAD:foo.dll',
                 'MOZBUILD_LDFLAGS += -DELAYLOAD:bar.dll',
             ],
             'MOZBUILD_HOST_CFLAGS': [
                 'MOZBUILD_HOST_CFLAGS += -funroll-loops',
                 'MOZBUILD_HOST_CFLAGS += -wall',
             ],