Example #1
0
 def getBuildEnv(self, replaceVar=mx_subst.path_substitutions):
     env = super(SulongTestSuite, self).getBuildEnv(replaceVar=replaceVar)
     env['VPATH'] = os.path.join(self.dir, self.name)
     env['PROJECT'] = self.name
     env['TESTS'] = ' '.join(self.getTests())
     env['VARIANTS'] = ' '.join(self.getVariants())
     env['BUILD_REF'] = '1' if self.buildRef else '0'
     env['BUILD_SO'] = '1' if self.buildSharedObject else '0'
     env['SO_EXT'] = mx.add_lib_suffix("")
     env['CLANG'] = mx_sulong.findBundledLLVMProgram('clang')
     env['CLANGXX'] = mx_sulong.findBundledLLVMProgram('clang++')
     env['LLVM_OPT'] = mx_sulong.findBundledLLVMProgram('opt')
     env['LLVM_AS'] = mx_sulong.findBundledLLVMProgram('llvm-as')
     env['LLVM_DIS'] = mx_sulong.findBundledLLVMProgram('llvm-dis')
     env['LLVM_LINK'] = mx_sulong.findBundledLLVMProgram('llvm-link')
     env['LLVM_OBJCOPY'] = mx_sulong.findBundledLLVMProgram('llvm-objcopy')
     env['GRAALVM_LLVM_HOME'] = mx_subst.path_substitutions.substitute(
         "<path:SULONG_HOME>")
     if 'OS' not in env:
         env['OS'] = mx_subst.path_substitutions.substitute("<os>")
     if SulongTestSuite.haveDragonegg():
         env['DRAGONEGG'] = mx_sulong.dragonEggPath()
         env['DRAGONEGG_GCC'] = mx_sulong.getGCC()
         env['DRAGONEGG_LLVMAS'] = mx_sulong.findLLVMProgramForDragonegg(
             "llvm-as")
         env['DRAGONEGG_FC'] = mx_sulong.getGFortran()
         env['FC'] = mx_sulong.getGFortran()
     elif not self._is_needs_rebuild_call and getattr(
             self, 'requireDragonegg', False):
         mx.abort(
             'Could not find dragonegg, cannot build "{}" (requireDragonegg = True).'
             .format(self.name))
     return env
 def _default_cmake_vars(self):
     _config = dict()
     _config['CMAKE_INSTALL_PREFIX'] = self._install_dir
     _config['SULONG_PROJECT_NAME'] = self.name
     _config['SULONG_ENABLED_LANGUAGES'] = ';'.join(self._get_languages())
     _config[
         'SULONG_BUILD_SHARED_OBJECT'] = 'YES' if self.buildSharedObject else 'NO'
     _config['CLANG'] = mx_sulong.findBundledLLVMProgram('clang')
     _config['CLANGXX'] = mx_sulong.findBundledLLVMProgram('clang++')
     _config['LLVM_OPT'] = mx_sulong.findBundledLLVMProgram('opt')
     _config['LLVM_AS'] = mx_sulong.findBundledLLVMProgram('llvm-as')
     _config['LLVM_LINK'] = mx_sulong.findBundledLLVMProgram('llvm-link')
     _config['LLVM_CONFIG'] = mx_sulong.findBundledLLVMProgram(
         'llvm-config')
     _config['LLVM_OBJCOPY'] = mx_sulong.findBundledLLVMProgram(
         'llvm-objcopy')
     if DragonEggSupport.haveDragonegg():
         _config['DRAGONEGG'] = DragonEggSupport.pluginPath()
         _config['DRAGONEGG_GCC'] = DragonEggSupport.findGCCProgram(
             'gcc', optional=False)
         _config['DRAGONEGG_LLVM_LINK'] = DragonEggSupport.findLLVMProgram(
             "llvm-link")
         _config['DRAGONEGG_LLVMAS'] = DragonEggSupport.findLLVMProgram(
             "llvm-as")
         _config['DRAGONEGG_FC'] = DragonEggSupport.findGCCProgram(
             'gfortran', optional=False)
         _config['FC'] = DragonEggSupport.findGCCProgram('gfortran',
                                                         optional=False)
     return _config
 def _default_cmake_vars(self):
     _config = dict()
     _config['CMAKE_INSTALL_PREFIX'] = self._install_dir
     _config['SULONG_PROJECT_NAME'] = self.name
     _config['SULONG_ENABLED_LANGUAGES'] = ';'.join(self._get_languages())
     # _config['SULONG_VARIANTS'] = ';'.join(self.getVariants())
     # _config['SULONG_BUILD_REF'] = 'YES' if self.buildRef else 'NO'
     _config['SULONG_BUILD_SHARED_OBJECT'] = 'YES' if self.buildSharedObject else 'NO'
     # _config['SO_EXT'] = mx.add_lib_suffix("")
     _config['CLANG'] = mx_sulong.findBundledLLVMProgram('clang')
     _config['CLANGXX'] = mx_sulong.findBundledLLVMProgram('clang++')
     _config['LLVM_OPT'] = mx_sulong.findBundledLLVMProgram('opt')
     _config['LLVM_AS'] = mx_sulong.findBundledLLVMProgram('llvm-as')
     # _config['LLVM_DIS'] = mx_sulong.findBundledLLVMProgram('llvm-dis')
     _config['LLVM_LINK'] = mx_sulong.findBundledLLVMProgram('llvm-link')
     _config['LLVM_CONFIG'] = mx_sulong.findBundledLLVMProgram('llvm-config')
     _config['LLVM_OBJCOPY'] = mx_sulong.findBundledLLVMProgram('llvm-objcopy')
     # _config['GRAALVM_LLVM_HOME'] = mx_subst.path_substitutions.substitute("<path:SULONG_HOME>")
     # if 'OS' not in _config:
     #     _config['OS'] = mx_subst.path_substitutions.substitute("<os>")
     if DragonEggSupport.haveDragonegg():
         _config['DRAGONEGG'] = DragonEggSupport.pluginPath()
         _config['DRAGONEGG_GCC'] = DragonEggSupport.findGCCProgram('gcc', optional=False)
         _config['DRAGONEGG_LLVM_LINK'] = DragonEggSupport.findLLVMProgram("llvm-link")
         _config['DRAGONEGG_LLVMAS'] = DragonEggSupport.findLLVMProgram("llvm-as")
         _config['DRAGONEGG_FC'] = DragonEggSupport.findGCCProgram('gfortran', optional=False)
         _config['FC'] = DragonEggSupport.findGCCProgram('gfortran', optional=False)
     # elif not self._is_needs_rebuild_call and getattr(self, 'requireDragonegg', False):
     #     mx.abort('Could not find dragonegg, cannot build "{}" (requireDragonegg = True).'.format(self.name))
     return _config
 def getBuildEnv(self, replaceVar=mx_subst.path_substitutions):
     env = super(ExternalTestSuite, self).getBuildEnv(replaceVar=replaceVar)
     roots = [d.get_path(resolve=True) for d in self.buildDependencies if d.isPackedResourceLibrary()]
     env['PROJECT'] = self.name
     env['VPATH'] = ':'.join(roots)
     env['TESTFILE'] = self.getTestFile()
     env['VARIANTS'] = ' '.join(self.getVariants())
     env['BUILD_REF'] = '1' if self.buildRef else '0'
     env['BUILD_SO'] = '1' if self.buildSharedObject else '0'
     env['SO_EXT'] = mx.add_lib_suffix("")
     env['CLANG'] = mx_sulong.findBundledLLVMProgram('clang')
     env['CLANGXX'] = mx_sulong.findBundledLLVMProgram('clang++')
     env['LLVM_OPT'] = mx_sulong.findBundledLLVMProgram('opt')
     env['LLVM_AS'] = mx_sulong.findBundledLLVMProgram('llvm-as')
     env['LLVM_DIS'] = mx_sulong.findBundledLLVMProgram('llvm-dis')
     env['LLVM_LINK'] = mx_sulong.findBundledLLVMProgram('llvm-link')
     env['LLVM_OBJCOPY'] = mx_sulong.findBundledLLVMProgram('llvm-objcopy')
     env['GRAALVM_LLVM_HOME'] = mx_subst.path_substitutions.substitute("<path:SULONG_HOME>")
     if 'OS' not in env:
         env['OS'] = mx_subst.path_substitutions.substitute("<os>")
     if DragonEggSupport.haveDragonegg():
         env['DRAGONEGG'] = DragonEggSupport.pluginPath()
         env['DRAGONEGG_GCC'] = DragonEggSupport.findGCCProgram('gcc', optional=False)
         env['DRAGONEGG_LLVMAS'] = DragonEggSupport.findLLVMProgram("llvm-as")
         env['DRAGONEGG_FC'] = DragonEggSupport.findGCCProgram('gfortran', optional=False)
         env['FC'] = DragonEggSupport.findGCCProgram('gfortran', optional=False)
     elif not self._is_needs_rebuild_call and getattr(self, 'requireDragonegg', False):
         mx.abort('Could not find dragonegg, cannot build "{}" (requireDragonegg = True).'.format(self.name))
     return env
