mirror of https://github.com/ARMmbed/mbed-os.git
Implement the .mbedignore functionality.
Check the content of `.mbedignore` files and try to match the file patterns against the directories and source files found while travelling the directory structure. Every line in `.mbedignore` file is treated as a unix style glob pattern. Before matching, the pattern is appended with its directory location, so it will match only folder on same level, or deeper in the directory structure. For example: Directory ./source/test contains .mbedignore with content: `unittest/*` Then everything under ./source/test/unittest/ is ignored, including the unittest folder itself. Another example: When .mbedignore file contains just `*`, then everything under the folder it is located, is ignored. It won't even be added to include paths.
parent
3c08e7b7b3
commit
3d3b0a771f
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
|
||||
import re
|
||||
import sys
|
||||
from os import stat, walk, getcwd
|
||||
from os import stat, walk, getcwd, sep
|
||||
from copy import copy
|
||||
from time import time, sleep
|
||||
from types import ListType
|
||||
|
@ -30,6 +30,7 @@ from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedExc
|
|||
from tools.settings import BUILD_OPTIONS, MBED_ORG_USER
|
||||
import tools.hooks as hooks
|
||||
from hashlib import md5
|
||||
import fnmatch
|
||||
|
||||
|
||||
#Disables multiprocessing if set to higher number than the host machine CPUs
|
||||
|
@ -165,6 +166,7 @@ LEGACY_TOOLCHAIN_NAMES = {
|
|||
|
||||
class mbedToolchain:
|
||||
VERBOSE = True
|
||||
ignorepatterns = []
|
||||
|
||||
CORTEX_SYMBOLS = {
|
||||
"Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
|
||||
|
@ -343,6 +345,12 @@ class mbedToolchain:
|
|||
|
||||
return False
|
||||
|
||||
def is_ignored(self, file_path):
|
||||
for pattern in self.ignorepatterns:
|
||||
if fnmatch.fnmatch(file_path, pattern):
|
||||
return True
|
||||
return False
|
||||
|
||||
def scan_resources(self, path, exclude_paths=None):
|
||||
labels = self.get_labels()
|
||||
resources = Resources(path)
|
||||
|
@ -370,10 +378,28 @@ class mbedToolchain:
|
|||
if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
|
||||
(d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
|
||||
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
|
||||
(d == 'TESTS') or
|
||||
exists(join(dir_path, '.buildignore'))):
|
||||
(d == 'TESTS')):
|
||||
dirs.remove(d)
|
||||
|
||||
|
||||
# Check if folder contains .mbedignore
|
||||
try:
|
||||
with open (join(dir_path,".mbedignore"), "r") as f:
|
||||
lines=f.readlines()
|
||||
lines = [l.strip() for l in lines] # Strip whitespaces
|
||||
lines = [l for l in lines if l != ""] # Strip empty lines
|
||||
lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines
|
||||
# Append root path to glob patterns
|
||||
# and append patterns to ignorepatterns
|
||||
self.ignorepatterns.extend([join(dir_path,line.strip()) for line in lines])
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
# Remove dirs that already match the ignorepatterns
|
||||
# to avoid travelling into them and to prevent them
|
||||
# on appearing in include path.
|
||||
if self.is_ignored(join(dir_path,"")):
|
||||
dirs.remove(d)
|
||||
|
||||
if exclude_paths:
|
||||
for exclude_path in exclude_paths:
|
||||
rel_path = relpath(dir_path, exclude_path)
|
||||
|
@ -386,6 +412,10 @@ class mbedToolchain:
|
|||
|
||||
for file in files:
|
||||
file_path = join(root, file)
|
||||
|
||||
if self.is_ignored(file_path):
|
||||
continue
|
||||
|
||||
_, ext = splitext(file)
|
||||
ext = ext.lower()
|
||||
|
||||
|
|
Loading…
Reference in New Issue