changeset 16022:3f350b0d93c9

pass make variables on the command line instead of in environment variables to simplify running the make on the command line without mx
author Doug Simon <doug.simon@oracle.com>
date Wed, 04 Jun 2014 22:58:14 +0200
parents 0926a952ba55
children 774349ad0b03
files mx/mx_graal.py
diffstat 1 files changed, 41 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/mx/mx_graal.py	Wed Jun 04 22:18:38 2014 +0200
+++ b/mx/mx_graal.py	Wed Jun 04 22:58:14 2014 +0200
@@ -737,26 +737,35 @@
                 return
         else:
             cpus = multiprocessing.cpu_count()
-            runCmd = [mx.gmake_cmd()]
-            runCmd.append(build + buildSuffix)
+            makeDir = join(_graal_home, 'make')
+            runCmd = [mx.gmake_cmd(), '-C', makeDir]
+
             env = os.environ.copy()
 
+            # These must be passed as environment variables
+            env.setdefault('LANG', 'C')
+            env['JAVA_HOME'] = jdk
+
+            def setMakeVar(name, default, env=None):
+                """Sets a make variable on the command line to the value
+                   of the variable in 'env' with the same name if defined
+                   and 'env' is not None otherwise to 'default'
+                """
+                runCmd.append(name + '=' + (env.get(name, default) if env else default))
+
             if opts2.D:
                 for nv in opts2.D:
                     name, value = nv.split('=', 1)
-                    env[name.strip()] = value
-
-            env.setdefault('ARCH_DATA_MODEL', '64')
-            env.setdefault('LANG', 'C')
-            env.setdefault('HOTSPOT_BUILD_JOBS', str(cpus))
-            env.setdefault('ALT_BOOTDIR', mx.java().jdk)
+                    setMakeVar(name.strip(), value)
 
-            if not mx._opts.verbose:
-                runCmd.append('MAKE_VERBOSE=')
-            env['JAVA_HOME'] = jdk
+            setMakeVar('ARCH_DATA_MODEL', '64', env=env)
+            setMakeVar('HOTSPOT_BUILD_JOBS', str(cpus), env=env)
+            setMakeVar('ALT_BOOTDIR', mx.java().jdk, env=env)
+
+            setMakeVar('MAKE_VERBOSE', 'y' if mx._opts.verbose else '')
             if vm.endswith('nograal'):
-                env['INCLUDE_GRAAL'] = 'false'
-                env.setdefault('ALT_OUTPUTDIR', join(_graal_home, 'build-nograal', mx.get_os()))
+                setMakeVar('INCLUDE_GRAAL', 'false')
+                setMakeVar('ALT_OUTPUTDIR', join(_graal_home, 'build-nograal', mx.get_os()), env=env)
             else:
                 # extract latest release tag for graal
                 try:
@@ -768,34 +777,39 @@
                 if tags:
                     # extract the most recent tag
                     tag = sorted(tags, key=lambda e: [int(x) for x in e[len("graal-"):].split('.')], reverse=True)[0]
-                    env.setdefault('USER_RELEASE_SUFFIX', tag)
-                    env.setdefault('GRAAL_VERSION', tag[len("graal-"):])
+                    setMakeVar('USER_RELEASE_SUFFIX', tag)
+                    setMakeVar('GRAAL_VERSION', tag[len("graal-"):])
                 else:
                     version = 'unknown-{}-{}'.format(platform.node(), time.strftime('%Y-%m-%d_%H-%M-%S_%Z'))
-                    env.setdefault('USER_RELEASE_SUFFIX', 'graal-' + version)
-                    env.setdefault('GRAAL_VERSION', version)
-                env['INCLUDE_GRAAL'] = 'true'
-            env.setdefault('INSTALL', 'y')
+                    setMakeVar('USER_RELEASE_SUFFIX', 'graal-' + version)
+                    setMakeVar('GRAAL_VERSION', version)
+                setMakeVar('INCLUDE_GRAAL', 'true')
+            setMakeVar('INSTALL', 'y', env=env)
             if mx.get_os() == 'solaris':
                 # If using sparcWorks, setup flags to avoid make complaining about CC version
                 cCompilerVersion = subprocess.Popen('CC -V', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stderr.readlines()[0]
                 if cCompilerVersion.startswith('CC: Sun C++'):
                     compilerRev = cCompilerVersion.split(' ')[3]
-                    env.setdefault('ENFORCE_COMPILER_REV', compilerRev)
-                    env.setdefault('ENFORCE_CC_COMPILER_REV', compilerRev)
+                    setMakeVar('ENFORCE_COMPILER_REV', compilerRev, env=env)
+                    setMakeVar('ENFORCE_CC_COMPILER_REV', compilerRev, env=env)
                     if build == 'jvmg':
-                        # I want ALL the symbols when I'm debugging on Solaris
-                        # Some Makefile variable are overloaded by environment variable so we need to explicitely
-                        # pass them down in the command line. This one is an example of that.
-                        runCmd.append('STRIP_POLICY=no_strip')
+                        # We want ALL the symbols when debugging on Solaris
+                        setMakeVar('STRIP_POLICY', 'no_strip')
             # This removes the need to unzip the *.diz files before debugging in gdb
-            env.setdefault('ZIP_DEBUGINFO_FILES', '0')
+            setMakeVar('ZIP_DEBUGINFO_FILES', '0', env=env)
 
             # Clear these 2 variables as having them set can cause very confusing build problems
             env.pop('LD_LIBRARY_PATH', None)
             env.pop('CLASSPATH', None)
 
-            mx.run(runCmd, cwd=join(_graal_home, 'make'), err=filterXusage, env=env)
+            if mx._opts.verbose:
+                # Issue an env prefix that can be used to run the make on the command line
+                envPrefix = ' '.join([key + '=' + env[key] for key in env.iterkeys() if not os.environ.has_key(key) or env[key] != os.environ[key]])
+                if len(envPrefix):
+                    mx.log('env ' + envPrefix + ' \\')
+
+            runCmd.append(build + buildSuffix)
+            mx.run(runCmd, err=filterXusage, env=env)
 
         jvmCfg = _vmCfgInJdk(jdk)
         if not exists(jvmCfg):