Example #5
0
def checkCFile(targetFile):
    mx.logvv("  checking file " + targetFile)
    """ Checks the formatting of a C file and returns True if the formatting is okay """
    clangFormat = mx_sulong.findBundledLLVMProgram('clang-format')
    formatCommand = [clangFormat, targetFile]
    formattedContent = mx_sulong._decode(subprocess.check_output(formatCommand)).splitlines()
    with open(targetFile) as f:
        originalContent = f.read().splitlines()
    if not formattedContent == originalContent:
        # modify the file to the right format
        subprocess.check_output(formatCommand + ['-i'])
        mx.log('\n'.join(formattedContent))
        mx.log('\nmodified formatting in {0} to the format above'.format(targetFile))
        mx.logv("command: " + " ".join(formatCommand))
        return False
    return True
Example #6
0
 def getBuildEnv(self, replaceVar=mx_subst.path_substitutions):
     env = super(GeneratedTestSuite, self).getBuildEnv(replaceVar=replaceVar)
     env['VPATH'] = self.dir
     env['PROJECT'] = self.name
     env['TESTS'] = ' '.join(self.getTests())
     env['VARIANTS'] = ' '.join(self.getVariants())
     env['BUILD_REF'] = '1' if self.buildRef else '0'
     env['BUILD_SO'] = '1' if self.buildSharedObject else '0'
     env['SO_EXT'] = mx.add_lib_suffix("")
     env['CLANG'] = mx_sulong.findBundledLLVMProgram('clang')
     env['CLANGXX'] = mx_sulong.findBundledLLVMProgram('clang++')
     env['LLVM_OPT'] = mx_sulong.findBundledLLVMProgram('opt')
     env['LLVM_AS'] = mx_sulong.findBundledLLVMProgram('llvm-as')
     env['LLVM_DIS'] = mx_sulong.findBundledLLVMProgram('llvm-dis')
     env['LLVM_LINK'] = mx_sulong.findBundledLLVMProgram('llvm-link')
     env['LLVM_OBJCOPY'] = mx_sulong.findBundledLLVMProgram('llvm-objcopy')
     env['GRAALVM_LLVM_HOME'] = mx_subst.path_substitutions.substitute("<path:SULONG_HOME>")
     return env
