mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Merge pull request #2377 from sarahmarshy/flag_revision
Pass only relevant defines at each stage of compilationpull/2342/head
						commit
						9d1fbda9fe
					
				| 
						 | 
				
			
			@ -43,7 +43,7 @@ class Exporter(object):
 | 
			
		|||
        self.build_url_resolver = build_url_resolver
 | 
			
		||||
        jinja_loader = FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))
 | 
			
		||||
        self.jinja_environment = Environment(loader=jinja_loader)
 | 
			
		||||
        self.extra_symbols = extra_symbols
 | 
			
		||||
        self.extra_symbols = extra_symbols if extra_symbols else []
 | 
			
		||||
        self.config_macros = []
 | 
			
		||||
        self.sources_relative = sources_relative
 | 
			
		||||
        self.config_header = None
 | 
			
		||||
| 
						 | 
				
			
			@ -59,6 +59,11 @@ class Exporter(object):
 | 
			
		|||
    def progen_flags(self):
 | 
			
		||||
        if not hasattr(self, "_progen_flag_cache") :
 | 
			
		||||
            self._progen_flag_cache = dict([(key + "_flags", value) for key,value in self.flags.iteritems()])
 | 
			
		||||
            asm_defines = ["-D"+symbol for symbol in self.toolchain.get_symbols(True)]
 | 
			
		||||
            c_defines = ["-D" + symbol for symbol in self.toolchain.get_symbols()]
 | 
			
		||||
            self._progen_flag_cache['asm_flags'] += asm_defines
 | 
			
		||||
            self._progen_flag_cache['c_flags'] += c_defines
 | 
			
		||||
            self._progen_flag_cache['cxx_flags'] += c_defines
 | 
			
		||||
            if self.config_header:
 | 
			
		||||
                self._progen_flag_cache['c_flags'] += self.toolchain.get_config_option(self.config_header)
 | 
			
		||||
                self._progen_flag_cache['cxx_flags'] += self.toolchain.get_config_option(self.config_header)
 | 
			
		||||
| 
						 | 
				
			
			@ -214,11 +219,16 @@ class Exporter(object):
 | 
			
		|||
        """ This function returns symbols which must be exported.
 | 
			
		||||
            Please add / overwrite symbols in each exporter separately
 | 
			
		||||
        """
 | 
			
		||||
        symbols = self.toolchain.get_symbols() + self.config_macros
 | 
			
		||||
 | 
			
		||||
        # We have extra symbols from e.g. libraries, we want to have them also added to export
 | 
			
		||||
        if add_extra_symbols:
 | 
			
		||||
            if self.extra_symbols is not None:
 | 
			
		||||
                symbols.extend(self.extra_symbols)
 | 
			
		||||
        extra = self.extra_symbols if add_extra_symbols else []
 | 
			
		||||
        if hasattr(self, "MBED_CONFIG_HEADER_SUPPORTED") and self.MBED_CONFIG_HEADER_SUPPORTED:
 | 
			
		||||
            # If the config header is supported, we will preinclude it and do not not
 | 
			
		||||
            # need the macros as preprocessor flags
 | 
			
		||||
            return extra
 | 
			
		||||
 | 
			
		||||
        symbols = self.toolchain.get_symbols(True) + self.toolchain.get_symbols() \
 | 
			
		||||
                  + self.config_macros + extra
 | 
			
		||||
        return symbols
 | 
			
		||||
 | 
			
		||||
