[llvm-commits] [LNT] r154716 - in /lnt/trunk: lnt/testing/util/compilers.py tests/SharedInputs/FakeCompilers/fakecompiler.py tests/testing/Compilers.py

Daniel Dunbar daniel at zuster.org
Fri Apr 13 16:36:19 PDT 2012


Author: ddunbar
Date: Fri Apr 13 18:36:19 2012
New Revision: 154716

URL: http://llvm.org/viewvc/llvm-project?rev=154716&view=rev
Log:
lnt.testing.util.compilers: Simplify get_cc_info() a bit to more clearly separate the interrogation from the parsing.

Modified:
    lnt/trunk/lnt/testing/util/compilers.py
    lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py
    lnt/trunk/tests/testing/Compilers.py

Modified: lnt/trunk/lnt/testing/util/compilers.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/util/compilers.py?rev=154716&r1=154715&r2=154716&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/util/compilers.py (original)
+++ lnt/trunk/lnt/testing/util/compilers.py Fri Apr 13 18:36:19 2012
@@ -16,46 +16,64 @@
     cc = path
 
     # Interrogate the compiler.
-    cc_version = capture([cc, '-v', '-E'] + cc_flags + 
+    cc_version = capture([cc, '-v', '-E'] + cc_flags +
                          ['-x', 'c', '/dev/null', '-###'],
                          include_stderr=True).strip()
 
-    # Check if this is icc, which isn't going to cooperate with most of our
-    # interrogation. This has only been tested for icc 11.1, it isn't
-    # particularly robust.
+    # Determine the assembler version, as found by the compiler.
+    cc_as_version = capture([cc, "-c", '-Wa,-v', '-o', '/dev/null'] + cc_flags +
+                            ['-x', 'assembler', '/dev/null'],
+                            include_stderr=True).strip()
+
+    # Determine the linker version, as found by the compiler.
+    tf = tempfile.NamedTemporaryFile(suffix='.c')
+    name = tf.name
+    tf.close()
+    tf = open(name, 'w')
+    print >>tf, "int main() { return 0; }"
+    tf.close()
+    cc_ld_version = capture(([cc, "-Wl,-v", '-o', '/dev/null'] +
+                             cc_flags + [tf.name]),
+                            include_stderr=True).strip()
+    rm_f(tf.name)
+
+    # Extract the default target .ll (or assembly, for non-LLVM compilers).
+    cc_target_assembly = capture([cc, '-S', '-flto', '-o', '-'] + cc_flags +
+                                 ['-x', 'c', '/dev/null'],
+                                 include_stderr=True).strip()
+
+    # Extract the compiler's response to -dumpmachine as the target.
+    cc_target = cc_dumpmachine = capture([cc, '-dumpmachine']).strip()
+
+    # Default the target to the response from dumpmachine.
+    cc_target = cc_dumpmachine
+
+    # Parse out the compiler's version line and the path to the "cc1" binary.
     cc1_binary = None
-    if cc_version.startswith('icc: command line warning'):
-        cc_name = 'icc'
-        cc_version = capture([cc, '-v'], include_stderr=True).strip()
-        cc_version_num = cc_version        
-        if cc_version_num.startswith('Version '):
-            cc_version_num = cc_version_num.split(' ', 1)[1]
-        cc_target = capture([cc, '-dumpmachine']).strip()
-    else:
-        version_ln = None
-        cc_target = None
-        for ln in cc_version.split('\n'):
-            if ' version ' in ln:
-                version_ln = ln
-            elif ln.startswith('Target:'):
-                cc_target = ln.split(':',1)[1].strip()
-            elif 'cc1' in ln or 'clang-cc' in ln:
-                m = re.match(r' "([^"]*)".*"-E".*', ln)
-                if not m:
-                    error("unable to determine cc1 binary: %r: %r" % (cc, ln))
-                cc1_binary, = m.groups()
-        if version_ln is None:
-            error("unable to find compiler version: %r: %r" % (cc, cc_version))
-        if cc_target is None:
-            error("unable to find compiler target: %r: %r" % (cc, cc_version))
-        if cc1_binary is None:
-            error("unable to find compiler cc1 binary: %r: %r" % (
-                    cc, cc_version))
-        m = re.match(r'(.*) version ([^ ]*) (\([^(]*\))(.*)', version_ln)
-        if not m:
-            error("unable to determine compiler version: %r: %r" % (
-                    cc, version_ln))
-        cc_name,cc_version_num,cc_build_string,cc_extra = m.groups()
+    version_ln = None
+    for ln in cc_version.split('\n'):
+        if ' version ' in ln:
+            version_ln = ln
+        elif 'cc1' in ln or 'clang-cc' in ln:
+            m = re.match(r' "([^"]*)".*"-E".*', ln)
+            if not m:
+                error("unable to determine cc1 binary: %r: %r" % (cc, ln))
+            cc1_binary, = m.groups()
+        elif "-_Amachine" in ln:
+            m = re.match(r'([^ ]*) *-.*', ln)
+            if not m:
+                error("unable to determine cc1 binary: %r: %r" % (cc, ln))
+            cc1_binary, = m.groups()
+    if version_ln is None:
+        error("unable to find compiler version: %r: %r" % (cc, cc_version))
+    if cc1_binary is None:
+        error("unable to find compiler cc1 binary: %r: %r" % (
+                cc, cc_version))
+    m = re.match(r'(.*) version ([^ ]*) (\([^(]*\))(.*)', version_ln)
+    if not m:
+        error("unable to determine compiler version: %r: %r" % (
+                cc, version_ln))
+    cc_name,cc_version_num,cc_build_string,cc_extra = m.groups()
 
     # Compute normalized compiler name and type. We try to grab source
     # revisions, branches, and tags when possible.
@@ -68,7 +86,8 @@
     if cc_name == 'icc':
         cc_norm_name = 'icc'
         cc_build = 'PROD'
-        
+        cc_src_tag = cc_version_num
+
     elif cc_name == 'gcc' and (cc_extra == '' or
                                re.match(r' \(dot [0-9]+\)', cc_extra)):
         cc_norm_name = 'gcc'
@@ -108,7 +127,7 @@
         if m:
             cc_build = 'PROD'
             cc_src_tag, = m.groups()
-            
+
             # We sometimes use a tag of 9999 to indicate a dev build.
             if cc_src_tag == '9999':
                 cc_build = 'DEV'
@@ -123,7 +142,7 @@
                 cc_alt_src_branch,cc_alt_src_revision = m.groups()
             else:
                 error('unable to determine Clang development build info: %r' % (
-                        (cc_name, cc_build_string, cc_extra)))
+                        (cc_name, cc_build_string, cc_extra),))
 
     elif cc_name == 'gcc' and 'LLVM build' in cc_extra:
         llvm_capable = True
