|
14 | 14 | See the License for the specific language governing permissions and
|
15 | 15 | limitations under the License.
|
16 | 16 | """
|
17 |
| -from os.path import splitext, basename, join |
| 17 | +import os |
| 18 | + |
| 19 | +from os.path import splitext, basename, join, dirname |
18 | 20 | from random import randint
|
19 | 21 | from tools.utils import mkdir
|
20 | 22 | from tools.export.exporters import Exporter
|
@@ -79,32 +81,103 @@ def __gen_dir(self, dirname):
|
79 | 81 | def __generate_uid(self):
|
80 | 82 | return "%0.9u" % randint(0, 999999999)
|
81 | 83 |
|
| 84 | + @staticmethod |
| 85 | + def filter_dot(str): |
| 86 | + """ |
| 87 | + This function removes ./ from str. |
| 88 | + str must be converted with win_to_unix() before using this function. |
| 89 | + """ |
| 90 | + if str == None: |
| 91 | + return None |
| 92 | + if str[:2] == './': |
| 93 | + return str[2:] |
| 94 | + return str |
| 95 | + |
| 96 | + def build_excludelist(self): |
| 97 | + self.source_folders = [self.filter_dot(s) for s in set(dirname( |
| 98 | + src) for src in self.resources.c_sources + self.resources.cpp_sources + self.resources.s_sources)] |
| 99 | + if '.' in self.source_folders: |
| 100 | + self.source_folders.remove('.') |
| 101 | + #print source_folders |
| 102 | + |
| 103 | + top_folders = [f for f in set(s.split('/')[0] for s in self.source_folders)] |
| 104 | + #print top_folders |
| 105 | + |
| 106 | + for top_folder in top_folders: |
| 107 | + # |
| 108 | + for root, dirs, files in os.walk(top_folder, topdown=True): |
| 109 | + # Paths returned by os.walk() must be split with os.dep |
| 110 | + # to accomodate Windows weirdness. |
| 111 | + parts = root.split(os.sep) |
| 112 | + self.remove_unused('/'.join(parts)) |
| 113 | + |
| 114 | + def remove_unused(self, path): |
| 115 | + found = False |
| 116 | + for used in self.include_path: |
| 117 | + if path == used: |
| 118 | + found = True |
| 119 | + needToAdd = True |
| 120 | + if not found: |
| 121 | + for dir in self.exclude_dirs: |
| 122 | + # Do not exclude subfolders from excluded folder |
| 123 | + if path.find(dir+'/') != -1: |
| 124 | + needToAdd = False |
| 125 | + if needToAdd: |
| 126 | + self.exclude_dirs.append(path) |
| 127 | + |
82 | 128 | def generate(self):
|
83 | 129 | fp_hardware = "no"
|
84 | 130 | fp_abi = "soft"
|
85 | 131 | core = self.toolchain.target.core
|
86 | 132 | if core == "Cortex-M4F" or core == "Cortex-M7F":
|
87 | 133 | fp_hardware = "fpv4-sp-d16"
|
88 |
| - fp_abi = "soft-fp" |
| 134 | + fp_abi = "softfp" |
89 | 135 | elif core == "Cortex-M7FD":
|
90 | 136 | fp_hardware = "fpv5-d16"
|
91 |
| - fp_abi = "soft-fp" |
92 |
| - |
| 137 | + fp_abi = "softfp" |
| 138 | + |
| 139 | + self.resources.win_to_unix() |
| 140 | + |
93 | 141 | libraries = []
|
94 | 142 | for lib in self.resources.libraries:
|
95 | 143 | l, _ = splitext(basename(lib))
|
96 | 144 | libraries.append(l[3:])
|
97 | 145 |
|
| 146 | + self.include_path = [self.filter_dot(s) for s in self.resources.inc_dirs] |
| 147 | + print 'Include folders: {0}'.format(len(self.include_path)) |
| 148 | + #for dir in self.include_path: |
| 149 | + # print "%s" % dir |
| 150 | + |
| 151 | + self.exclude_dirs = [] |
| 152 | + self.build_excludelist() |
| 153 | + |
| 154 | + print 'Exclude folders: {0}'.format(len(self.exclude_dirs)) |
| 155 | + #for dir in self.exclude_dirs: |
| 156 | + # print "%s" % dir |
| 157 | + |
| 158 | + self.exclude_dirs = '|'.join(self.exclude_dirs) |
| 159 | + |
| 160 | + self.ld_script = self.filter_dot(self.resources.linker_script) |
| 161 | + #print 'Linker script: {0}'.format(self.ld_script) |
| 162 | + |
| 163 | + self.lib_dirs = [self.filter_dot(s) for s in self.resources.lib_dirs] |
| 164 | + |
| 165 | + self.symbols = [s.replace('"', '"') for s in self.toolchain.get_symbols()] |
| 166 | + #print "%s" % self.symbols |
| 167 | + |
98 | 168 | ctx = {
|
99 | 169 | 'name': self.project_name,
|
100 |
| - 'include_paths': self.resources.inc_dirs, |
101 |
| - 'linker_script': self.resources.linker_script, |
102 |
| - 'library_paths': self.resources.lib_dirs, |
| 170 | + 'include_paths': self.include_path, |
| 171 | + 'exclude_paths': self.exclude_dirs, |
| 172 | + 'linker_script': self.ld_script, |
| 173 | + 'library_paths': self.lib_dirs, |
103 | 174 | 'object_files': self.resources.objects,
|
104 | 175 | 'libraries': libraries,
|
105 |
| - 'symbols': self.toolchain.get_symbols(), |
| 176 | + 'symbols': self.symbols, |
106 | 177 | 'board_name': self.BOARDS[self.target.upper()]['name'],
|
107 | 178 | 'mcu_name': self.BOARDS[self.target.upper()]['mcuId'],
|
| 179 | + 'c_include_uid': self.__generate_uid(), |
| 180 | + 'cpp_include_uid': self.__generate_uid(), |
108 | 181 | 'debug_config_uid': self.__generate_uid(),
|
109 | 182 | 'debug_tool_compiler_uid': self.__generate_uid(),
|
110 | 183 | 'debug_tool_compiler_input_uid': self.__generate_uid(),
|
|
0 commit comments