def zip_working_directory_and_clean_up(tempdirectory=None, destination=None, program_name=None, clean=True):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,8 +76,6 @@ class IAREmbeddedWorkbench(Exporter):
 | 
			
		|||
        project_data['tool_specific']['iar'].setdefault("misc", {})
 | 
			
		||||
        project_data['tool_specific']['iar'].update(tool_specific['iar'])
 | 
			
		||||
        project_data['tool_specific']['iar']['misc'].update(self.progen_flags)
 | 
			
		||||
        project_data['tool_specific']['iar']['misc']['asm_flags'].extend(
 | 
			
		||||
            ['-D%s' % d for d in self.toolchain.get_symbols()])
 | 
			
		||||
        # VLA is enabled via template IccAllowVLA
 | 
			
		||||
        project_data['tool_specific']['iar']['misc']['c_flags'].remove("--vla")
 | 
			
		||||
        project_data['common']['build_dir'] = os.path.join(project_data['common']['build_dir'], 'iar_arm')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,10 +73,14 @@ class Uvision4(Exporter):
 | 
			
		|||
 | 
			
		||||
        # get flags from toolchain and apply
 | 
			
		||||
        project_data['tool_specific']['uvision']['misc'] = {}
 | 
			
		||||
        # asm flags only, common are not valid within uvision project, they are armcc specific
 | 
			
		||||
        project_data['tool_specific']['uvision']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags']))
 | 
			
		||||
        # need to make this a string for progen. Only adds preprocessor when "macros" set
 | 
			
		||||
        asm_flag_string = '--cpreproc --cpreproc_opts=-D__ASSERT_MSG,' + ",".join(
 | 
			
		||||
            list(set(self.progen_flags['asm_flags'])))
 | 
			
		||||
        project_data['tool_specific']['uvision']['misc']['asm_flags'] = [asm_flag_string]
 | 
			
		||||
        # cxx flags included, as uvision have them all in one tab
 | 
			
		||||
        project_data['tool_specific']['uvision']['misc']['c_flags'] = list(set(self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags']))
 | 
			
		||||
        project_data['tool_specific']['uvision']['misc']['c_flags'] = list(set(
 | 
			
		||||
            ['-D__ASSERT_MSG'] + self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags[
 | 
			
		||||
                'cxx_flags']))
 | 
			
		||||
        # not compatible with c99 flag set in the template
 | 
			
		||||
        project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--c99")
 | 
			
		||||
        # cpp is not required as it's implicit for cpp files
 | 
			
		||||
| 
						 | 
				
			
			@ -85,17 +89,6 @@ class Uvision4(Exporter):
 | 
			
		|||
        project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--no_vla")
 | 
			
		||||
        project_data['tool_specific']['uvision']['misc']['ld_flags'] = self.progen_flags['ld_flags']
 | 
			
		||||
 | 
			
		||||
        i = 0
 | 
			
		||||
        for macro in project_data['common']['macros']:
 | 
			
		||||
            # armasm does not like floating numbers in macros, timestamp to int
 | 
			
		||||
            if macro.startswith('MBED_BUILD_TIMESTAMP'):
 | 
			
		||||
                timestamp = macro[len('MBED_BUILD_TIMESTAMP='):]
 | 
			
		||||
                project_data['common']['macros'][i] = 'MBED_BUILD_TIMESTAMP=' + str(int(float(timestamp)))
 | 
			
		||||
            # armasm does not even accept MACRO=string
 | 
			
		||||
            if macro.startswith('MBED_USERNAME'):
 | 
			
		||||
                project_data['common']['macros'].pop(i)
 | 
			
		||||
            i += 1
 | 
			
		||||
        project_data['common']['macros'].append('__ASSERT_MSG')
 | 
			
		||||
        project_data['common']['build_dir'] = project_data['common']['build_dir'] + '\\' + 'uvision4'
 | 
			
		||||
        if progen_build:
 | 
			
		||||
            self.progen_gen_file('uvision', project_data, True)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,10 +73,12 @@ class Uvision5(Exporter):
 | 
			
		|||
 | 
			
		||||
        # get flags from toolchain and apply
 | 
			
		||||
        project_data['tool_specific']['uvision5']['misc'] = {}
 | 
			
		||||
        # asm flags only, common are not valid within uvision project, they are armcc specific
 | 
			
		||||
        project_data['tool_specific']['uvision5']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags']))
 | 
			
		||||
 | 
			
		||||
        # need to make this a string got progen. Only adds preprocessor when "macros" set
 | 
			
		||||
        asm_flag_string = '--cpreproc --cpreproc_opts=-D__ASSERT_MSG,' + ",".join(list(set(self.progen_flags['asm_flags'])))
 | 
			
		||||
        project_data['tool_specific']['uvision5']['misc']['asm_flags'] = [asm_flag_string]
 | 
			
		||||
        # cxx flags included, as uvision have them all in one tab
 | 
			
		||||
        project_data['tool_specific']['uvision5']['misc']['c_flags'] = list(set(self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags']))
 | 
			
		||||
        project_data['tool_specific']['uvision5']['misc']['c_flags'] = list(set(['-D__ASSERT_MSG']+self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags']))
 | 
			
		||||
        # not compatible with c99 flag set in the template
 | 
			
		||||
        project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--c99")
 | 
			
		||||
        # cpp is not required as it's implicit for cpp files
 | 
			
		||||
| 
						 | 
				
			
			@ -85,17 +87,6 @@ class Uvision5(Exporter):
 | 
			
		|||
        project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--no_vla")
 | 
			
		||||
        project_data['tool_specific']['uvision5']['misc']['ld_flags'] = self.progen_flags['ld_flags']
 | 
			
		||||
 | 
			
		||||
        i = 0
 | 
			
		||||
        for macro in project_data['common']['macros']:
 | 
			
		||||
            # armasm does not like floating numbers in macros, timestamp to int
 | 
			
		||||
            if macro.startswith('MBED_BUILD_TIMESTAMP'):
 | 
			
		||||
                timestamp = macro[len('MBED_BUILD_TIMESTAMP='):]
 | 
			
		||||
                project_data['common']['macros'][i] = 'MBED_BUILD_TIMESTAMP=' + str(int(float(timestamp)))
 | 
			
		||||
            # armasm does not even accept MACRO=string
 | 
			
		||||
            if macro.startswith('MBED_USERNAME'):
 | 
			
		||||
                project_data['common']['macros'].pop(i)
 | 
			
		||||
            i += 1
 | 
			
		||||
        project_data['common']['macros'].append('__ASSERT_MSG')
 | 
			
		||||
        project_data['common']['build_dir'] = project_data['common']['build_dir'] + '\\' + 'uvision5'
 | 
			
		||||
        if progen_build:
 | 
			
		||||
            self.progen_gen_file('uvision5', project_data, True)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -230,7 +230,8 @@ class mbedToolchain:
 | 
			
		|||
        self.macros = macros or []
 | 
			
		||||
 | 
			
		||||
        # Macros generated from toolchain and target rules/features
 | 
			
		||||
        self.symbols = None
 | 
			
		||||
        self.asm_symbols = None
 | 
			
		||||
        self.cxx_symbols = None
 | 
			
		||||
 | 
			
		||||
        # Labels generated from toolchain and target rules/features (used for selective build)
 | 
			
		||||
        self.labels = None
 | 
			
		||||
| 
						 | 
				
			
			@ -372,36 +373,50 @@ class mbedToolchain:
 | 
			
		|||
        event['toolchain'] = self
 | 
			
		||||
        return self.notify_fun(event, self.silent)
 | 
			
		||||
 | 
			
		||||
    def get_symbols(self):
 | 
			
		||||
        if self.symbols is None:
 | 
			
		||||
            # Target and Toolchain symbols
 | 
			
		||||
            labels = self.get_labels()
 | 
			
		||||
            self.symbols = ["TARGET_%s" % t for t in labels['TARGET']]
 | 
			
		||||
            self.symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
 | 
			
		||||
    def get_symbols(self, for_asm=False):
 | 
			
		||||
        if for_asm:
 | 
			
		||||
            if self.asm_symbols is None:
 | 
			
		||||
                self.asm_symbols = []
 | 
			
		||||
 | 
			
		||||
            # Cortex CPU symbols
 | 
			
		||||
            if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
 | 
			
		||||
                self.symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
 | 
			
		||||
                # Cortex CPU symbols
 | 
			
		||||
                if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
 | 
			
		||||
                    self.asm_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
 | 
			
		||||
 | 
			
		||||
            # Symbols defined by the on-line build.system
 | 
			
		||||
            self.symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
 | 
			
		||||
            if MBED_ORG_USER:
 | 
			
		||||
                self.symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
 | 
			
		||||
                # Add target's symbols
 | 
			
		||||
                self.asm_symbols += self.target.macros
 | 
			
		||||
                # Add extra symbols passed via 'macros' parameter
 | 
			
		||||
                self.asm_symbols += self.macros
 | 
			
		||||
            return list(set(self.asm_symbols))  # Return only unique symbols
 | 
			
		||||
        else:
 | 
			
		||||
            if self.cxx_symbols is None:
 | 
			
		||||
                # Target and Toolchain symbols
 | 
			
		||||
                labels = self.get_labels()
 | 
			
		||||
                self.cxx_symbols = ["TARGET_%s" % t for t in labels['TARGET']]
 | 
			
		||||
                self.cxx_symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
 | 
			
		||||
 | 
			
		||||
            # Add target's symbols
 | 
			
		||||
            self.symbols += self.target.macros
 | 
			
		||||
            # Add target's hardware
 | 
			
		||||
            self.symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
 | 
			
		||||
            # Add target's features
 | 
			
		||||
            self.symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
 | 
			
		||||
            # Add extra symbols passed via 'macros' parameter
 | 
			
		||||
            self.symbols += self.macros
 | 
			
		||||
                # Cortex CPU symbols
 | 
			
		||||
                if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
 | 
			
		||||
                    self.cxx_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
 | 
			
		||||
 | 
			
		||||
            # Form factor variables
 | 
			
		||||
            if hasattr(self.target, 'supported_form_factors'):
 | 
			
		||||
                self.symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
 | 
			
		||||
                # Symbols defined by the on-line build.system
 | 
			
		||||
                self.cxx_symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
 | 
			
		||||
                if MBED_ORG_USER:
 | 
			
		||||
                    self.cxx_symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
 | 
			
		||||
 | 
			
		||||
        return list(set(self.symbols))  # Return only unique symbols
 | 
			
		||||
                # Add target's symbols
 | 
			
		||||
                self.cxx_symbols += self.target.macros
 | 
			
		||||
                # Add target's hardware
 | 
			
		||||
                self.cxx_symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
 | 
			
		||||
                # Add target's features
 | 
			
		||||
                self.cxx_symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
 | 
			
		||||
                # Add extra symbols passed via 'macros' parameter
 | 
			
		||||
                self.cxx_symbols += self.macros
 | 
			
		||||
 | 
			
		||||
                # Form factor variables
 | 
			
		||||
                if hasattr(self.target, 'supported_form_factors'):
 | 
			
		||||
                    self.cxx_symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
 | 
			
		||||
 | 
			
		||||
            return list(set(self.cxx_symbols))  # Return only unique symbols
 | 
			
		||||
 | 
			
		||||
    # Extend the internal list of macros
 | 
			
		||||
    def add_macros(self, new_macros):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -128,16 +128,17 @@ class ARM(mbedToolchain):
 | 
			
		|||
    def get_config_option(self, config_header):
 | 
			
		||||
        return ['--preinclude=' + config_header]
 | 
			
		||||
 | 
			
		||||
    def get_compile_options(self, defines, includes):        
 | 
			
		||||
    def get_compile_options(self, defines, includes, for_asm=False):        
 | 
			
		||||
        opts = ['-D%s' % d for d in defines]
 | 
			
		||||
        if self.RESPONSE_FILES:
 | 
			
		||||
            opts += ['--via', self.get_inc_file(includes)]
 | 
			
		||||
        else:
 | 
			
		||||
            opts += ["-I%s" % i for i in includes]
 | 
			
		||||
 | 
			
		||||
        config_header = self.get_config_header()
 | 
			
		||||
        if config_header is not None:
 | 
			
		||||
            opts = opts + self.get_config_option(config_header)
 | 
			
		||||
        if not for_asm:
 | 
			
		||||
            config_header = self.get_config_header()
 | 
			
		||||
            if config_header is not None:
 | 
			
		||||
                opts = opts + self.get_config_option(config_header)
 | 
			
		||||
        return opts
 | 
			
		||||
 | 
			
		||||
    @hook_tool
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +149,7 @@ class ARM(mbedToolchain):
 | 
			
		|||
        tempfile = join(dir, basename(object) + '.E.s')
 | 
			
		||||
        
 | 
			
		||||
        # Build preprocess assemble command
 | 
			
		||||
        cmd_pre = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-E", "-o", tempfile, source]
 | 
			
		||||
        cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]
 | 
			
		||||
 | 
			
		||||
        # Build main assemble command
 | 
			
		||||
        cmd = self.asm + ["-o", object, tempfile]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -170,22 +170,23 @@ class GCC(mbedToolchain):
 | 
			
		|||
    def get_config_option(self, config_header):
 | 
			
		||||
        return ['-include', config_header]
 | 
			
		||||
 | 
			
		||||
    def get_compile_options(self, defines, includes):
 | 
			
		||||
    def get_compile_options(self, defines, includes, for_asm=False):
 | 
			
		||||
        opts = ['-D%s' % d for d in defines]
 | 
			
		||||
        if self.RESPONSE_FILES:
 | 
			
		||||
            opts += ['@%s' % self.get_inc_file(includes)]
 | 
			
		||||
        else:
 | 
			
		||||
            opts += ["-I%s" % i for i in includes]
 | 
			
		||||
 | 
			
		||||
        config_header = self.get_config_header()
 | 
			
		||||
        if config_header is not None:
 | 
			
		||||
            opts = opts + self.get_config_option(config_header)
 | 
			
		||||
        if not for_asm:
 | 
			
		||||
            config_header = self.get_config_header()
 | 
			
		||||
            if config_header is not None:
 | 
			
		||||
                opts = opts + self.get_config_option(config_header)
 | 
			
		||||
        return opts
 | 
			
		||||
 | 
			
		||||
    @hook_tool
 | 
			
		||||
    def assemble(self, source, object, includes):
 | 
			
		||||
        # Build assemble command
 | 
			
		||||
        cmd = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-o", object, source]
 | 
			
		||||
        cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-o", object, source]
 | 
			
		||||
 | 
			
		||||
        # Call cmdline hook
 | 
			
		||||
        cmd = self.hook.get_cmdline_assembler(cmd)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -151,12 +151,7 @@ class IAR(mbedToolchain):
 | 
			
		|||
        else:
 | 
			
		||||
            opts += ["-I%s" % i for i in includes]
 | 
			
		||||
 | 
			
		||||
        config_header = self.get_config_header()
 | 
			
		||||
        if for_asm:
 | 
			
		||||
            # The assembler doesn't support '--preinclude', so we need to add
 | 
			
		||||
            # the macros directly
 | 
			
		||||
            opts = opts + ['-D%s' % d for d in self.get_config_macros()]
 | 
			
		||||
        else:
 | 
			
		||||
        if not for_asm:
 | 
			
		||||
            config_header = self.get_config_header()
 | 
			
		||||
            if config_header is not None:
 | 
			
		||||
                opts = opts + self.get_config_option(config_header)
 | 
			
		||||
| 
						 | 
				
			
			@ -165,7 +160,7 @@ class IAR(mbedToolchain):
 | 
			
		|||
    @hook_tool
 | 
			
		||||
    def assemble(self, source, object, includes):
 | 
			
		||||
        # Build assemble command
 | 
			
		||||
        cmd = self.asm + self.get_compile_options(self.get_symbols(), includes, for_asm=True) + ["-o", object, source]
 | 
			
		||||
        cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes, True) + ["-o", object, source]
 | 
			
		||||
 | 
			
		||||
        # Call cmdline hook
 | 
			
		||||
        cmd = self.hook.get_cmdline_assembler(cmd)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue