From 9a1e9149b8136abdd299207520f56d741116dffe Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Wed, 3 Oct 2018 20:29:29 -0400 Subject: [PATCH] Bug 1397263 - move AS checks to toolchain.configure; r=glandium This is a fairly straightforward port of the AS tool checks from old-configure to toolchain.configure. AS is a little quirky in that we currently do a normal-looking check for it, but then override that value to be the C compiler for non-Windows builds, and ml[64]/armasm64 for Windows builds. After migrating those checks, the only things left in the MOZ_DEFAULT_COMPILER macro in compiler-opts.m4 were some unused bits, so I removed them: * Setting of CPP/CXXCPP, which are set in toolchain.configure now * Setting HOST_LDFLAGS to empty, which doesn't seem particularly useful. There was also a quirky old test that the assembler was ml[64] when js-ctypes is enabled that I removed, I don't think it provides any value since this patch will ensure that we're using the right assembler for Windows builds. --- build/autoconf/compiler-opts.m4 | 33 ------- build/moz.configure/toolchain.configure | 113 ++++++++++++++++++++---- js/src/old-configure.in | 19 ---- old-configure.in | 14 --- python/mozbuild/mozbuild/backend/tup.py | 5 +- 5 files changed, 95 insertions(+), 89 deletions(-) diff --git a/build/autoconf/compiler-opts.m4 b/build/autoconf/compiler-opts.m4 index 02408969c52d..d7684e6736b8 100644 --- a/build/autoconf/compiler-opts.m4 +++ b/build/autoconf/compiler-opts.m4 @@ -4,39 +4,6 @@ dnl file, You can obtain one at http://mozilla.org/MPL/2.0/. dnl Add compiler specific options -AC_DEFUN([MOZ_DEFAULT_COMPILER], -[ -dnl Default to MSVC for win32 and gcc-4.2 for darwin -dnl ============================================================== -if test -z "$CROSS_COMPILE"; then -case "$target" in -*-mingw*) - if test -z "$CPP"; then CPP="$CC -E -nologo"; fi - if test -z "$CXXCPP"; then CXXCPP="$CXX -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi - if test -z "$AS"; then - case "${target_cpu}" in - i*86) - AS=ml; - ;; - x86_64) - AS=ml64; - ;; - aarch64) - AS=armasm64; - ;; - esac - fi - if test -z "$MIDL"; then MIDL=midl; fi - - # need override this flag since we don't use $(LDFLAGS) for this. - if test -z "$HOST_LDFLAGS" ; then - HOST_LDFLAGS=" " - fi - ;; -esac -fi -]) - dnl ============================================================================ dnl C++ rtti dnl We don't use it in the code, but it can be usefull for debugging, so give diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure index 179dbfa3d1a8..472ff25c0d37 100755 --- a/build/moz.configure/toolchain.configure +++ b/build/moz.configure/toolchain.configure @@ -796,6 +796,33 @@ def default_cxx_compilers(c_compiler, other_c_compiler=None, other_cxx_compiler= return default_cxx_compilers +@template +def provided_program(env_var): + '''Template handling cases where a program can be specified either as a + path or as a path with applicable arguments. + ''' + + @depends_if(env_var) + @imports(_from='itertools', _import='takewhile') + @imports(_from='mozbuild.shellutil', _import='split', _as='shell_split') + def provided(cmd): + # Assume the first dash-prefixed item (and any subsequent items) are + # command-line options, the item before the dash-prefixed item is + # the program we're looking for, and anything before that is a wrapper + # of some kind (e.g. sccache). + cmd = shell_split(cmd[0]) + + without_flags = list(takewhile(lambda x: not x.startswith('-'), cmd)) + + return namespace( + wrapper=without_flags[:-1], + program=without_flags[-1], + flags=cmd[len(without_flags):], + ) + + return provided + + @template def compiler(language, host_or_target, c_compiler=None, other_compiler=None, other_c_compiler=None): @@ -841,31 +868,14 @@ def compiler(language, host_or_target, c_compiler=None, other_compiler=None, # Handle the compiler given by the user through one of the CC/CXX/HOST_CC/ # HOST_CXX variables. - @depends_if(var) - @imports(_from='itertools', _import='takewhile') - @imports(_from='mozbuild.shellutil', _import='split', _as='shell_split') - def provided_compiler(cmd): - # Historically, the compiler variables have contained more than the - # path to the compiler itself. So for backwards compatibility, try to - # find what is what in there, assuming the first dash-prefixed item is - # a compiler option, the item before that is the compiler, and anything - # before that is a compiler wrapper. - cmd = shell_split(cmd[0]) - - without_flags = list(takewhile(lambda x: not x.startswith('-'), cmd)) - - return namespace( - wrapper=without_flags[:-1], - compiler=without_flags[-1], - flags=cmd[len(without_flags):], - ) + provided_compiler = provided_program(var) # Normally, we'd use `var` instead of `_var`, but the interaction with # old-configure complicates things, and for now, we a) can't take the plain # result from check_prog as CC/CXX/HOST_CC/HOST_CXX and b) have to let # old-configure AC_SUBST it (because it's autoconf doing it, not us) compiler = check_prog('_%s' % var, what=what, progs=default_compilers, - input=provided_compiler.compiler, + input=provided_compiler.program, paths=toolchain_search_path) @depends(compiler, provided_compiler, compiler_wrapper, host_or_target) @@ -1808,6 +1818,71 @@ set_config('LD_IS_BFD', depends(select_linker.KIND) add_old_configure_assignment('LINKER_LDFLAGS', select_linker.LINKER_FLAG) +# Assembler detection +# ============================================================== + +js_option(env='AS', nargs=1, help='Path to the assembler') + +@depends(target, c_compiler) +def as_info(target, c_compiler): + if c_compiler.type in ('msvc', 'clang-cl'): + ml = { + 'x86': 'ml', + 'x86_64': 'ml64', + 'aarch64': 'armasm64.exe', + }.get(target.cpu) + return namespace( + type='masm', + names=(ml, ) + ) + # When building with anything but MSVC, we just use the C compiler as the assembler. + return namespace( + type='gcc', + names=(c_compiler.compiler, ) + ) + +# One would expect the assembler to be specified merely as a program. But in +# cases where the assembler is passed down into js/, it can be specified in +# the same way as CC: a program + a list of argument flags. We might as well +# permit the same behavior in general, even though it seems somewhat unusual. +# So we have to do the same sort of dance as we did above with +# `provided_compiler`. +provided_assembler = provided_program('AS') +assembler = check_prog('_AS', input=provided_assembler.program, + what='the assembler', progs=as_info.names) + +@depends(as_info, assembler, provided_assembler, c_compiler) +def as_with_flags(as_info, assembler, provided_assembler, c_compiler): + if provided_assembler: + return provided_assembler.wrapper + \ + [provided_assembler.program] + \ + provided_assembler.flags + + if as_info.type == 'masm': + return assembler + + assert as_info.type == 'gcc' + + # Need to add compiler wrappers and flags as appropriate. + return c_compiler.wrapper + [assembler] + c_compiler.flags + + +add_old_configure_assignment('AS', as_with_flags) + +@depends(as_info, target) +def as_dash_c_flag(as_info, target): + # armasm64 doesn't understand -c. + if as_info.type == 'masm' and target.cpu == 'aarch64': + return '' + else: + return '-c' + + +set_config('AS_DASH_C_FLAG', as_dash_c_flag) + +# clang plugin handling +# ============================================================== + js_option('--enable-clang-plugin', env='ENABLE_CLANG_PLUGIN', help="Enable building with the mozilla clang plugin") diff --git a/js/src/old-configure.in b/js/src/old-configure.in index 09c98b8d8192..f255df9ad7fa 100644 --- a/js/src/old-configure.in +++ b/js/src/old-configure.in @@ -65,8 +65,6 @@ _PTHREAD_LDFLAGS="" LDFLAGS="$LDFLAGS $LINKER_LDFLAGS" -MOZ_DEFAULT_COMPILER - if test -z "$JS_STANDALONE"; then autoconfmk=autoconf-js.mk fi @@ -400,10 +398,7 @@ AC_SUBST(MOZJS_ALPHA) dnl ======================================================== dnl set the defaults first dnl ======================================================== -AS_BIN=$AS AR_EXTRACT='$(AR) x' -AS='$(CC)' -AS_DASH_C_FLAG='-c' MOZ_USER_DIR=".mozilla" MOZ_FIX_LINK_PATHS="-Wl,-rpath-link,${DIST}/bin -Wl,-rpath-link,${prefix}/lib" @@ -676,9 +671,6 @@ case "$target" in TARGET_COMPILER_ABI=msvc HOST_CC='$(CC)' HOST_CXX='$(CXX)' - if test "$AS_BIN"; then - AS="$(basename "$AS_BIN")" - fi case "$LINKER" in *lld*) AR='llvm-lib' @@ -1661,15 +1653,6 @@ dnl = dnl ======================================================== MOZ_ARG_HEADER(Standalone module options (Not for building Mozilla)) -if test "$JS_HAS_CTYPES"; then - dnl JS_HAS_CTYPES is defined by Python configure. This check remains - dnl as long as determining $AS remains in old-configure. - dnl Error out if we're on MSVC and MASM is unavailable. - if test -n "$_MSC_VER" -a \( "$AS" != "ml.exe" -a "$AS" != "ml64.exe" \); then - AC_MSG_ERROR([\"$AS\" is not a suitable assembler to build js-ctypes. If you are building with MS Visual Studio 8 Express, you may download the MASM 8.0 package, upgrade to Visual Studio 9 Express, or install the Vista SDK. Or do not use --enable-ctypes.]) - fi -fi - dnl ======================================================== dnl = dnl = Options for generating the shell as a script @@ -1694,10 +1677,8 @@ dnl ======================================================== AC_SUBST(AR) AC_SUBST(AR_FLAGS) AC_SUBST(AR_EXTRACT) -AC_SUBST(AS) AC_SUBST(NM) AC_SUBST_LIST(ASFLAGS) -AC_SUBST(AS_DASH_C_FLAG) AC_SUBST(RC) AC_SUBST(RCFLAGS) AC_SUBST(WINDRES) diff --git a/old-configure.in b/old-configure.in index 11b3f45bab4d..9131be073597 100644 --- a/old-configure.in +++ b/old-configure.in @@ -80,8 +80,6 @@ _PTHREAD_LDFLAGS="" LDFLAGS="$LDFLAGS $LINKER_LDFLAGS" -MOZ_DEFAULT_COMPILER - if test "$COMPILE_ENVIRONMENT"; then MOZ_ANDROID_NDK fi # COMPILE_ENVIRONMENT @@ -441,10 +439,7 @@ fi # COMPILE_ENVIRONMENT dnl ======================================================== dnl set the defaults first dnl ======================================================== -AS_BIN=$AS AR_EXTRACT='$(AR) x' -AS='$(CC)' -AS_DASH_C_FLAG='-c' MOZ_USER_DIR=".mozilla" MOZ_FIX_LINK_PATHS="-Wl,-rpath-link,${DIST}/bin -Wl,-rpath-link,${prefix}/lib" @@ -861,13 +856,6 @@ case "$target" in fi else TARGET_COMPILER_ABI=msvc - if test "$AS_BIN"; then - AS="$(basename "$AS_BIN")" - fi - # armasm64 doesn't understand -c. - if test "$CPU_ARCH" = "aarch64"; then - AS_DASH_C_FLAG= - fi case "$LINKER" in *lld*) AR='llvm-lib' @@ -3912,10 +3900,8 @@ dnl ======================================================== AC_SUBST(AR) AC_SUBST(AR_FLAGS) AC_SUBST(AR_EXTRACT) -AC_SUBST(AS) AC_SUBST(NM) AC_SUBST_LIST(ASFLAGS) -AC_SUBST(AS_DASH_C_FLAG) AC_SUBST(RC) AC_SUBST(RCFLAGS) AC_SUBST(WINDRES) diff --git a/python/mozbuild/mozbuild/backend/tup.py b/python/mozbuild/mozbuild/backend/tup.py index ea8dbbc67456..bc40dbb6769c 100644 --- a/python/mozbuild/mozbuild/backend/tup.py +++ b/python/mozbuild/mozbuild/backend/tup.py @@ -185,10 +185,7 @@ class BackendTupfile(object): for srcs, compiler, flags, dash_c, prefix in compilers: for src in sorted(srcs): self.export_icecc() - # AS can be set to $(CC), so we need to call expand_variables on - # the compiler to get the real value. - compiler_value = self.variables.get(compiler, self.environment.substs[compiler]) - cmd = [expand_variables(compiler_value, self.environment.substs)] + cmd = [self.variables.get(compiler, self.environment.substs[compiler])] cmd.extend(shell_quote(f) for f in self.local_flags[flags]) cmd.extend(shell_quote(f) for f in self.per_source_flags[src]) cmd.extend([dash_c, '%f', '-o', '%o'])