[dragonegg] r175968 - Rather than basing the list of supported languages on how gcc was configured,

Duncan Sands baldrick at free.fr
Sat Feb 23 09:26:41 PST 2013


Author: baldrick
Date: Sat Feb 23 11:26:41 2013
New Revision: 175968

URL: http://llvm.org/viewvc/llvm-project?rev=175968&view=rev
Log:
Rather than basing the list of supported languages on how gcc was configured,
instead try to compile a mini program for each language.  The problem with
looking at the configure line is that:
  - It can contain logical expressions like "all";
  - Default languages (C) might not be listed;
  - Distributions generally configure gcc with all languages, but the actual
    front-end is not installed by default (you have to install an extra package
    to get it).  For example on Debian based systems gcc will always have been
    configured for Fortran yet you can't compile Fortran programs unless you
    install the gfortran package.

Modified:
    dragonegg/trunk/Makefile
    dragonegg/trunk/test/DEUtils.py
    dragonegg/trunk/test/compilator/compilator-lit.cfg
    dragonegg/trunk/test/dragonegg-lit.site.cfg.in
    dragonegg/trunk/test/validator/validator-lit.cfg

Modified: dragonegg/trunk/Makefile
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Makefile?rev=175968&r1=175967&r2=175968&view=diff
==============================================================================
--- dragonegg/trunk/Makefile (original)
+++ dragonegg/trunk/Makefile Sat Feb 23 11:26:41 2013
@@ -59,7 +59,6 @@ GCC_VERSION=$(shell $(GCC) -dumpversion)
 GCC_MAJOR=$(word 1, $(subst ., ,$(GCC_VERSION)))
 GCC_MINOR=$(word 2, $(subst ., ,$(GCC_VERSION)))
 GCC_MICRO=$(word 3, $(subst ., ,$(GCC_VERSION)))
-GCC_LANGUAGES=c,$(shell $(GCC) -v 2>&1 | grep -o -- '--enable-languages=[^ ]*' | sed 's/--enable-languages=//')
 TARGET_TRIPLE=$(shell $(GCC) -dumpmachine)
 
 LLVM_VERSION=$(shell $(LLVM_CONFIG) --version)
@@ -152,7 +151,6 @@ $(LIT_SITE_CONFIG): $(TEST_SRC_DIR)/drag
 	$(QUIET)mkdir -p test
 	$(QUIET)echo s=@DRAGONEGG_PLUGIN@=$(CURDIR)/$(PLUGIN)=g > lit.tmp
 	$(QUIET)echo s=@GCC@=$(GCC)=g >> lit.tmp
-	$(QUIET)echo s=@GCC_LANGUAGES@=$(GCC_LANGUAGES)=g >> lit.tmp
 	$(QUIET)echo s=@LLVM_TOOLS_DIR@=$(LLVM_TOOLS_DIR)=g >> lit.tmp
 	$(QUIET)echo s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)-gcc-$(GCC_MAJOR).$(GCC_MINOR)=g >> lit.tmp
 	$(QUIET)echo s=@TEST_OUTPUT_DIR@=$(CURDIR)/test/Output=g >> lit.tmp