@@ -145,44 +164,26 @@
 
     # If LLVM capable, fetch the llvm target instead.
     if llvm_capable:
-        target_cc_ll = capture([cc, '-S', '-flto', '-o', '-'] + cc_flags + 
-                               ['-x', 'c', '/dev/null'],
-                               include_stderr=True).strip()
-        m = re.search('target triple = "(.*)"', target_cc_ll)
+        m = re.search('target triple = "(.*)"', cc_target_assembly)
         if m:
             cc_target, = m.groups()
         else:
             error("unable to determine LLVM compiler target: %r: %r" %
                   (cc, target_cc_ll))
 
-    # Determine the binary tool versions for the assembler and the linker, as
-    # found by the compiler.
-    cc_as_version = capture([cc, "-c", '-Wa,-v', '-o', '/dev/null'] + cc_flags +
-                            ['-x', 'assembler', '/dev/null'],
-                            include_stderr=True).strip()
-
-    tf = tempfile.NamedTemporaryFile(suffix='.c')
-    name = tf.name
-    tf.close()
-    tf = open(name, 'w')
-    print >>tf, "int main() { return 0; }"
-    tf.close()
-    cc_ld_version = capture(([cc, "-Wl,-v", '-o', '/dev/null'] + 
-                             cc_flags + [tf.name]),
-                            include_stderr=True).strip()
-    rm_f(tf.name)
-
     cc_exec_hash = hashlib.sha1()
     cc_exec_hash.update(open(cc,'rb').read())
 
     info = { 'cc_build' : cc_build,
              'cc_name' : cc_norm_name,
              'cc_version_number' : cc_version_num,
+             'cc_dumpmachine' : cc_dumpmachine,
              'cc_target' : cc_target,
              'cc_version' :cc_version,
              'cc_exec_hash' : cc_exec_hash.hexdigest(),
              'cc_as_version' : cc_as_version,
              'cc_ld_version' : cc_ld_version,
+             'cc_target_assembly' : cc_target_assembly,
              }
     if cc1_binary is not None:
         cc1_exec_hash = hashlib.sha1()
