Ejemplo n.º 1
0
    def update_pair(self, dest, src):
        assert is_string(dest), \
            "dest is not a string: %s (src is %s)" % (str(dest), str(src))
        assert src is None or is_string(src), \
            "src is not a string: %s (dest is %s)" % (str(src), str(dest))

        for d in self.dirs:
            if dest in self.dirs[d]:
                self.dirs[d].remove(dest)
                self.dirs[d].append(FilePair(dest, src))
                return True
        # no such file
        return False
Ejemplo n.º 2
0
    def add_rule(self, directory, rules):
        """parses the rules defined in 'rules', applicable to the folder 'dir'

        This stores the rules internally for further processing.

        :type directory: string
        :type rules: list or None
        """
        if is_string(rules):
            rules = [rules]

        if directory.split('/')[0] == 'gnarl':
            collection = self.rules['gnarl']
            used_scenarios = self.lib_scenarios['gnarl']
        else:
            collection = self.rules['gnat']
            used_scenarios = self.lib_scenarios['gnat']
        assert directory not in collection, \
            "directory %s defined twice" % directory

        # add the rule object to the current set of rules
        rule = Rule(rules, scenarios=self.scenarios, as_new_rule=True)

        collection[directory] = rule

        # and make sure to update the list of used scenario variables
        for sc in rule.used_scenarios:
            if sc not in used_scenarios:
                used_scenarios.append(sc)
Ejemplo n.º 3
0
 def __eq__(self, other):
     if is_string(other):
         return self._dst == other
     elif isinstance(other, FilePair):
         return other._dst == self._dst and other._src == self._src
     else:
         return False
Ejemplo n.º 4
0
    def add_linker_script(self, script, dst=None, loader=''):
        """Adds a new linker script to the BSP.
        """
        assert is_string(script)

        if dst is None:
            # not a pair: just copy the script without renaming it
            obj = LdScript(os.path.basename(script), script, loader)
        else:
            obj = LdScript(dst, script, loader)

        assert obj not in self.ld_scripts, \
            "duplicated ld script name %s" % str(obj)

        self._ld_scripts.append(obj)
Ejemplo n.º 5
0
 def __init__(self, dst, src, loaders):
     super(LdScript, self).__init__(dst=dst, src=src)
     if loaders is None:
         self._loaders = None
     elif is_string(loaders):
         if len(loaders) == 0:
             self._loaders = tuple()
         else:
             self._loaders = (loaders, )
     elif isinstance(loaders, list):
         self._loaders = tuple(loaders)
     elif isinstance(loaders, tuple):
         self._loaders = loaders
     else:
         assert False, "unexpected type for loader %s" % str(loaders)
Ejemplo n.º 6
0
    def dump_runtime_xml(self, rts_name, rts):
        """Dumps the runtime.xml file that gives the configuration to gprbuild
        """
        ret = '<?xml version="1.0" ?>\n\n'
        ret += '<gprconfig>\n'
        ret += '  <configuration>\n'
        ret += '    <config><![CDATA[\n'
        if self.loaders is not None:
            # Add USER loader so users can always specify their own linker
            # script. To ensure the USER loader is always used for this
            # purpose it cannot be defined by a target
            assert 'USER' not in self.loaders, \
                "target cannot define USER loader"

            loaders = list(self.loaders) + ['USER']
        else:
            assert len(self.ld_scripts) <= 1, (
                "target configuration error: no loader specified and several"
                " ld scripts are defined")
            if len(self.ld_scripts) == 1:
                loaders = ['DEFAULT', 'USER']
                self.ld_scripts[0].add_loader('DEFAULT')
            else:
                loaders = ['USER']

        ret += '   type Loaders is ("%s");\n' % '", "'.join(loaders)
        ret += '   Loader : Loaders := external("LOADER", "%s");\n\n' % \
            loaders[0]

        ret += '   package Compiler is\n'
        if len(self.compiler_switches) > 0:
            ret += '      Common_Required_Switches := ("%s");\n' % \
                   '", "'.join(self.compiler_switches)
        else:
            ret += '      Common_Required_Switches := ();\n'

        if len(self.c_switches) > 0:
            ret += '      C_Required_Switches := ("%s");\n' % \
                   '", "'.join(self.c_switches)

        ret += '\n'

        for lang in ('Ada', 'C', 'Asm', 'Asm2', 'Asm_Cpp'):
            w = '      '
            ret += w + 'for Leading_Required_Switches ("%s") use\n' % lang
            w = '         '
            ret += w + 'Compiler\'Leading_Required_Switches ("%s") &\n' % \
                       lang
            ret += w + 'Common_Required_Switches'
            if lang != 'Ada' and len(self.c_switches) > 0:
                ret += ' &\n' + w
                ret += 'C_Required_Switches'
            ret += ';\n'
        ret += '   end Compiler;\n\n'

        switches = []
        for sw in self.ld_switches:
            if sw['loader'] is None or sw['loader'] == '':
                switches.append('"%s"' % sw['switch'])

        ret += '   package Linker is\n'
        indent = 6
        blank = indent * ' '
        ret += blank + \
            'for Required_Switches use Linker\'Required_Switches &\n'
        ret += blank + '  ("-Wl,-L${RUNTIME_DIR(Ada)}/adalib",\n'
        indent = 9
        blank = indent * ' '

        ret += blank + '"-nostartfiles"'
        if rts.rts_vars['RTS_Profile'] != "ravenscar-full":
            ret += ', "-nolibc"'
        else:
            # in the ravenscar-full case, the runtime depends on
            # functionalities from newlib, such as memory allocation.
            ret += ', "-lc", "-lgnat"'

        # Add the user script path first, so that they have precedence
        ret += ',\n' + blank + '"-L${RUNTIME_DIR(ada)}/ld_user"'
        # And then our own script(s), if any
        if len(self.ld_scripts) > 0:
            ret += ',\n' + blank + '"-L${RUNTIME_DIR(ada)}/ld"'

        if len(switches) > 0:
            ret += ',\n' + blank
            ret += (',\n' + blank).join(switches)
            blank = indent * ' '
        ret += ') &\n' + blank + 'Compiler.Common_Required_Switches;\n'
        indent = 6
        blank = indent * ' '

        if loaders is not None:
            ret += '\n' + blank
            ret += 'case Loader is\n'
            indent += 3
            blank = indent * ' '

            for loader in loaders:
                ret += blank
                ret += 'when "%s" =>\n' % loader
                if loader == 'USER':
                    continue
                indent += 3
                blank = indent * ' '

                switches = []
                for val in self.ld_scripts:
                    if val.loaders is None or loader in val.loaders:
                        switches.append('"-T", "%s"' % val.name)
                for sw in self.ld_switches:
                    if is_string(sw['loader']) \
                            and sw['loader'] == loader:
                        switches.append('"%s"' % sw['switch'])
                    if isinstance(sw['loader'], list) \
                            and loader in sw['loader']:
                        switches.append('"%s"' % sw['switch'])
                if len(switches) > 0:
                    ret += blank
                    ret += \
                        'for Required_Switches use Linker\'Required_Switches'
                    ret += ' &\n' + blank + '  '
                    ret += '(%s);\n' % (',\n   ' + blank).join(switches)
                indent -= 3
                blank = indent * ' '

            indent -= 3
            blank = indent * ' '
            ret += '%send case;\n' % blank

        ret += ('   end Linker;\n'
                ']]>\n'
                '   </config>\n'
                '  </configuration>\n'
                '</gprconfig>\n')
        return ret