Modified: dragonegg/trunk/test/DEUtils.py
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/DEUtils.py?rev=175968&r1=175967&r2=175968&view=diff
==============================================================================
--- dragonegg/trunk/test/DEUtils.py (original)
+++ dragonegg/trunk/test/DEUtils.py Sat Feb 23 11:26:41 2013
@@ -1,3 +1,6 @@
+import tempfile
+import TestRunner
+
 suffixMap = {
   '.adb'   : 'ada',
   '.ads'   : 'ada',
@@ -20,16 +23,43 @@ suffixMap = {
   '.go'    : 'go',
   '.jar'   : 'java',
   '.class' : 'java',
-  '.m'     : 'objc',
-  '.mm'    : 'objc++',
+  '.m'     : 'objective-c',
+  '.mm'    : 'objective-c++',
 }
 
 def getLanguageForSuffix(suffix):
-    return suffixMap[suffix]
+  return suffixMap[suffix]
 
 def getSuffixesForLanguage(language):
-    suffixes = []
-    for suffix in suffixMap:
-       if suffixMap[suffix] == language:
-           suffixes.append(suffix)
-    return suffixes
+  suffixes = []
+  for suffix in suffixMap:
+     if suffixMap[suffix] == language:
+       suffixes.append(suffix)
+  return suffixes
+
+def isLanguageSupported(language, compiler):
+  # For most languages it suffices to try compiling an empty file.
+  source = tempfile.NamedTemporaryFile(mode='w+t')
+
+  # However for Ada and Go an empty file is not a valid compilation unit.
+  if language == 'ada':
+    # Use an obscure package name, as if the package is called XYZ and a file
+    # called XYZ.adb exists then the test will fail.
+    source.write('package U5TE4J886W is end;\n')
+  elif language == 'go':
+    source.write('package main\n')
+  # GCC doesn't recognize "-x fortran" so use "-x f77" instead.
+  elif language == 'fortran':
+    language = 'f77'
+
+  # If something was written then ensure it is visible to the compiler process.
+  source.flush()
+
+  # The language is supported if the file compiles without error.
+  out,err,exitCode = TestRunner.executeCommand([compiler, '-S', '-x',
+                          language, source.name])
+  return exitCode == 0
+
+def getSupportedLanguages(compiler):
+  allLanguages = set(suffixMap.values())
+  return [lang for lang in allLanguages if isLanguageSupported(lang, compiler)]

Modified: dragonegg/trunk/test/compilator/compilator-lit.cfg
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/compilator/compilator-lit.cfg?rev=175968&r1=175967&r2=175968&view=diff
==============================================================================
--- dragonegg/trunk/test/compilator/compilator-lit.cfg (original)
+++ dragonegg/trunk/test/compilator/compilator-lit.cfg Sat Feb 23 11:26:41 2013
@@ -16,7 +16,7 @@ config.test_exec_root = config.test_outp
 
 # suffixes: A list of file types to treat as compilable.
 config.suffixes = []
-for language in config.gcc_languages.split(','):
+for language in DEUtils.getSupportedLanguages(config.gcc_executable):
     config.suffixes = config.suffixes + DEUtils.getSuffixesForLanguage(language)
 
 config.language_flags = {

Modified: dragonegg/trunk/test/dragonegg-lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/dragonegg-lit.site.cfg.in?rev=175968&r1=175967&r2=175968&view=diff
==============================================================================
--- dragonegg/trunk/test/dragonegg-lit.site.cfg.in (original)
+++ dragonegg/trunk/test/dragonegg-lit.site.cfg.in Sat Feb 23 11:26:41 2013
@@ -1,6 +1,5 @@
 config.dragonegg_plugin = "@DRAGONEGG_PLUGIN@"
 config.gcc_executable   = "@GCC@"
-config.gcc_languages    = "@GCC_LANGUAGES@"
 config.llvm_tools_dir   = "@LLVM_TOOLS_DIR@"
 config.target_triple    = "@TARGET_TRIPLE@"
 config.test_output_dir  = "@TEST_OUTPUT_DIR@"

Modified: dragonegg/trunk/test/validator/validator-lit.cfg
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/validator-lit.cfg?rev=175968&r1=175967&r2=175968&view=diff
==============================================================================
--- dragonegg/trunk/test/validator/validator-lit.cfg (original)
+++ dragonegg/trunk/test/validator/validator-lit.cfg Sat Feb 23 11:26:41 2013
@@ -37,7 +37,7 @@ config.test_format = lit.formats.ShTest(
 
 # suffixes: A list of file extensions to treat as test files.
 config.suffixes = []
-for language in config.gcc_languages.split(','):
+for language in DEUtils.getSupportedLanguages(config.gcc_executable):
     config.suffixes = config.suffixes + DEUtils.getSuffixesForLanguage(language)
 
 # test_source_root: The root path where tests are located.





More information about the llvm-commits mailing list