Example #7
0
def bugpoint(args=None, out=None):
    parser = ArgumentParser(
        prog='mx bugpoint',
        description="Run 'bugpoint' with useful defaults.",
        epilog="Remaining arguments are passed to 'bugpoint'.")
    parser.add_argument(
        '--opt-command',
        help="Path to opt. (default: use 'opt' from the toolchain)",
        default=mx_sulong.findBundledLLVMProgram('opt'))
    parser.add_argument(
        '--keep-main',
        help='Force function reduction to keep main. (always true)',
        action='store_true')
    parser.add_argument(
        '--compile-custom',
        help=
        'Use -compile-command to define a command to compile the bitcode. Useful to avoid linking. (always true)',
        action='store_true')
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        '--compile-command',
        help=
        'Command to compile the bitcode. The command will be stored in a temporary script file.  (default:  %(default)s)',
        default='mx check-interesting')
    group.add_argument('--interestingness-test',
                       help='synonym for --compile-command',
                       dest='compile_command')
    parser.add_argument(
        '--mlimit',
        metavar="<MBytes>",
        help=
        'Maximum amount of memory to use. 0 disables check. Defaults to 0.',
        type=int,
        default=0)
    parser.add_argument('--help-bugpoint',
                        help='Show the bugpoint help.',
                        action='store_true')
    parsed_args, remaining_args = parser.parse_known_args(args)

    if parsed_args.help_bugpoint:
        mx_sulong.llvm_extra_tool(['bugpoint', '--help'])
        return

    class ClosedExecutableTempFile(object):
        def __init__(self, content, *args, **kwargs):
            self.content = content
            self.args = args
            self.kwargs = kwargs
            self.name = None

        def __enter__(self):
            with tempfile.NamedTemporaryFile(*self.args,
                                             delete=False,
                                             **self.kwargs) as fp:
                fp.write(mx._encode(self.content))
                st = os.stat(fp.name)
                os.chmod(fp.name, st.st_mode | stat.S_IEXEC)
                self.name = fp.name
            # ensure the file is closed!
            return self.name

        def __exit__(self, exc_type, exc_val, exc_tb):
            if self.name:
                os.remove(self.name)

    script_content = "#!/bin/bash\n"
    compile_command = parsed_args.compile_command
    if compile_command.startswith("mx "):
        compile_command = mx_sulong.get_mx_exe() + " -p {} ".format(
            mx_sulong._suite.dir) + compile_command[3:]
    script_content += compile_command + " $@\n"

    with ClosedExecutableTempFile(script_content,
                                  prefix="bugpoint-compile-command-",
                                  suffix=".sh") as compile_script:
        mx_sulong.llvm_extra_tool([
            'bugpoint', '--opt-command=' + parsed_args.opt_command,
            '--keep-main', '--compile-custom', '--mlimit=' +
            str(parsed_args.mlimit), '--compile-command=' + compile_script
        ] + remaining_args)