Bug 1310168 - Allow CC/CCC in makefiles and use it on TC, r=ttaubert
authorFranziskus Kiefer <franziskuskiefer@gmail.com>
Wed, 12 Oct 2016 14:21:56 +0200
changeset 12716 e0c174ad96f9fb6a2a15a967d7b3b41e11edf2e0
parent 12715 e29198e8a4d76f0dd0352c9a8fb71fcd2258bc71
child 12717 ad2a42aed57a01cfc1d8b14fad8c782f52e17093
push id1666
push userfranziskuskiefer@gmail.com
push dateFri, 14 Oct 2016 13:49:41 +0000
reviewersttaubert
bugs1310168
Bug 1310168 - Allow CC/CCC in makefiles and use it on TC, r=ttaubert
Makefile
automation/taskcluster/docker-arm/setup.sh
automation/taskcluster/docker/setup.sh
automation/taskcluster/graph/src/extend.js
automation/taskcluster/scripts/build.sh
automation/taskcluster/scripts/build_gyp.sh
automation/taskcluster/scripts/gen_certs.sh
automation/taskcluster/scripts/run_scan_build.sh
automation/taskcluster/scripts/run_tests.sh
automation/taskcluster/scripts/tools.sh
coreconf/Darwin.mk
coreconf/Linux.mk
--- a/Makefile
+++ b/Makefile
@@ -80,16 +80,22 @@ ifdef USE_DEBUG_RTL
 NSPR_CONFIGURE_OPTS += --enable-debug-rtl
 endif
 ifdef USE_STATIC_RTL
 NSPR_CONFIGURE_OPTS += --enable-static-rtl
 endif
 ifdef NS_USE_GCC
 NSPR_CONFIGURE_ENV = CC=gcc CXX=g++
 endif
+ifdef CC
+NSPR_CONFIGURE_ENV = CC=$(CC)
+endif
+ifdef CCC
+NSPR_CONFIGURE_ENV += CXX=$(CCC)
+endif
 
 ifdef SANITIZER_CFLAGS
 ifdef BUILD_OPT
 NSPR_CONFIGURE_OPTS += --enable-debug-symbols
 endif
 NSPR_CONFIGURE_ENV += CFLAGS='$(SANITIZER_CFLAGS)' \
                       CXXFLAGS='$(SANITIZER_CFLAGS)' \
                       LDFLAGS='$(SANITIZER_LDFLAGS)'
--- a/automation/taskcluster/docker-arm/setup.sh
+++ b/automation/taskcluster/docker-arm/setup.sh
@@ -19,20 +19,16 @@ apt_packages+=('zlib1g-dev')
 
 # Install packages.
 apt-get install -y --no-install-recommends ${apt_packages[@]}
 
 # Latest Mercurial.
 pip install --upgrade pip
 pip install Mercurial
 
-# Compiler options.
-update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 30
-update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 30
-
 locale-gen en_US.UTF-8
 dpkg-reconfigure locales
 
 # Cleanup.
 rm -rf ~/.ccache ~/.cache
 apt-get autoremove -y
 apt-get clean
 apt-get autoclean
--- a/automation/taskcluster/docker/setup.sh
+++ b/automation/taskcluster/docker/setup.sh
@@ -43,26 +43,16 @@ apt-get -y update
 apt-get install -y --no-install-recommends ${apt_packages[@]}
 
 # 32-bit builds
 ln -s /usr/include/x86_64-linux-gnu/zconf.h /usr/include
 
 # Install clang-3.9 into /usr/local/.
 curl http://llvm.org/releases/3.9.0/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz | tar xJv -C /usr/local --strip-components=1
 
-# Compiler options.
-update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/clang 5
-update-alternatives --install /usr/bin/g++ g++ /usr/local/bin/clang++ 5
-update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10
-update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
-update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 20
-update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 20
-update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 30
-update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 30
-
 locale-gen en_US.UTF-8
 dpkg-reconfigure locales
 
 # Cleanup.
 rm -rf ~/.ccache ~/.cache
 apt-get autoremove -y
 apt-get clean
 apt-get autoclean
