def create_cmd(self, function, command):
     global compilers, linkers
     if function in self.cmd_type.instances:
         logger.error('Cannot add a {0} with the function `{1}` because one already exists.\n'
                 'Maybe you meant to use `modify-{0}`?',
                 self.cmd_type_name, args.function)
     return self.cmd_type(function, command)
예제 #2
0
    def create(self):
        from bs import compilers_and_linkers

        if compilers_and_linkers.CLEAN:
            for ff in [self.header, self.output]:
                if os.path.exists(ff):
                    print("removing {}".format(ff))
                    os.remove(ff)
        elif self.needs_updating:
            if self.target_language is None:
                logger.error(
                    "You must specify a target language for a SwigSource\n"
                    "This can be done in the `{}` file by setting the SwigSource.target_language attribute",
                    OBJECTIVES_FILE,
                )
            cmd = ["swig", "-{}".format(self.target_language)]
            if self.cpp:
                cmd.append("-c++")
            cmd.extend(["-o", self.name])
            cmd.extend(["-oh", self.header])
            cmd.extend(self.args)
            cmd.append(self.interface_file)
            print(" ".join(cmd))
            try:
                subprocess.check_call(cmd)
            except CalledProcessError:
                logger.error("subprocess call failed")
예제 #3
0
def get_builder(function):
    try:
        return instances[function]
    except KeyError:
        logger.error('Could not find a builder with the function `{}`.\n'
                'Available builders are:\n  {}\n' + Add.help,
                function, '\n  '.join(str(builder) for builder in instances.values()))
def get_compiler(function):
    try:
        return compilers[function]
    except KeyError:
        logger.error('could not find a compiler with the function `{}`.\n'
                'The available compilers are:\n  {}\n'
                'New compilers can be added using `add-compiler`',
                function, '\n  '.join(str(comp) for comp in compilers.values()))
 def invoke(self, args):
     cmd = self.get_cmd(args.function)
     if cmd is None:
         logger.error('Cannot find a {0} with the function `{1}`\n'
             'The available {0}s are:\n  {}\n'
             'Maybe you entered a {0} command instead of a function.\n{}',
             self.cmd_type_name,
             function,
             '\n  '.join(str(compiler) for compiler in instances.get(self.cmd_type_name, {}).values()),
             self.add_help())
     self._apply_options(cmd, args)
     config.save()
    def run(self, objective):
        if LIST:
            print(objective)
            for item in objective:
                if LIST_ALL or not isinstance(item, objectives.Object):
                    print('    {}'.format(item))
        if GRAPH:
            raise NotImplementedError
        if FLATTEN:
            print('') # new line for separation
            print('    flattened dependencies -- also lists sources')
            print('    ----------------------')
            for item in objective.flattened_dependencies():
                print('    {}'.format(item))

        if CLEAN:
            for item in objective.flattened_dependencies():
                if not isinstance(item, objectives.Source) and os.path.exists(item.output):
                    print('removing {}'.format(item.output))
                    os.remove(item.output)
            return

        if not LIST and not GRAPH and not FLATTEN:
            full_cmd = [self.command] + self.options
            for pp in self.paths:
                full_cmd.append('{}{}'.format(self.path_switch, pp))

            for item in objective.flattened_dependencies():
                if item.needs_updating:
                    output_dir = os.path.dirname(item.output)
                    if not os.path.exists(output_dir):
                        os.makedirs(output_dir)
                    specific_command = list(full_cmd)
                    for dep in item:
                        specific_command.append(dep.output)
                    specific_command.append('{}{}'.format(self.output_switch, item.output))
                    specific_command.extend(self.post_options)
                    print('{}'.format(' '.join(specific_command)))
                    try:
                        subprocess.check_call(specific_command)
                    except subprocess.CalledProcessError:
                        logger.error('subprocess call failed')