@@ -258,10 +259,11 @@
     # Otherwise, try to let the compiler itself tell us what the '++' version
     # would be. This is useful when the compiler under test is a symlink to the
     # real compiler.
-    cxx_path = capture([cc_path, '-print-prog-name=%s' % expected_cxx_name]).strip()
+    cxx_path = capture([cc_path,
+                        '-print-prog-name=%s' % expected_cxx_name]).strip()
     if os.path.exists(cxx_path):
         return cxx_path
-    
+
 o__all__ = ['get_cc_info', 'infer_cxx_compiler']
 
 if __name__ == '__main__':

Modified: lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py?rev=154716&r1=154715&r2=154716&view=diff
==============================================================================
--- lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py (original)
+++ lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py Fri Apr 13 18:36:19 2012
@@ -15,9 +15,6 @@
 class FakeCompiler(object):
     compiler_name = None
 
-    def print_version(self):
-        raise NotImplementedError
-
     def print_verbose_info(self):
         raise NotImplementedError
 
@@ -35,13 +32,22 @@
     
 class ICCv12_1_3(FakeCompiler):
     compiler_name = "icc-12.1.3"
-    def print_version(self):
-        print >>sys.stderr, """\
-icc version 12.1.3 (gcc version 4.2.1 compatibility)"""
-
     def print_verbose_info(self):
         print >>sys.stderr, """\
-icc: command line warning #10006: ignoring unknown option '-###'"""
+icc: command line warning #10006: ignoring unknown option '-###'
+icc version 12.1.3 (gcc version 4.2.1 compatibility)
+/usr/bin/icc-2011-base/bin/intel64/mcpcom    -_g -mP3OPT_inline_alloca -D__HONOR_STD -D__ICC=1210 -D__INTEL_COMPILER=1210 "-_Acpu(x86_64)" "-_Amachine(x86_64)" -D__BLOCKS__ -D__PTRDIFF_TYPE__=long "-D__SIZE_TYPE__=unsigned long" -D__WCHAR_TYPE__=int -D__WINT_TYPE__=int "-D__INTMAX_TYPE__=long int" "-D__UINTMAX_TYPE__=long unsigned int" -D__LONG_MAX__=9223372036854775807L -D__QMSPP_ -D__OPTIMIZE__ -D__NO_MATH_INLINES -D__NO_STRING_INLINES -D__NO_INLINE__ -D__GNUC_GNU_INLINE__ -D__GNUC__=4 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=1 -D__APPLE_CC__=5658 -D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1073 -D__LITTLE_ENDIAN__ -D__DYNAMIC__ "-D__private_extern__=__attribute__((visibility("hidden")))" -D__LP64__ -D_LP64 -D__GXX_ABI_VERSION=1002 -D__USER_LABEL_PREFIX__=_ -D__REGISTER_PREFIX__= -D__INTEL_RTTI__ -D__x86_64 -D__x86_64__ -D_MT -D__INTEL_COMPILER_BUILD_DATE=20120130 -D__PIC__ -D__APPLE__ -D__MACH__ -D__pentium4 -D__pentium4__ -D__tune_pentium4__ -D__SSE2__ -D__SSE3__ -D_
 _SSSE3__ -D__SSE__ -D__MMX__ -_k -_8 -_l -_D -_a -_b -E --gnu_version=421 -_W5 --gcc-extern-inline --multibyte_chars --blocks --array_section --simd --simd_func -mP1OPT_print_version=FALSE -mP1OPT_version=12.1-intel64 -mGLOB_diag_use_message_catalog=FALSE /dev/null
