takashi kadono
/
Nucleo_446
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/tools/resources/__init__.py@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | # mbed SDK |
kadonotakashi | 0:8fdf9a60065b | 2 | # Copyright (c) 2011-2013 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | # |
kadonotakashi | 0:8fdf9a60065b | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | # you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | # You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | # |
kadonotakashi | 0:8fdf9a60065b | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | # |
kadonotakashi | 0:8fdf9a60065b | 10 | # Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | # See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | # limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | |
kadonotakashi | 0:8fdf9a60065b | 16 | """ |
kadonotakashi | 0:8fdf9a60065b | 17 | # The scanning rules and Resources object. |
kadonotakashi | 0:8fdf9a60065b | 18 | |
kadonotakashi | 0:8fdf9a60065b | 19 | A project in Mbed OS contains metadata in the file system as directory names. |
kadonotakashi | 0:8fdf9a60065b | 20 | These directory names adhere to a set of rules referred to as scanning rules. |
kadonotakashi | 0:8fdf9a60065b | 21 | The following are the English version of the scanning rules: |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | Directory names starting with "TEST_", "TARGET_", "TOOLCHAIN_" and "FEATURE_" |
kadonotakashi | 0:8fdf9a60065b | 24 | are excluded from a build unless one of the following is true: |
kadonotakashi | 0:8fdf9a60065b | 25 | * The suffix after "TARGET_" is a target label (see target.labels). |
kadonotakashi | 0:8fdf9a60065b | 26 | * The suffix after "TOOLCHAIN_" is a toolchain label, defined by the |
kadonotakashi | 0:8fdf9a60065b | 27 | inheritance hierarchy of the toolchain class. |
kadonotakashi | 0:8fdf9a60065b | 28 | * The suffix after "FEATURE_" is a member of `target.features`. |
kadonotakashi | 0:8fdf9a60065b | 29 | |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | """ |
kadonotakashi | 0:8fdf9a60065b | 32 | |
kadonotakashi | 0:8fdf9a60065b | 33 | from __future__ import print_function, division, absolute_import |
kadonotakashi | 0:8fdf9a60065b | 34 | |
kadonotakashi | 0:8fdf9a60065b | 35 | import fnmatch |
kadonotakashi | 0:8fdf9a60065b | 36 | import re |
kadonotakashi | 0:8fdf9a60065b | 37 | from collections import namedtuple, defaultdict |
kadonotakashi | 0:8fdf9a60065b | 38 | from copy import copy |
kadonotakashi | 0:8fdf9a60065b | 39 | from itertools import chain |
kadonotakashi | 0:8fdf9a60065b | 40 | from os import walk, sep |
kadonotakashi | 0:8fdf9a60065b | 41 | from os.path import (join, splitext, dirname, relpath, basename, split, normcase, |
kadonotakashi | 0:8fdf9a60065b | 42 | abspath, exists) |
kadonotakashi | 0:8fdf9a60065b | 43 | |
kadonotakashi | 0:8fdf9a60065b | 44 | from .ignore import MbedIgnoreSet, IGNORE_FILENAME |
kadonotakashi | 0:8fdf9a60065b | 45 | |
kadonotakashi | 0:8fdf9a60065b | 46 | # Support legacy build conventions: the original mbed build system did not have |
kadonotakashi | 0:8fdf9a60065b | 47 | # standard labels for the "TARGET_" and "TOOLCHAIN_" specific directories, but |
kadonotakashi | 0:8fdf9a60065b | 48 | # had the knowledge of a list of these directories to be ignored. |
kadonotakashi | 0:8fdf9a60065b | 49 | LEGACY_IGNORE_DIRS = set([ |
kadonotakashi | 0:8fdf9a60065b | 50 | # Legacy Targets |
kadonotakashi | 0:8fdf9a60065b | 51 | 'LPC11U24', |
kadonotakashi | 0:8fdf9a60065b | 52 | 'LPC1768', |
kadonotakashi | 0:8fdf9a60065b | 53 | 'LPC2368', |
kadonotakashi | 0:8fdf9a60065b | 54 | 'LPC4088', |
kadonotakashi | 0:8fdf9a60065b | 55 | 'LPC812', |
kadonotakashi | 0:8fdf9a60065b | 56 | 'KL25Z', |
kadonotakashi | 0:8fdf9a60065b | 57 | |
kadonotakashi | 0:8fdf9a60065b | 58 | # Legacy Toolchains |
kadonotakashi | 0:8fdf9a60065b | 59 | 'ARM', |
kadonotakashi | 0:8fdf9a60065b | 60 | 'uARM', |
kadonotakashi | 0:8fdf9a60065b | 61 | 'IAR', |
kadonotakashi | 0:8fdf9a60065b | 62 | 'GCC_ARM', |
kadonotakashi | 0:8fdf9a60065b | 63 | 'GCC_CS', |
kadonotakashi | 0:8fdf9a60065b | 64 | 'GCC_CR', |
kadonotakashi | 0:8fdf9a60065b | 65 | 'GCC_CW', |
kadonotakashi | 0:8fdf9a60065b | 66 | 'GCC_CW_EWL', |
kadonotakashi | 0:8fdf9a60065b | 67 | 'GCC_CW_NEWLIB', |
kadonotakashi | 0:8fdf9a60065b | 68 | 'ARMC6', |
kadonotakashi | 0:8fdf9a60065b | 69 | |
kadonotakashi | 0:8fdf9a60065b | 70 | # Tests, here for simplicity |
kadonotakashi | 0:8fdf9a60065b | 71 | 'TESTS', |
kadonotakashi | 0:8fdf9a60065b | 72 | 'TEST_APPS', |
kadonotakashi | 0:8fdf9a60065b | 73 | ]) |
kadonotakashi | 0:8fdf9a60065b | 74 | LEGACY_TOOLCHAIN_NAMES = { |
kadonotakashi | 0:8fdf9a60065b | 75 | 'ARM_STD':'ARM', |
kadonotakashi | 0:8fdf9a60065b | 76 | 'ARM_MICRO': 'uARM', |
kadonotakashi | 0:8fdf9a60065b | 77 | 'GCC_ARM': 'GCC_ARM', |
kadonotakashi | 0:8fdf9a60065b | 78 | 'GCC_CR': 'GCC_CR', |
kadonotakashi | 0:8fdf9a60065b | 79 | 'IAR': 'IAR', |
kadonotakashi | 0:8fdf9a60065b | 80 | 'ARMC6': 'ARMC6', |
kadonotakashi | 0:8fdf9a60065b | 81 | } |
kadonotakashi | 0:8fdf9a60065b | 82 | |
kadonotakashi | 0:8fdf9a60065b | 83 | |
kadonotakashi | 0:8fdf9a60065b | 84 | FileRef = namedtuple("FileRef", "name path") |
kadonotakashi | 0:8fdf9a60065b | 85 | |
kadonotakashi | 0:8fdf9a60065b | 86 | class FileType(object): |
kadonotakashi | 0:8fdf9a60065b | 87 | C_SRC = "c" |
kadonotakashi | 0:8fdf9a60065b | 88 | CPP_SRC = "c++" |
kadonotakashi | 0:8fdf9a60065b | 89 | ASM_SRC = "s" |
kadonotakashi | 0:8fdf9a60065b | 90 | HEADER = "header" |
kadonotakashi | 0:8fdf9a60065b | 91 | INC_DIR = "inc" |
kadonotakashi | 0:8fdf9a60065b | 92 | LIB_DIR = "libdir" |
kadonotakashi | 0:8fdf9a60065b | 93 | LIB = "lib" |
kadonotakashi | 0:8fdf9a60065b | 94 | OBJECT = "o" |
kadonotakashi | 0:8fdf9a60065b | 95 | HEX = "hex" |
kadonotakashi | 0:8fdf9a60065b | 96 | BIN = "bin" |
kadonotakashi | 0:8fdf9a60065b | 97 | JSON = "json" |
kadonotakashi | 0:8fdf9a60065b | 98 | LD_SCRIPT = "ld" |
kadonotakashi | 0:8fdf9a60065b | 99 | LIB_REF = "libref" |
kadonotakashi | 0:8fdf9a60065b | 100 | BLD_REF = "bldref" |
kadonotakashi | 0:8fdf9a60065b | 101 | REPO_DIR = "repodir" |
kadonotakashi | 0:8fdf9a60065b | 102 | |
kadonotakashi | 0:8fdf9a60065b | 103 | def __init__(self): |
kadonotakashi | 0:8fdf9a60065b | 104 | raise NotImplemented |
kadonotakashi | 0:8fdf9a60065b | 105 | |
kadonotakashi | 0:8fdf9a60065b | 106 | class Resources(object): |
kadonotakashi | 0:8fdf9a60065b | 107 | ALL_FILE_TYPES = [ |
kadonotakashi | 0:8fdf9a60065b | 108 | FileType.C_SRC, |
kadonotakashi | 0:8fdf9a60065b | 109 | FileType.CPP_SRC, |
kadonotakashi | 0:8fdf9a60065b | 110 | FileType.ASM_SRC, |
kadonotakashi | 0:8fdf9a60065b | 111 | FileType.HEADER, |
kadonotakashi | 0:8fdf9a60065b | 112 | FileType.INC_DIR, |
kadonotakashi | 0:8fdf9a60065b | 113 | FileType.LIB_DIR, |
kadonotakashi | 0:8fdf9a60065b | 114 | FileType.LIB, |
kadonotakashi | 0:8fdf9a60065b | 115 | FileType.OBJECT, |
kadonotakashi | 0:8fdf9a60065b | 116 | FileType.HEX, |
kadonotakashi | 0:8fdf9a60065b | 117 | FileType.BIN, |
kadonotakashi | 0:8fdf9a60065b | 118 | FileType.JSON, |
kadonotakashi | 0:8fdf9a60065b | 119 | FileType.LD_SCRIPT, |
kadonotakashi | 0:8fdf9a60065b | 120 | FileType.LIB_REF, |
kadonotakashi | 0:8fdf9a60065b | 121 | FileType.BLD_REF, |
kadonotakashi | 0:8fdf9a60065b | 122 | FileType.REPO_DIR, |
kadonotakashi | 0:8fdf9a60065b | 123 | ] |
kadonotakashi | 0:8fdf9a60065b | 124 | |
kadonotakashi | 0:8fdf9a60065b | 125 | def __init__(self, notify, collect_ignores=False): |
kadonotakashi | 0:8fdf9a60065b | 126 | # publicly accessible things |
kadonotakashi | 0:8fdf9a60065b | 127 | self.ignored_dirs = [] |
kadonotakashi | 0:8fdf9a60065b | 128 | |
kadonotakashi | 0:8fdf9a60065b | 129 | # Pre-mbed 2.0 ignore dirs |
kadonotakashi | 0:8fdf9a60065b | 130 | self._legacy_ignore_dirs = (LEGACY_IGNORE_DIRS) |
kadonotakashi | 0:8fdf9a60065b | 131 | |
kadonotakashi | 0:8fdf9a60065b | 132 | # Primate parameters |
kadonotakashi | 0:8fdf9a60065b | 133 | self._notify = notify |
kadonotakashi | 0:8fdf9a60065b | 134 | self._collect_ignores = collect_ignores |
kadonotakashi | 0:8fdf9a60065b | 135 | |
kadonotakashi | 0:8fdf9a60065b | 136 | # Storage for file references, indexed by file type |
kadonotakashi | 0:8fdf9a60065b | 137 | self._file_refs = defaultdict(set) |
kadonotakashi | 0:8fdf9a60065b | 138 | |
kadonotakashi | 0:8fdf9a60065b | 139 | # Incremental scan related |
kadonotakashi | 0:8fdf9a60065b | 140 | self._label_paths = [] |
kadonotakashi | 0:8fdf9a60065b | 141 | self._labels = { |
kadonotakashi | 0:8fdf9a60065b | 142 | "TARGET": [], "TOOLCHAIN": [], "FEATURE": [], "COMPONENT": [] |
kadonotakashi | 0:8fdf9a60065b | 143 | } |
kadonotakashi | 0:8fdf9a60065b | 144 | self._prefixed_labels = set() |
kadonotakashi | 0:8fdf9a60065b | 145 | |
kadonotakashi | 0:8fdf9a60065b | 146 | # Path seperator style (defaults to OS-specific seperator) |
kadonotakashi | 0:8fdf9a60065b | 147 | self._sep = sep |
kadonotakashi | 0:8fdf9a60065b | 148 | |
kadonotakashi | 0:8fdf9a60065b | 149 | self._ignoreset = MbedIgnoreSet() |
kadonotakashi | 0:8fdf9a60065b | 150 | |
kadonotakashi | 0:8fdf9a60065b | 151 | def ignore_dir(self, directory): |
kadonotakashi | 0:8fdf9a60065b | 152 | if self._collect_ignores: |
kadonotakashi | 0:8fdf9a60065b | 153 | self.ignored_dirs.append(directory) |
kadonotakashi | 0:8fdf9a60065b | 154 | |
kadonotakashi | 0:8fdf9a60065b | 155 | def _collect_duplicates(self, dupe_dict, dupe_headers): |
kadonotakashi | 0:8fdf9a60065b | 156 | for filename in self.s_sources + self.c_sources + self.cpp_sources: |
kadonotakashi | 0:8fdf9a60065b | 157 | objname, _ = splitext(basename(filename)) |
kadonotakashi | 0:8fdf9a60065b | 158 | dupe_dict.setdefault(objname, set()) |
kadonotakashi | 0:8fdf9a60065b | 159 | dupe_dict[objname] |= set([filename]) |
kadonotakashi | 0:8fdf9a60065b | 160 | for filename in self.headers: |
kadonotakashi | 0:8fdf9a60065b | 161 | headername = basename(filename) |
kadonotakashi | 0:8fdf9a60065b | 162 | dupe_headers.setdefault(headername, set()) |
kadonotakashi | 0:8fdf9a60065b | 163 | dupe_headers[headername] |= set([headername]) |
kadonotakashi | 0:8fdf9a60065b | 164 | return dupe_dict, dupe_headers |
kadonotakashi | 0:8fdf9a60065b | 165 | |
kadonotakashi | 0:8fdf9a60065b | 166 | def detect_duplicates(self): |
kadonotakashi | 0:8fdf9a60065b | 167 | """Detect all potential ambiguities in filenames and report them with |
kadonotakashi | 0:8fdf9a60065b | 168 | a toolchain notification |
kadonotakashi | 0:8fdf9a60065b | 169 | """ |
kadonotakashi | 0:8fdf9a60065b | 170 | count = 0 |
kadonotakashi | 0:8fdf9a60065b | 171 | dupe_dict, dupe_headers = self._collect_duplicates(dict(), dict()) |
kadonotakashi | 0:8fdf9a60065b | 172 | for objname, filenames in dupe_dict.items(): |
kadonotakashi | 0:8fdf9a60065b | 173 | if len(filenames) > 1: |
kadonotakashi | 0:8fdf9a60065b | 174 | count+=1 |
kadonotakashi | 0:8fdf9a60065b | 175 | self._notify.tool_error( |
kadonotakashi | 0:8fdf9a60065b | 176 | "Object file %s.o is not unique! It could be made from: %s"\ |
kadonotakashi | 0:8fdf9a60065b | 177 | % (objname, " ".join(filenames))) |
kadonotakashi | 0:8fdf9a60065b | 178 | for headername, locations in dupe_headers.items(): |
kadonotakashi | 0:8fdf9a60065b | 179 | if len(locations) > 1: |
kadonotakashi | 0:8fdf9a60065b | 180 | count+=1 |
kadonotakashi | 0:8fdf9a60065b | 181 | self._notify.tool_error( |
kadonotakashi | 0:8fdf9a60065b | 182 | "Header file %s is not unique! It could be: %s" %\ |
kadonotakashi | 0:8fdf9a60065b | 183 | (headername, " ".join(locations))) |
kadonotakashi | 0:8fdf9a60065b | 184 | return count |
kadonotakashi | 0:8fdf9a60065b | 185 | |
kadonotakashi | 0:8fdf9a60065b | 186 | def win_to_unix(self): |
kadonotakashi | 0:8fdf9a60065b | 187 | self._sep = "/" |
kadonotakashi | 0:8fdf9a60065b | 188 | if self._sep != sep: |
kadonotakashi | 0:8fdf9a60065b | 189 | for file_type in self.ALL_FILE_TYPES: |
kadonotakashi | 0:8fdf9a60065b | 190 | v = [f._replace(name=f.name.replace(sep, self._sep)) for |
kadonotakashi | 0:8fdf9a60065b | 191 | f in self.get_file_refs(file_type)] |
kadonotakashi | 0:8fdf9a60065b | 192 | self._file_refs[file_type] = v |
kadonotakashi | 0:8fdf9a60065b | 193 | |
kadonotakashi | 0:8fdf9a60065b | 194 | def __str__(self): |
kadonotakashi | 0:8fdf9a60065b | 195 | s = [] |
kadonotakashi | 0:8fdf9a60065b | 196 | |
kadonotakashi | 0:8fdf9a60065b | 197 | for (label, file_type) in ( |
kadonotakashi | 0:8fdf9a60065b | 198 | ('Include Directories', FileType.INC_DIR), |
kadonotakashi | 0:8fdf9a60065b | 199 | ('Headers', FileType.HEADER), |
kadonotakashi | 0:8fdf9a60065b | 200 | |
kadonotakashi | 0:8fdf9a60065b | 201 | ('Assembly sources', FileType.ASM_SRC), |
kadonotakashi | 0:8fdf9a60065b | 202 | ('C sources', FileType.C_SRC), |
kadonotakashi | 0:8fdf9a60065b | 203 | ('C++ sources', FileType.CPP_SRC), |
kadonotakashi | 0:8fdf9a60065b | 204 | |
kadonotakashi | 0:8fdf9a60065b | 205 | ('Library directories', FileType.LIB_DIR), |
kadonotakashi | 0:8fdf9a60065b | 206 | ('Objects', FileType.OBJECT), |
kadonotakashi | 0:8fdf9a60065b | 207 | ('Libraries', FileType.LIB), |
kadonotakashi | 0:8fdf9a60065b | 208 | |
kadonotakashi | 0:8fdf9a60065b | 209 | ('Hex files', FileType.HEX), |
kadonotakashi | 0:8fdf9a60065b | 210 | ('Bin files', FileType.BIN), |
kadonotakashi | 0:8fdf9a60065b | 211 | ('Linker script', FileType.LD_SCRIPT) |
kadonotakashi | 0:8fdf9a60065b | 212 | ): |
kadonotakashi | 0:8fdf9a60065b | 213 | resources = self.get_file_refs(file_type) |
kadonotakashi | 0:8fdf9a60065b | 214 | if resources: |
kadonotakashi | 0:8fdf9a60065b | 215 | s.append('%s:\n ' % label + '\n '.join( |
kadonotakashi | 0:8fdf9a60065b | 216 | "%s -> %s" % (name, path) for name, path in resources)) |
kadonotakashi | 0:8fdf9a60065b | 217 | |
kadonotakashi | 0:8fdf9a60065b | 218 | return '\n'.join(s) |
kadonotakashi | 0:8fdf9a60065b | 219 | |
kadonotakashi | 0:8fdf9a60065b | 220 | |
kadonotakashi | 0:8fdf9a60065b | 221 | def _add_labels(self, prefix, labels): |
kadonotakashi | 0:8fdf9a60065b | 222 | self._labels[prefix].extend(labels) |
kadonotakashi | 0:8fdf9a60065b | 223 | self._prefixed_labels |= set("%s_%s" % (prefix, label) for label in labels) |
kadonotakashi | 0:8fdf9a60065b | 224 | for path, base_path, into_path in self._label_paths: |
kadonotakashi | 0:8fdf9a60065b | 225 | if basename(path) in self._prefixed_labels: |
kadonotakashi | 0:8fdf9a60065b | 226 | self.add_directory(path, base_path, into_path) |
kadonotakashi | 0:8fdf9a60065b | 227 | self._label_paths = [(p, b, i) for p, b, i in self._label_paths |
kadonotakashi | 0:8fdf9a60065b | 228 | if basename(p) not in self._prefixed_labels] |
kadonotakashi | 0:8fdf9a60065b | 229 | |
kadonotakashi | 0:8fdf9a60065b | 230 | def add_target_labels(self, target): |
kadonotakashi | 0:8fdf9a60065b | 231 | self._add_labels("TARGET", target.labels) |
kadonotakashi | 0:8fdf9a60065b | 232 | self._add_labels("COMPONENT", target.components) |
kadonotakashi | 0:8fdf9a60065b | 233 | self.add_features(target.features) |
kadonotakashi | 0:8fdf9a60065b | 234 | |
kadonotakashi | 0:8fdf9a60065b | 235 | def add_features(self, features): |
kadonotakashi | 0:8fdf9a60065b | 236 | self._add_labels("FEATURE", features) |
kadonotakashi | 0:8fdf9a60065b | 237 | |
kadonotakashi | 0:8fdf9a60065b | 238 | def add_toolchain_labels(self, toolchain): |
kadonotakashi | 0:8fdf9a60065b | 239 | for prefix, value in toolchain.get_labels().items(): |
kadonotakashi | 0:8fdf9a60065b | 240 | self._add_labels(prefix, value) |
kadonotakashi | 0:8fdf9a60065b | 241 | self._legacy_ignore_dirs -= set( |
kadonotakashi | 0:8fdf9a60065b | 242 | [toolchain.target.name, LEGACY_TOOLCHAIN_NAMES[toolchain.name]]) |
kadonotakashi | 0:8fdf9a60065b | 243 | |
kadonotakashi | 0:8fdf9a60065b | 244 | def add_ignore_patterns(self, root, base_path, patterns): |
kadonotakashi | 0:8fdf9a60065b | 245 | real_base = relpath(root, base_path) |
kadonotakashi | 0:8fdf9a60065b | 246 | self._ignoreset.add_ignore_patterns(real_base, patterns) |
kadonotakashi | 0:8fdf9a60065b | 247 | |
kadonotakashi | 0:8fdf9a60065b | 248 | def _not_current_label(self, dirname, label_type): |
kadonotakashi | 0:8fdf9a60065b | 249 | return (dirname.startswith(label_type + "_") and |
kadonotakashi | 0:8fdf9a60065b | 250 | dirname[len(label_type) + 1:] not in self._labels[label_type]) |
kadonotakashi | 0:8fdf9a60065b | 251 | |
kadonotakashi | 0:8fdf9a60065b | 252 | def add_file_ref(self, file_type, file_name, file_path): |
kadonotakashi | 0:8fdf9a60065b | 253 | if sep != self._sep: |
kadonotakashi | 0:8fdf9a60065b | 254 | ref = FileRef(file_name.replace(sep, self._sep), file_path) |
kadonotakashi | 0:8fdf9a60065b | 255 | else: |
kadonotakashi | 0:8fdf9a60065b | 256 | ref = FileRef(file_name, file_path) |
kadonotakashi | 0:8fdf9a60065b | 257 | self._file_refs[file_type].add(ref) |
kadonotakashi | 0:8fdf9a60065b | 258 | |
kadonotakashi | 0:8fdf9a60065b | 259 | def get_file_refs(self, file_type): |
kadonotakashi | 0:8fdf9a60065b | 260 | """Return a list of FileRef for every file of the given type""" |
kadonotakashi | 0:8fdf9a60065b | 261 | return list(self._file_refs[file_type]) |
kadonotakashi | 0:8fdf9a60065b | 262 | |
kadonotakashi | 0:8fdf9a60065b | 263 | def _all_parents(self, files): |
kadonotakashi | 0:8fdf9a60065b | 264 | for name in files: |
kadonotakashi | 0:8fdf9a60065b | 265 | components = name.split(self._sep) |
kadonotakashi | 0:8fdf9a60065b | 266 | start_at = 2 if components[0] in set(['', '.']) else 1 |
kadonotakashi | 0:8fdf9a60065b | 267 | for index, directory in reversed(list(enumerate(components))[start_at:]): |
kadonotakashi | 0:8fdf9a60065b | 268 | if directory in self._prefixed_labels: |
kadonotakashi | 0:8fdf9a60065b | 269 | start_at = index + 1 |
kadonotakashi | 0:8fdf9a60065b | 270 | break |
kadonotakashi | 0:8fdf9a60065b | 271 | for n in range(start_at, len(components)): |
kadonotakashi | 0:8fdf9a60065b | 272 | parent = self._sep.join(components[:n]) |
kadonotakashi | 0:8fdf9a60065b | 273 | yield parent |
kadonotakashi | 0:8fdf9a60065b | 274 | |
kadonotakashi | 0:8fdf9a60065b | 275 | def _get_from_refs(self, file_type, key): |
kadonotakashi | 0:8fdf9a60065b | 276 | if file_type is FileType.INC_DIR: |
kadonotakashi | 0:8fdf9a60065b | 277 | parents = set(self._all_parents(self._get_from_refs( |
kadonotakashi | 0:8fdf9a60065b | 278 | FileType.HEADER, key))) |
kadonotakashi | 0:8fdf9a60065b | 279 | parents.add(".") |
kadonotakashi | 0:8fdf9a60065b | 280 | else: |
kadonotakashi | 0:8fdf9a60065b | 281 | parents = set() |
kadonotakashi | 0:8fdf9a60065b | 282 | return sorted( |
kadonotakashi | 0:8fdf9a60065b | 283 | list(parents) + [key(f) for f in self.get_file_refs(file_type)] |
kadonotakashi | 0:8fdf9a60065b | 284 | ) |
kadonotakashi | 0:8fdf9a60065b | 285 | |
kadonotakashi | 0:8fdf9a60065b | 286 | |
kadonotakashi | 0:8fdf9a60065b | 287 | def get_file_names(self, file_type): |
kadonotakashi | 0:8fdf9a60065b | 288 | return self._get_from_refs(file_type, lambda f: f.name) |
kadonotakashi | 0:8fdf9a60065b | 289 | |
kadonotakashi | 0:8fdf9a60065b | 290 | def get_file_paths(self, file_type): |
kadonotakashi | 0:8fdf9a60065b | 291 | return self._get_from_refs(file_type, lambda f: f.path) |
kadonotakashi | 0:8fdf9a60065b | 292 | |
kadonotakashi | 0:8fdf9a60065b | 293 | def add_files_to_type(self, file_type, files): |
kadonotakashi | 0:8fdf9a60065b | 294 | for f in files: |
kadonotakashi | 0:8fdf9a60065b | 295 | self.add_file_ref(file_type, f, f) |
kadonotakashi | 0:8fdf9a60065b | 296 | |
kadonotakashi | 0:8fdf9a60065b | 297 | @property |
kadonotakashi | 0:8fdf9a60065b | 298 | def inc_dirs(self): |
kadonotakashi | 0:8fdf9a60065b | 299 | return self.get_file_names(FileType.INC_DIR) |
kadonotakashi | 0:8fdf9a60065b | 300 | |
kadonotakashi | 0:8fdf9a60065b | 301 | @property |
kadonotakashi | 0:8fdf9a60065b | 302 | def headers(self): |
kadonotakashi | 0:8fdf9a60065b | 303 | return self.get_file_names(FileType.HEADER) |
kadonotakashi | 0:8fdf9a60065b | 304 | |
kadonotakashi | 0:8fdf9a60065b | 305 | @property |
kadonotakashi | 0:8fdf9a60065b | 306 | def s_sources(self): |
kadonotakashi | 0:8fdf9a60065b | 307 | return self.get_file_names(FileType.ASM_SRC) |
kadonotakashi | 0:8fdf9a60065b | 308 | |
kadonotakashi | 0:8fdf9a60065b | 309 | @property |
kadonotakashi | 0:8fdf9a60065b | 310 | def c_sources(self): |
kadonotakashi | 0:8fdf9a60065b | 311 | return self.get_file_names(FileType.C_SRC) |
kadonotakashi | 0:8fdf9a60065b | 312 | |
kadonotakashi | 0:8fdf9a60065b | 313 | @property |
kadonotakashi | 0:8fdf9a60065b | 314 | def cpp_sources(self): |
kadonotakashi | 0:8fdf9a60065b | 315 | return self.get_file_names(FileType.CPP_SRC) |
kadonotakashi | 0:8fdf9a60065b | 316 | |
kadonotakashi | 0:8fdf9a60065b | 317 | @property |
kadonotakashi | 0:8fdf9a60065b | 318 | def lib_dirs(self): |
kadonotakashi | 0:8fdf9a60065b | 319 | return self.get_file_names(FileType.LIB_DIR) |
kadonotakashi | 0:8fdf9a60065b | 320 | |
kadonotakashi | 0:8fdf9a60065b | 321 | @property |
kadonotakashi | 0:8fdf9a60065b | 322 | def objects(self): |
kadonotakashi | 0:8fdf9a60065b | 323 | return self.get_file_names(FileType.OBJECT) |
kadonotakashi | 0:8fdf9a60065b | 324 | |
kadonotakashi | 0:8fdf9a60065b | 325 | @property |
kadonotakashi | 0:8fdf9a60065b | 326 | def libraries(self): |
kadonotakashi | 0:8fdf9a60065b | 327 | return self.get_file_names(FileType.LIB) |
kadonotakashi | 0:8fdf9a60065b | 328 | |
kadonotakashi | 0:8fdf9a60065b | 329 | @property |
kadonotakashi | 0:8fdf9a60065b | 330 | def lib_builds(self): |
kadonotakashi | 0:8fdf9a60065b | 331 | return self.get_file_names(FileType.BLD_REF) |
kadonotakashi | 0:8fdf9a60065b | 332 | |
kadonotakashi | 0:8fdf9a60065b | 333 | @property |
kadonotakashi | 0:8fdf9a60065b | 334 | def lib_refs(self): |
kadonotakashi | 0:8fdf9a60065b | 335 | return self.get_file_names(FileType.LIB_REF) |
kadonotakashi | 0:8fdf9a60065b | 336 | |
kadonotakashi | 0:8fdf9a60065b | 337 | @property |
kadonotakashi | 0:8fdf9a60065b | 338 | def linker_script(self): |
kadonotakashi | 0:8fdf9a60065b | 339 | options = self.get_file_names(FileType.LD_SCRIPT) |
kadonotakashi | 0:8fdf9a60065b | 340 | if options: |
kadonotakashi | 0:8fdf9a60065b | 341 | return options[0] |
kadonotakashi | 0:8fdf9a60065b | 342 | else: |
kadonotakashi | 0:8fdf9a60065b | 343 | return None |
kadonotakashi | 0:8fdf9a60065b | 344 | |
kadonotakashi | 0:8fdf9a60065b | 345 | @property |
kadonotakashi | 0:8fdf9a60065b | 346 | def hex_files(self): |
kadonotakashi | 0:8fdf9a60065b | 347 | return self.get_file_names(FileType.HEX) |
kadonotakashi | 0:8fdf9a60065b | 348 | |
kadonotakashi | 0:8fdf9a60065b | 349 | @property |
kadonotakashi | 0:8fdf9a60065b | 350 | def bin_files(self): |
kadonotakashi | 0:8fdf9a60065b | 351 | return self.get_file_names(FileType.BIN) |
kadonotakashi | 0:8fdf9a60065b | 352 | |
kadonotakashi | 0:8fdf9a60065b | 353 | @property |
kadonotakashi | 0:8fdf9a60065b | 354 | def json_files(self): |
kadonotakashi | 0:8fdf9a60065b | 355 | return self.get_file_names(FileType.JSON) |
kadonotakashi | 0:8fdf9a60065b | 356 | |
kadonotakashi | 0:8fdf9a60065b | 357 | def add_directory( |
kadonotakashi | 0:8fdf9a60065b | 358 | self, |
kadonotakashi | 0:8fdf9a60065b | 359 | path, |
kadonotakashi | 0:8fdf9a60065b | 360 | base_path=None, |
kadonotakashi | 0:8fdf9a60065b | 361 | into_path=None, |
kadonotakashi | 0:8fdf9a60065b | 362 | exclude_paths=None, |
kadonotakashi | 0:8fdf9a60065b | 363 | ): |
kadonotakashi | 0:8fdf9a60065b | 364 | """ Scan a directory and include its resources in this resources obejct |
kadonotakashi | 0:8fdf9a60065b | 365 | |
kadonotakashi | 0:8fdf9a60065b | 366 | Positional arguments: |
kadonotakashi | 0:8fdf9a60065b | 367 | path - the path to search for resources |
kadonotakashi | 0:8fdf9a60065b | 368 | |
kadonotakashi | 0:8fdf9a60065b | 369 | Keyword arguments |
kadonotakashi | 0:8fdf9a60065b | 370 | base_path - If this is part of an incremental scan, include the origin |
kadonotakashi | 0:8fdf9a60065b | 371 | directory root of the scan here |
kadonotakashi | 0:8fdf9a60065b | 372 | into_path - Pretend that scanned files are within the specified |
kadonotakashi | 0:8fdf9a60065b | 373 | directory within a project instead of using their actual path |
kadonotakashi | 0:8fdf9a60065b | 374 | exclude_paths - A list of paths that are to be excluded from a build |
kadonotakashi | 0:8fdf9a60065b | 375 | """ |
kadonotakashi | 0:8fdf9a60065b | 376 | self._notify.progress("scan", abspath(path)) |
kadonotakashi | 0:8fdf9a60065b | 377 | |
kadonotakashi | 0:8fdf9a60065b | 378 | if base_path is None: |
kadonotakashi | 0:8fdf9a60065b | 379 | base_path = path |
kadonotakashi | 0:8fdf9a60065b | 380 | if into_path is None: |
kadonotakashi | 0:8fdf9a60065b | 381 | into_path = path |
kadonotakashi | 0:8fdf9a60065b | 382 | if self._collect_ignores and path in self.ignored_dirs: |
kadonotakashi | 0:8fdf9a60065b | 383 | self.ignored_dirs.remove(path) |
kadonotakashi | 0:8fdf9a60065b | 384 | if exclude_paths: |
kadonotakashi | 0:8fdf9a60065b | 385 | self.add_ignore_patterns( |
kadonotakashi | 0:8fdf9a60065b | 386 | path, base_path, [join(e, "*") for e in exclude_paths]) |
kadonotakashi | 0:8fdf9a60065b | 387 | |
kadonotakashi | 0:8fdf9a60065b | 388 | for root, dirs, files in walk(path, followlinks=True): |
kadonotakashi | 0:8fdf9a60065b | 389 | # Check if folder contains .mbedignore |
kadonotakashi | 0:8fdf9a60065b | 390 | if IGNORE_FILENAME in files: |
kadonotakashi | 0:8fdf9a60065b | 391 | real_base = relpath(root, base_path) |
kadonotakashi | 0:8fdf9a60065b | 392 | self._ignoreset.add_mbedignore( |
kadonotakashi | 0:8fdf9a60065b | 393 | real_base, join(root, IGNORE_FILENAME)) |
kadonotakashi | 0:8fdf9a60065b | 394 | |
kadonotakashi | 0:8fdf9a60065b | 395 | root_path =join(relpath(root, base_path)) |
kadonotakashi | 0:8fdf9a60065b | 396 | if self._ignoreset.is_ignored(join(root_path,"")): |
kadonotakashi | 0:8fdf9a60065b | 397 | self.ignore_dir(root_path) |
kadonotakashi | 0:8fdf9a60065b | 398 | dirs[:] = [] |
kadonotakashi | 0:8fdf9a60065b | 399 | continue |
kadonotakashi | 0:8fdf9a60065b | 400 | |
kadonotakashi | 0:8fdf9a60065b | 401 | for d in copy(dirs): |
kadonotakashi | 0:8fdf9a60065b | 402 | dir_path = join(root, d) |
kadonotakashi | 0:8fdf9a60065b | 403 | if d == '.hg' or d == '.git': |
kadonotakashi | 0:8fdf9a60065b | 404 | fake_path = join(into_path, relpath(dir_path, base_path)) |
kadonotakashi | 0:8fdf9a60065b | 405 | self.add_file_ref(FileType.REPO_DIR, fake_path, dir_path) |
kadonotakashi | 0:8fdf9a60065b | 406 | |
kadonotakashi | 0:8fdf9a60065b | 407 | if (any(self._not_current_label(d, t) for t |
kadonotakashi | 0:8fdf9a60065b | 408 | in self._labels.keys())): |
kadonotakashi | 0:8fdf9a60065b | 409 | self._label_paths.append((dir_path, base_path, into_path)) |
kadonotakashi | 0:8fdf9a60065b | 410 | self.ignore_dir(dir_path) |
kadonotakashi | 0:8fdf9a60065b | 411 | dirs.remove(d) |
kadonotakashi | 0:8fdf9a60065b | 412 | elif (d.startswith('.') or d in self._legacy_ignore_dirs or |
kadonotakashi | 0:8fdf9a60065b | 413 | self._ignoreset.is_ignored(join(root_path, d, ""))): |
kadonotakashi | 0:8fdf9a60065b | 414 | self.ignore_dir(dir_path) |
kadonotakashi | 0:8fdf9a60065b | 415 | dirs.remove(d) |
kadonotakashi | 0:8fdf9a60065b | 416 | |
kadonotakashi | 0:8fdf9a60065b | 417 | # Add root to include paths |
kadonotakashi | 0:8fdf9a60065b | 418 | root = root.rstrip("/") |
kadonotakashi | 0:8fdf9a60065b | 419 | |
kadonotakashi | 0:8fdf9a60065b | 420 | for file in files: |
kadonotakashi | 0:8fdf9a60065b | 421 | file_path = join(root, file) |
kadonotakashi | 0:8fdf9a60065b | 422 | self._add_file(file_path, base_path, into_path) |
kadonotakashi | 0:8fdf9a60065b | 423 | |
kadonotakashi | 0:8fdf9a60065b | 424 | _EXT = { |
kadonotakashi | 0:8fdf9a60065b | 425 | ".c": FileType.C_SRC, |
kadonotakashi | 0:8fdf9a60065b | 426 | ".cc": FileType.CPP_SRC, |
kadonotakashi | 0:8fdf9a60065b | 427 | ".cpp": FileType.CPP_SRC, |
kadonotakashi | 0:8fdf9a60065b | 428 | ".s": FileType.ASM_SRC, |
kadonotakashi | 0:8fdf9a60065b | 429 | ".h": FileType.HEADER, |
kadonotakashi | 0:8fdf9a60065b | 430 | ".hh": FileType.HEADER, |
kadonotakashi | 0:8fdf9a60065b | 431 | ".hpp": FileType.HEADER, |
kadonotakashi | 0:8fdf9a60065b | 432 | ".o": FileType.OBJECT, |
kadonotakashi | 0:8fdf9a60065b | 433 | ".hex": FileType.HEX, |
kadonotakashi | 0:8fdf9a60065b | 434 | ".bin": FileType.BIN, |
kadonotakashi | 0:8fdf9a60065b | 435 | ".json": FileType.JSON, |
kadonotakashi | 0:8fdf9a60065b | 436 | ".a": FileType.LIB, |
kadonotakashi | 0:8fdf9a60065b | 437 | ".ar": FileType.LIB, |
kadonotakashi | 0:8fdf9a60065b | 438 | ".sct": FileType.LD_SCRIPT, |
kadonotakashi | 0:8fdf9a60065b | 439 | ".ld": FileType.LD_SCRIPT, |
kadonotakashi | 0:8fdf9a60065b | 440 | ".icf": FileType.LD_SCRIPT, |
kadonotakashi | 0:8fdf9a60065b | 441 | ".lib": FileType.LIB_REF, |
kadonotakashi | 0:8fdf9a60065b | 442 | ".bld": FileType.BLD_REF, |
kadonotakashi | 0:8fdf9a60065b | 443 | } |
kadonotakashi | 0:8fdf9a60065b | 444 | |
kadonotakashi | 0:8fdf9a60065b | 445 | _DIR_EXT = { |
kadonotakashi | 0:8fdf9a60065b | 446 | ".a": FileType.LIB_DIR, |
kadonotakashi | 0:8fdf9a60065b | 447 | ".ar": FileType.LIB_DIR, |
kadonotakashi | 0:8fdf9a60065b | 448 | } |
kadonotakashi | 0:8fdf9a60065b | 449 | |
kadonotakashi | 0:8fdf9a60065b | 450 | def _add_file(self, file_path, base_path, into_path): |
kadonotakashi | 0:8fdf9a60065b | 451 | """ Add a single file into the resources object that was found by |
kadonotakashi | 0:8fdf9a60065b | 452 | scanning starting as base_path |
kadonotakashi | 0:8fdf9a60065b | 453 | """ |
kadonotakashi | 0:8fdf9a60065b | 454 | |
kadonotakashi | 0:8fdf9a60065b | 455 | if (self._ignoreset.is_ignored(relpath(file_path, base_path)) or |
kadonotakashi | 0:8fdf9a60065b | 456 | basename(file_path).startswith(".")): |
kadonotakashi | 0:8fdf9a60065b | 457 | self.ignore_dir(relpath(file_path, base_path)) |
kadonotakashi | 0:8fdf9a60065b | 458 | return |
kadonotakashi | 0:8fdf9a60065b | 459 | |
kadonotakashi | 0:8fdf9a60065b | 460 | fake_path = join(into_path, relpath(file_path, base_path)) |
kadonotakashi | 0:8fdf9a60065b | 461 | _, ext = splitext(file_path) |
kadonotakashi | 0:8fdf9a60065b | 462 | try: |
kadonotakashi | 0:8fdf9a60065b | 463 | file_type = self._EXT[ext.lower()] |
kadonotakashi | 0:8fdf9a60065b | 464 | self.add_file_ref(file_type, fake_path, file_path) |
kadonotakashi | 0:8fdf9a60065b | 465 | except KeyError: |
kadonotakashi | 0:8fdf9a60065b | 466 | pass |
kadonotakashi | 0:8fdf9a60065b | 467 | try: |
kadonotakashi | 0:8fdf9a60065b | 468 | dir_type = self._DIR_EXT[ext.lower()] |
kadonotakashi | 0:8fdf9a60065b | 469 | self.add_file_ref(dir_type, dirname(fake_path), dirname(file_path)) |
kadonotakashi | 0:8fdf9a60065b | 470 | except KeyError: |
kadonotakashi | 0:8fdf9a60065b | 471 | pass |
kadonotakashi | 0:8fdf9a60065b | 472 | |
kadonotakashi | 0:8fdf9a60065b | 473 | |
kadonotakashi | 0:8fdf9a60065b | 474 | def scan_with_toolchain(self, src_paths, toolchain, dependencies_paths=None, |
kadonotakashi | 0:8fdf9a60065b | 475 | inc_dirs=None, exclude=True): |
kadonotakashi | 0:8fdf9a60065b | 476 | """ Scan resources using initialized toolcain |
kadonotakashi | 0:8fdf9a60065b | 477 | |
kadonotakashi | 0:8fdf9a60065b | 478 | Positional arguments |
kadonotakashi | 0:8fdf9a60065b | 479 | src_paths - the paths to source directories |
kadonotakashi | 0:8fdf9a60065b | 480 | toolchain - valid toolchain object |
kadonotakashi | 0:8fdf9a60065b | 481 | |
kadonotakashi | 0:8fdf9a60065b | 482 | Keyword arguments |
kadonotakashi | 0:8fdf9a60065b | 483 | dependencies_paths - dependency paths that we should scan for include dirs |
kadonotakashi | 0:8fdf9a60065b | 484 | inc_dirs - additional include directories which should be added to |
kadonotakashi | 0:8fdf9a60065b | 485 | the scanner resources |
kadonotakashi | 0:8fdf9a60065b | 486 | exclude - Exclude the toolchain's build directory from the resources |
kadonotakashi | 0:8fdf9a60065b | 487 | """ |
kadonotakashi | 0:8fdf9a60065b | 488 | self.add_toolchain_labels(toolchain) |
kadonotakashi | 0:8fdf9a60065b | 489 | for path in src_paths: |
kadonotakashi | 0:8fdf9a60065b | 490 | if exists(path): |
kadonotakashi | 0:8fdf9a60065b | 491 | into_path = relpath(path).strip(".\\/") |
kadonotakashi | 0:8fdf9a60065b | 492 | if exclude: |
kadonotakashi | 0:8fdf9a60065b | 493 | self.add_directory( |
kadonotakashi | 0:8fdf9a60065b | 494 | path, |
kadonotakashi | 0:8fdf9a60065b | 495 | into_path=into_path, |
kadonotakashi | 0:8fdf9a60065b | 496 | exclude_paths=[toolchain.build_dir] |
kadonotakashi | 0:8fdf9a60065b | 497 | ) |
kadonotakashi | 0:8fdf9a60065b | 498 | else: |
kadonotakashi | 0:8fdf9a60065b | 499 | self.add_directory(path, into_path=into_path) |
kadonotakashi | 0:8fdf9a60065b | 500 | |
kadonotakashi | 0:8fdf9a60065b | 501 | # Scan dependency paths for include dirs |
kadonotakashi | 0:8fdf9a60065b | 502 | if dependencies_paths is not None: |
kadonotakashi | 0:8fdf9a60065b | 503 | toolchain.progress("dep", dependencies_paths) |
kadonotakashi | 0:8fdf9a60065b | 504 | for dep in dependencies_paths: |
kadonotakashi | 0:8fdf9a60065b | 505 | lib_self = self.__class__(self._notify, self._collect_ignores)\ |
kadonotakashi | 0:8fdf9a60065b | 506 | .scan_with_toolchain([dep], toolchain) |
kadonotakashi | 0:8fdf9a60065b | 507 | self.inc_dirs.extend(lib_self.inc_dirs) |
kadonotakashi | 0:8fdf9a60065b | 508 | |
kadonotakashi | 0:8fdf9a60065b | 509 | # Add additional include directories if passed |
kadonotakashi | 0:8fdf9a60065b | 510 | if inc_dirs: |
kadonotakashi | 0:8fdf9a60065b | 511 | if isinstance(inc_dirs, list): |
kadonotakashi | 0:8fdf9a60065b | 512 | self.inc_dirs.extend(inc_dirs) |
kadonotakashi | 0:8fdf9a60065b | 513 | else: |
kadonotakashi | 0:8fdf9a60065b | 514 | self.inc_dirs.append(inc_dirs) |
kadonotakashi | 0:8fdf9a60065b | 515 | |
kadonotakashi | 0:8fdf9a60065b | 516 | # Load self into the config system which might expand/modify self |
kadonotakashi | 0:8fdf9a60065b | 517 | # based on config data |
kadonotakashi | 0:8fdf9a60065b | 518 | toolchain.config.load_resources(self) |
kadonotakashi | 0:8fdf9a60065b | 519 | |
kadonotakashi | 0:8fdf9a60065b | 520 | # Set the toolchain's configuration data |
kadonotakashi | 0:8fdf9a60065b | 521 | toolchain.set_config_data(toolchain.config.get_config_data()) |
kadonotakashi | 0:8fdf9a60065b | 522 | |
kadonotakashi | 0:8fdf9a60065b | 523 | return self |
kadonotakashi | 0:8fdf9a60065b | 524 | |
kadonotakashi | 0:8fdf9a60065b | 525 | def scan_with_config(self, src_paths, config): |
kadonotakashi | 0:8fdf9a60065b | 526 | if config.target: |
kadonotakashi | 0:8fdf9a60065b | 527 | self.add_target_labels(config.target) |
kadonotakashi | 0:8fdf9a60065b | 528 | for path in src_paths: |
kadonotakashi | 0:8fdf9a60065b | 529 | if exists(path): |
kadonotakashi | 0:8fdf9a60065b | 530 | self.add_directory(path) |
kadonotakashi | 0:8fdf9a60065b | 531 | config.load_resources(self) |
kadonotakashi | 0:8fdf9a60065b | 532 | return self |
kadonotakashi | 0:8fdf9a60065b | 533 |