--- a/automation/taskcluster/graph/src/extend.js
+++ b/automation/taskcluster/graph/src/extend.js
@@ -34,16 +34,21 @@ queue.filter(task => {
     if (task.symbol == "clang-3.9" && task.collection == "asan") {
       return false;
     }
 
     // Remove extra builds w/ gcc-5 on non-ASan.
     if (task.symbol == "gcc-5" && task.collection != "asan") {
       return false;
     }
+
+    // Remove extra builds on gyp builds (TODO: add when it supports CC/CCC).
+    if (task.collection == "gyp") {
+      return false;
+    }
   }
 
   if (task.tests == "bogo") {
     // No BoGo tests on Windows.
     if (task.platform == "windows2012-64") {
       return false;
     }
 
@@ -120,33 +125,33 @@ export default async function main() {
     collection: "gyp",
     image: LINUX_IMAGE
   });
 
   await scheduleLinux("Linux 64 (ASan, debug)", {
     env: {
       NSS_DISABLE_ARENA_FREE_LIST: "1",
       NSS_DISABLE_UNLOAD: "1",
-      GCC_VERSION: "clang",
-      GXX_VERSION: "clang++",
+      CC: "clang",
+      CCC: "clang++",
       USE_ASAN: "1",
       USE_64: "1"
     },
     platform: "linux64",
     collection: "asan",
     image: LINUX_IMAGE
   });
 
   await scheduleLinux("Linux 64 (ASan+UBSan, debug)", {
     env: {
       UBSAN_OPTIONS: "print_stacktrace=1",
       NSS_DISABLE_ARENA_FREE_LIST: "1",
       NSS_DISABLE_UNLOAD: "1",
-      GCC_VERSION: "clang",
-      GXX_VERSION: "clang++",
+      CC: "clang",
+      CCC: "clang++",
       USE_UBSAN: "1",
       USE_ASAN: "1",
       USE_64: "1"
     },
     platform: "linux64",
     collection: "ubsan",
     image: LINUX_IMAGE
   });
@@ -217,45 +222,45 @@ async function scheduleLinux(name, base)
     ]
   }));
 
   // Extra builds.
   let extra_base = merge({group: "Builds"}, build_base);
   queue.scheduleTask(merge(extra_base, {
     name: `${name} w/ clang-3.9`,
     env: {
-      GCC_VERSION: "clang",
-      GXX_VERSION: "clang++"
+      CC: "clang",
+      CCC: "clang++",
     },
     symbol: "clang-3.9"
   }));
 
   queue.scheduleTask(merge(extra_base, {
     name: `${name} w/ gcc-4.8`,
     env: {
-      GCC_VERSION: "gcc-4.8",
-      GXX_VERSION: "g++-4.8"
+      CC: "gcc-4.8",
+      CCC: "g++-4.8"
     },
     symbol: "gcc-4.8"
   }));
 
   queue.scheduleTask(merge(extra_base, {
     name: `${name} w/ gcc-5`,
     env: {
-      GCC_VERSION: "gcc-5",
-      GXX_VERSION: "g++-5"
+      CC: "gcc-5",
+      CCC: "g++-5"
     },
     symbol: "gcc-5"
   }));
 
   queue.scheduleTask(merge(extra_base, {
     name: `${name} w/ gcc-6.1`,
     env: {
-      GCC_VERSION: "gcc-6",
-      GXX_VERSION: "g++-6"
+      CC: "gcc-6",
+      CCC: "g++-6"
     },
     symbol: "gcc-6.1"
   }));
 
   queue.scheduleTask(merge(extra_base, {
     name: `${name} w/ NSS_DISABLE_LIBPKIX=1`,
     env: {NSS_DISABLE_LIBPKIX: "1"},
     symbol: "noLibpkix"
@@ -408,18 +413,18 @@ async function scheduleTools() {
     ]
   }));
 
   queue.scheduleTask(merge(base, {
     symbol: "scan-build-3.9",
     name: "scan-build-3.9",
     env: {
       USE_64: "1",
-      GCC_VERSION: "clang",
-      GXX_VERSION: "clang++"
+      CC: "clang",
+      CCC: "clang++",
     },
     artifacts: {
       public: {
         expires: 24 * 7,
         type: "directory",
         path: "/home/worker/artifacts"
       }
     },
--- a/automation/taskcluster/scripts/build.sh
+++ b/automation/taskcluster/scripts/build.sh
@@ -1,16 +1,13 @@
 #!/usr/bin/env bash
 
 source $(dirname $0)/tools.sh
 
 if [[ $(id -u) -eq 0 ]]; then
-    # Set compiler.
-    switch_compilers
-
     # Drop privileges by re-running this script.
     exec su worker $0
 fi
 
 # Clone NSPR if needed.
 hg_clone https://hg.mozilla.org/projects/nspr nspr default
 
 # Build.
--- a/automation/taskcluster/scripts/build_gyp.sh
+++ b/automation/taskcluster/scripts/build_gyp.sh
@@ -1,16 +1,13 @@
 #!/usr/bin/env bash
 
 source $(dirname $0)/tools.sh
 
 if [[ $(id -u) -eq 0 ]]; then
-    # Set compiler.
-    switch_compilers
-
     # Drop privileges by re-running this script.
     exec su worker $0
 fi
 
 # Clone NSPR if needed.
 hg_clone https://hg.mozilla.org/projects/nspr nspr default
 
 # Build.
--- a/automation/taskcluster/scripts/gen_certs.sh
+++ b/automation/taskcluster/scripts/gen_certs.sh
@@ -1,18 +1,15 @@
 #!/usr/bin/env bash
 
 set -v -e -x
 
 source $(dirname $0)/tools.sh
 
 if [ $(id -u) = 0 ]; then
-    # Set compiler.
-    switch_compilers
-
     # Stupid Docker.
     echo "127.0.0.1 localhost.localdomain" >> /etc/hosts
 
     # Drop privileges by re-running this script.
     exec su worker $0
 fi
 
 # Fetch artifact if needed.
--- a/automation/taskcluster/scripts/run_scan_build.sh
+++ b/automation/taskcluster/scripts/run_scan_build.sh
@@ -1,17 +1,13 @@
 #!/usr/bin/env bash
 
 source $(dirname $0)/tools.sh
 
 if [ $(id -u) = 0 ]; then
-
-    # Set compiler.
-    switch_compilers
-
     # Drop privileges by re-running this script.
     exec su worker $0 $@
 fi
 
 # Clone NSPR if needed.
 if [ ! -d "nspr" ]; then
     hg_clone https://hg.mozilla.org/projects/nspr nspr default
 fi
@@ -30,17 +26,17 @@ declare -A scan=( \
     )
 
 # remove .OBJ directories to force a rebuild of just the select few
 for i in "${!scan[@]}"; do
    find "$i" -name "*.OBJ" -exec rm -rf {} \+
 done
 
 # run scan-build (only building affected directories)
-scan-build -o /home/worker/artifacts make nss_build_all && cd ..
+scan-build -o /home/worker/artifacts --use-cc=$(CC) --use-c++=$(CCC) make nss_build_all && cd ..
 
 # print errors we found
 set +v +x
 STATUS=0
 for i in "${!scan[@]}"; do
    n=$(grep -Rn "$i" /home/worker/artifacts/*/report-*.html | wc -l)
    if [ $n -ne ${scan[$i]} ]; then
      STATUS=1
--- a/automation/taskcluster/scripts/run_tests.sh
+++ b/automation/taskcluster/scripts/run_tests.sh
@@ -1,16 +1,13 @@
 #!/usr/bin/env bash
 
 source $(dirname $0)/tools.sh
 
 if [ $(id -u) = 0 ]; then
-    # Set compiler.
-    switch_compilers
-
     # Stupid Docker.
     echo "127.0.0.1 localhost.localdomain" >> /etc/hosts
 
     # Drop privileges by re-running this script.
     exec su worker $0
 fi
 
 # Fetch artifact if needed.
--- a/automation/taskcluster/scripts/tools.sh
+++ b/automation/taskcluster/scripts/tools.sh
@@ -1,25 +1,12 @@
 #!/usr/bin/env bash
 
 set -v -e -x
 
-switch_compilers() {
-    GCC=`which ${GCC_VERSION:-gcc-5}`
-    GXX=`which ${GXX_VERSION:-g++-5}`
-
-    if [ -e "$GCC" ] && [ -e "$GXX" ]; then
-        update-alternatives --set gcc $GCC
-        update-alternatives --set g++ $GXX
-    else
-        echo "Unknown compiler $GCC_VERSION/$GXX_VERSION."
-        exit 1
-    fi
-}
-
 # Usage: hg_clone repo dir [revision=@]
 hg_clone() {
     repo=$1
     dir=$2
     rev=${3:-@}
     for i in 0 2 5; do
         sleep $i
         hg clone -r "$rev" "$repo" "$dir" && return
--- a/coreconf/Darwin.mk
+++ b/coreconf/Darwin.mk
@@ -1,22 +1,22 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+CC     ?= gcc
+CCC    ?= g++
+RANLIB ?= ranlib
+
 include $(CORE_DEPTH)/coreconf/UNIX.mk
 include $(CORE_DEPTH)/coreconf/Werror.mk
 
 DEFAULT_COMPILER = gcc
 
-CC		= gcc
-CCC		= g++
-RANLIB		= ranlib
-
 ifndef CPU_ARCH
 # When cross-compiling, CPU_ARCH should already be defined as the target
 # architecture, set to powerpc or i386.
 CPU_ARCH	:= $(shell uname -p)
 endif
 
 ifeq (,$(filter-out i%86,$(CPU_ARCH)))
 ifdef USE_64
--- a/coreconf/Linux.mk
+++ b/coreconf/Linux.mk
@@ -1,30 +1,30 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+CC     ?= gcc
+CCC    ?= g++
+RANLIB ?= ranlib
+
 include $(CORE_DEPTH)/coreconf/UNIX.mk
 
 #
 # The default implementation strategy for Linux is now pthreads
 #
 ifneq ($(OS_TARGET),Android)
 	USE_PTHREADS = 1
 endif
 
 ifeq ($(USE_PTHREADS),1)
 	IMPL_STRATEGY = _PTH
 endif
 
-CC			= gcc
-CCC			= g++
-RANLIB			= ranlib
-
 DEFAULT_COMPILER = gcc
 
 ifeq ($(OS_TARGET),Android)
 ifndef ANDROID_NDK
 	$(error Must set ANDROID_NDK to the path to the android NDK first)
 endif
 ifndef ANDROID_TOOLCHAIN_VERSION
 	$(error Must set ANDROID_TOOLCHAIN_VERSION to the requested version number)