+... more boring stuff here ...
+"""
+
+    def print_llvm_target(self):
+        print """\
+icc: command line warning #10006: ignoring unknown option '-flto'
+	.file "null"
+	.section	__DATA, __data
+# End
+	.subsections_via_symbols
+"""
 
     def print_dumpmachine(self):
         print """i686-apple-darwin11"""
@@ -56,35 +62,48 @@
 target triple = "x86_64-apple-darwin11.0.0"
 """
 
+    def print_dumpmachine(self):
+        print """x86_64-apple-darwin11.0.0"""
+
+# Clang build at r154331 (for example).
 class Clang_r154331(LLVMCompiler):
     compiler_name = "clang-r154331"
 
     def print_verbose_info(self):
-        self.print_version()
-        print >>sys.stderr, """\
- "%s" "-cc1" "-E" ... more boring stuff here ...""" % (
-            g_program,)
-
-    def print_version(self):
         print >>sys.stderr, """\
 clang version 3.1 (trunk 154331) (llvm/trunk 154329)
 Target: x86_64-apple-darwin11.3.0
 Thread model: posix"""
+        print >>sys.stderr, """\
+ "%s" "-cc1" "-E" ... more boring stuff here ...""" % (
+            g_program,)
 
-class AppleClang_138_1(LLVMCompiler):
-    compiler_name = "apple-clang-138.1"
+# Clang build from a git repository.
+class Clang_git(LLVMCompiler):
+    compiler_name = "clang-git"
 
     def print_verbose_info(self):
-        self.print_version()
+        print >>sys.stderr, """\
+clang version 3.1\
+ (git:/git/clang.git 37ce0feee598d82e7220fa0a4b110619cae6ea72)\
+ (git:/git/llvm.git 60fca4f64e697ad834ce7ee8c2e478cae394c7dc)
+Target: arm-apple-darwin11.4.0
+Thread model: posix"""
         print >>sys.stderr, """\
  "%s" "-cc1" "-E" ... more boring stuff here ...""" % (
             g_program,)
 
-    def print_version(self):
+class AppleClang_138_1(LLVMCompiler):
+    compiler_name = "apple-clang-138.1"
+
+    def print_verbose_info(self):
         print >>sys.stderr, """\
 Apple clang version 2.0 (tags/Apple/clang-138.1) (based on LLVM 2.9svn)
 Target: x86_64-apple-darwin11.3.0
 Thread model: posix"""
+        print >>sys.stderr, """\
+ "%s" "-cc1" "-E" ... more boring stuff here ...""" % (
+            g_program,)
 
 fake_compilers = dict((value.compiler_name, value)
                       for key,value in locals().items()
@@ -107,8 +126,6 @@
     args = tuple(sys.argv[1:])
     if args == ('-v', '-E', '-x', 'c', '/dev/null', '-###'):
         compiler_instance.print_verbose_info()
-    elif args == ('-v',):
-        compiler_instance.print_version()
     elif args == ('-dumpmachine',):
         compiler_instance.print_dumpmachine()
     elif args == ('-c', '-Wa,-v', '-o', '/dev/null', '-x', 'assembler',

Modified: lnt/trunk/tests/testing/Compilers.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/testing/Compilers.py?rev=154716&r1=154715&r2=154716&view=diff
==============================================================================
--- lnt/trunk/tests/testing/Compilers.py (original)
+++ lnt/trunk/tests/testing/Compilers.py Fri Apr 13 18:36:19 2012
@@ -24,7 +24,7 @@
 assert info['cc_name'] == 'icc'
 assert info['cc_build'] == 'PROD'
 assert info['cc_target'] == 'i686-apple-darwin11'
-assert info['inferred_run_order'] == '      0'
+assert info['inferred_run_order'] == '     12'
 
 # Check a random Clang from SVN.
 info = get_info("clang-r154331")





More information about the llvm-commits mailing list