Rework export resource scanning

pull/7183/head
Jimmy Brisson 2018-04-24 14:05:46 -05:00
parent 2d8cf737e4
commit 519e338667
3 changed files with 46 additions and 45 deletions

View File

@ -42,7 +42,7 @@ from .paths import (MBED_CMSIS_PATH, MBED_TARGETS_PATH, MBED_LIBRARIES,
MBED_CONFIG_FILE, MBED_LIBRARIES_DRIVERS,
MBED_LIBRARIES_PLATFORM, MBED_LIBRARIES_HAL,
BUILD_DIR)
from .resources import scan_resources
from .resources import Resources
from .targets import TARGET_NAMES, TARGET_MAP
from .libraries import Library
from .toolchains import TOOLCHAIN_CLASSES
@ -517,8 +517,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
try:
# Call unified scan_resources
resources = scan_resources(src_paths, toolchain, inc_dirs=inc_dirs)
print(resources)
resources = Resources().scan_with_toolchain(src_paths, toolchain, inc_dirs)
# Change linker script if specified
if linker_script is not None:

View File

@ -25,8 +25,8 @@ import copy
from shutil import rmtree, copyfile
import zipfile
from ..build_api import prepare_toolchain, scan_resources
from ..toolchains import Resources
from ..resources import Resources
from ..build_api import prepare_toolchain
from ..targets import TARGET_NAMES
from . import (lpcxpresso, ds5_5, iar, makefile, embitz, coide, kds, simplicity,
atmelstudio, mcuxpresso, sw4stm32, e2studio, zip, cmsis, uvision,
@ -275,10 +275,13 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
if name is None:
name = basename(normpath(abspath(src_paths[0])))
resource_dict = {loc: sum((toolchain.scan_resources(p, collect_ignores=True)
for p in path),
Resources())
for loc, path in src_paths.items()}
resource_dict = {}
for loc, path in src_paths.items():
res = Resources(collect_ignores=True)
res.add_toolchain_labels(toolchain)
for p in path:
res.add_directory(p, None)
resource_dict[loc] = res
resources = Resources()
for loc, res in resource_dict.items():

View File

@ -129,7 +129,7 @@ class LazyDict(object):
self.lazy = new_lazy
self.eager = {}
class Resources:
class Resources(object):
def __init__(self, base_path=None, collect_ignores=False):
self.base_path = base_path
self.collect_ignores = collect_ignores
@ -414,7 +414,6 @@ class Resources:
"""
if base_path is None:
base_path = path
print("%s %s %s" % (path, base_path, exclude_paths))
for root, dirs, files in walk(path, followlinks=True):
# Check if folder contains .mbedignore
if ".mbedignore" in files:
@ -448,7 +447,6 @@ class Resources:
self.is_ignored(join(relpath(root, base_path), d,"")) or
# Ignore TESTS dir
(d == 'TESTS')):
print("ignoreing %s" % dir_path)
self.ignore_dir(dir_path)
dirs.remove(d)
elif d.startswith('FEATURE_'):
@ -456,7 +454,6 @@ class Resources:
# These are dynamically added by the config system if the conditions are matched
def closure (dir_path=dir_path, base_path=base_path):
return self.add_directory(dir_path, base_path=base_path)
print("lazying %s" % dir_path)
self.features.add_lazy(d[8:], closure)
self.ignore_dir(dir_path)
dirs.remove(d)
@ -464,7 +461,6 @@ class Resources:
for exclude_path in exclude_paths:
rel_path = relpath(dir_path, exclude_path)
if not (rel_path.startswith('..')):
print("excluding %s" % dir_path)
self.ignore_dir(dir_path)
dirs.remove(d)
break
@ -537,41 +533,44 @@ class Resources:
self.json_files.append(file_path)
def scan_resources(src_paths, toolchain, dependencies_paths=None,
inc_dirs=None, base_path=None, collect_ignores=False):
""" Scan resources using initialized toolcain
def scan_with_toolchain(self, src_paths, toolchain, dependencies_paths=None,
inc_dirs=None, base_path=None, exclude=True):
""" Scan resources using initialized toolcain
Positional arguments
src_paths - the paths to source directories
toolchain - valid toolchain object
dependencies_paths - dependency paths that we should scan for include dirs
inc_dirs - additional include directories which should be added to
the scanner resources
"""
Positional arguments
src_paths - the paths to source directories
toolchain - valid toolchain object
dependencies_paths - dependency paths that we should scan for include dirs
inc_dirs - additional include directories which should be added to
the scanner resources
"""
resources = Resources(base_path, collect_ignores)
resources.add_toolchain_labels(toolchain)
for path in src_paths:
resources.add_directory(path, base_path, exclude_paths=[toolchain.build_dir])
self.add_toolchain_labels(toolchain)
for path in src_paths:
if exclude:
self.add_directory(path, base_path, exclude_paths=[toolchain.build_dir])
else:
self.add_directory(path, base_path)
# Scan dependency paths for include dirs
if dependencies_paths is not None:
for path in dependencies_paths:
lib_resources = toolchain.scan_resources(path)
resources.inc_dirs.extend(lib_resources.inc_dirs)
# Scan dependency paths for include dirs
if dependencies_paths is not None:
for path in dependencies_paths:
lib_self = self.__class__(self.base_path, self.collect_ignores)\
.scan_with_toolchain([path], toolchain)
self.inc_dirs.extend(lib_self.inc_dirs)
# Add additional include directories if passed
if inc_dirs:
if isinstance(inc_dirs, list):
resources.inc_dirs.extend(inc_dirs)
else:
resources.inc_dirs.append(inc_dirs)
# Add additional include directories if passed
if inc_dirs:
if isinstance(inc_dirs, list):
self.inc_dirs.extend(inc_dirs)
else:
self.inc_dirs.append(inc_dirs)
# Load resources into the config system which might expand/modify resources
# based on config data
toolchain.config.load_resources(resources)
# Load self into the config system which might expand/modify self
# based on config data
toolchain.config.load_resources(self)
# Set the toolchain's configuration data
toolchain.set_config_data(toolchain.config.get_config_data())
# Set the toolchain's configuration data
toolchain.set_config_data(toolchain.config.get_config_data())
return resources
return self