Bug 1262735 - Separate compiler and flags when passing them to CMake. r?ehsan draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 07 Apr 2016 15:04:13 +0900
changeset 349601 52f961bd3c8f8d16b86761218fa2bf92007e90d3
parent 349600 b1f6d9b41d1210751d94e43ae0255fdbb2b3aa5d
child 349602 9d5f4357199162eabb03dca2f78aeca0ec901ea0
push id15145
push userbmo:mh+mozilla@glandium.org
push dateTue, 12 Apr 2016 01:01:37 +0000
reviewersehsan
bugs1262735, 1042132
milestone48.0a1
Bug 1262735 - Separate compiler and flags when passing them to CMake. r?ehsan When passing -DCMAKE_C_COMPILER="gcc -flags" to CMake, ninja then tries to literally call "gcc -flags", not "gcc" "-flags", and a "gcc -flags" file obviously doesn't exist, so the build fails. This fixes a regression from bug 1042132. Hopefully, this also doesn't regress bug 1042132 itself.
build/build-clang/build-clang.py
--- a/build/build-clang/build-clang.py
+++ b/build/build-clang/build-clang.py
@@ -191,18 +191,20 @@ def build_one_stage_aux(cc, cxx, src_dir
     build_dir = stage_dir + "/build"
     inst_dir = stage_dir + "/clang"
 
     run_cmake = True
     if os.path.exists(build_dir + "/build.ninja"):
         run_cmake = False
 
     cmake_args = ["-GNinja",
-                  "-DCMAKE_C_COMPILER=%s" % cc,
-                  "-DCMAKE_CXX_COMPILER=%s" % cxx,
+                  "-DCMAKE_C_COMPILER=%s" % cc[0],
+                  "-DCMAKE_CXX_COMPILER=%s" % cxx[0],
+                  "-DCMAKE_C_FLAGS=%s" % ' '.join(cc[1:]),
+                  "-DCMAKE_CXX_FLAGS=%s" % ' '.join(cxx[1:]),
                   "-DCMAKE_BUILD_TYPE=%s" % build_type,
                   "-DLLVM_TARGETS_TO_BUILD=X86;ARM",
                   "-DLLVM_ENABLE_ASSERTIONS=%s" % ("ON" if assertions else "OFF"),
                   "-DPYTHON_EXECUTABLE=%s" % python_path,
                   "-DCMAKE_INSTALL_PREFIX=%s" % inst_dir,
                   "-DLLVM_TOOL_LIBCXX_BUILD=%s" % ("ON" if build_libcxx else "OFF"),
                   "-DLIBCXX_LIBCPPABI_VERSION=\"\"",
                   src_dir];
@@ -338,68 +340,68 @@ if __name__ == "__main__":
         os.makedirs(build_dir)
 
     stage1_dir = build_dir + '/stage1'
     stage1_inst_dir = stage1_dir + '/clang'
 
     final_stage_dir = stage1_dir
 
     if is_darwin():
-        extra_cflags = ""
-        extra_cxxflags = "-stdlib=libc++"
-        extra_cflags2 = ""
-        extra_cxxflags2 = "-stdlib=libc++"
+        extra_cflags = []
+        extra_cxxflags = ["-stdlib=libc++"]
+        extra_cflags2 = []
+        extra_cxxflags2 = ["-stdlib=libc++"]
     elif is_linux():
-        extra_cflags = "-static-libgcc"
-        extra_cxxflags = "-static-libgcc -static-libstdc++"
-        extra_cflags2 = "-fPIC --gcc-toolchain=%s" % gcc_dir
-        extra_cxxflags2 = "-fPIC --gcc-toolchain=%s" % gcc_dir
+        extra_cflags = ["-static-libgcc"]
+        extra_cxxflags = ["-static-libgcc", "-static-libstdc++"]
+        extra_cflags2 = ["-fPIC", "--gcc-toolchain=%s" % gcc_dir]
+        extra_cxxflags2 = ["-fPIC", "--gcc-toolchain=%s" % gcc_dir]
 
         if os.environ.has_key('LD_LIBRARY_PATH'):
             os.environ['LD_LIBRARY_PATH'] = '%s/lib64/:%s' % (gcc_dir, os.environ['LD_LIBRARY_PATH']);
         else:
             os.environ['LD_LIBRARY_PATH'] = '%s/lib64/' % gcc_dir
     elif is_windows():
-        extra_cflags = ""
-        extra_cxxflags = ""
-        extra_cflags2 = ""
-        extra_cxxflags2 = ""
+        extra_cflags = []
+        extra_cxxflags = []
+        extra_cflags2 = []
+        extra_cxxflags2 = []
 
     build_one_stage(
-        cc + " %s" % extra_cflags,
-        cxx + " %s" % extra_cxxflags,
+        [cc] + extra_cflags,
+        [cxx] + extra_cxxflags,
         llvm_source_dir, stage1_dir, build_libcxx,
         build_type, assertions, python_path)
 
     if stages > 1:
         stage2_dir = build_dir + '/stage2'
         stage2_inst_dir = stage2_dir + '/clang'
         final_stage_dir = stage2_dir
         build_one_stage(
-            stage1_inst_dir + "/bin/%s%s %s" %
-                (cc_name, exe_ext, extra_cflags2),
-            stage1_inst_dir + "/bin/%s%s %s" %
-                (cxx_name, exe_ext, extra_cxxflags2),
+            [stage1_inst_dir + "/bin/%s%s" %
+                (cc_name, exe_ext)] + extra_cflags2,
+            [stage1_inst_dir + "/bin/%s%s" %
+                (cxx_name, exe_ext)] + extra_cxxflags2,
             llvm_source_dir, stage2_dir, build_libcxx,
             build_type, assertions, python_path)
 
         if stages > 2:
             stage3_dir = build_dir + '/stage3'
             final_stage_dir = stage3_dir
             build_one_stage(
-                stage2_inst_dir + "/bin/%s%s %s" %
-                    (cc_name, exe_ext, extra_cflags2),
-                stage2_inst_dir + "/bin/%s%s %s" %
-                    (cxx_name, exe_ext, extra_cxxflags2),
+                [stage2_inst_dir + "/bin/%s%s" %
+                    (cc_name, exe_ext)] + extra_cflags2,
+                [stage2_inst_dir + "/bin/%s%s" %
+                    (cxx_name, exe_ext)] + extra_cxxflags2,
                 llvm_source_dir, stage3_dir, build_libcxx,
                 build_type, assertions, python_path)
 
     if is_linux():
         final_stage_inst_dir = final_stage_dir + '/clang'
         build_and_use_libgcc(
-            {"CC": cc + " %s" % extra_cflags,
-             "CXX": cxx + " %s" % extra_cxxflags},
+            {"CC": cc + " %s" % ' '.join(extra_cflags),
+             "CXX": cxx + " %s" % ' '.join(extra_cxxflags)},
             final_stage_inst_dir)
 
     if is_darwin() or is_windows():
         build_tar_package("tar", "clang.tar.bz2", final_stage_dir, "clang")
     else:
         build_tar_package("tar", "clang.tar.xz", final_stage_dir, "clang")