From c5a721c1046c9938fc4c1dee1016181e1f4011ba Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Wed, 16 Jan 2019 11:04:39 -0600 Subject: [PATCH] Test that libraries' source is excluded --- tools/build_api.py | 2 +- tools/test/config/config_test.py | 31 +++++++++++++++++-- .../config/requires_from_lib/lib3/lib3.cpp | 0 .../config/requires_from_lib/test_data.json | 3 +- .../config/requires_omit_lib/lib1/lib1.cpp | 0 .../{bl => }/lib1/mbed_lib.json | 0 .../test/config/requires_omit_lib/lib2/lib2.c | 0 .../{storage => }/lib2/mbed_lib.json | 0 .../config/requires_omit_lib/test_data.json | 4 ++- 9 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tools/test/config/requires_from_lib/lib3/lib3.cpp create mode 100644 tools/test/config/requires_omit_lib/lib1/lib1.cpp rename tools/test/config/requires_omit_lib/{bl => }/lib1/mbed_lib.json (100%) create mode 100644 tools/test/config/requires_omit_lib/lib2/lib2.c rename tools/test/config/requires_omit_lib/{storage => }/lib2/mbed_lib.json (100%) diff --git a/tools/build_api.py b/tools/build_api.py index 0faf8eadb8..b8ccba0ff8 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -147,7 +147,7 @@ def get_config(src_paths, target, toolchain_name=None, app_config=None): cfg, macros = config.get_config_data() features = config.get_features() - return cfg, macros, features + return cfg, macros, features, res def is_official_target(target_name, version): """ Returns True, None if a target is part of the official release for the diff --git a/tools/test/config/config_test.py b/tools/test/config/config_test.py index 9acc8723d1..5df96c8c93 100644 --- a/tools/test/config/config_test.py +++ b/tools/test/config/config_test.py @@ -26,6 +26,14 @@ from os.path import join, isfile, dirname, abspath from tools.build_api import get_config from tools.targets import set_targets_json_location, Target, TARGET_NAMES from tools.config import ConfigException, Config, ConfigParameter, ConfigMacro +from tools.resources import Resources + +NOT_CONFIG = [ + "expected_macros", + "expected_features", + "included_source", + "excluded_source", +] def compare_config(cfg, expected): """Compare the output of config against a dictionary of known good results @@ -40,7 +48,7 @@ def compare_config(cfg, expected): except KeyError: return "Unexpected key '%s' in configuration data" % k for k in expected: - if k not in ["expected_macros", "expected_features"] + list(cfg.keys()): + if k not in NOT_CONFIG + list(cfg.keys()): return "Expected key '%s' was not found in configuration data" % k return "" @@ -73,7 +81,7 @@ def test_config(name): set_targets_json_location(targets_json if isfile(targets_json) else None) for target, expected in test_data.items(): try: - cfg, macros, features = get_config(test_dir, target, "GCC_ARM") + cfg, macros, features, resources = get_config(test_dir, target, "GCC_ARM") res = compare_config(cfg, expected) assert not(res), res expected_macros = expected.get("expected_macros", None) @@ -84,6 +92,25 @@ def test_config(name): assert sorted(expected_macros) == sorted(macros) if expected_features is not None: assert sorted(expected_features) == sorted(features) + + included_source = [ + join(test_dir, src) for src in + expected.get("included_source", []) + ] + excluded_source = [ + join(test_dir, src) for src in + expected.get("excluded_source", []) + ] + for typ in Resources.ALL_FILE_TYPES: + for _, path in resources.get_file_refs(typ): + print(path) + if included_source and path in included_source: + included_source.remove(path) + if excluded_source: + assert(path not in excluded_source) + assert(not included_source) + if included_source: + assert(False) except ConfigException as e: err_msg = str(e) if "exception_msg" not in expected: diff --git a/tools/test/config/requires_from_lib/lib3/lib3.cpp b/tools/test/config/requires_from_lib/lib3/lib3.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/test/config/requires_from_lib/test_data.json b/tools/test/config/requires_from_lib/test_data.json index 58a5b197af..ac5f14628c 100644 --- a/tools/test/config/requires_from_lib/test_data.json +++ b/tools/test/config/requires_from_lib/test_data.json @@ -2,6 +2,7 @@ "test_target": { "lib3.test": "GOOD", "lib2.test": "GOOD", - "lib1.test": "GOOD" + "lib1.test": "GOOD", + "included_source": ["lib3/lib3.cpp"] } } diff --git a/tools/test/config/requires_omit_lib/lib1/lib1.cpp b/tools/test/config/requires_omit_lib/lib1/lib1.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/test/config/requires_omit_lib/bl/lib1/mbed_lib.json b/tools/test/config/requires_omit_lib/lib1/mbed_lib.json similarity index 100% rename from tools/test/config/requires_omit_lib/bl/lib1/mbed_lib.json rename to tools/test/config/requires_omit_lib/lib1/mbed_lib.json diff --git a/tools/test/config/requires_omit_lib/lib2/lib2.c b/tools/test/config/requires_omit_lib/lib2/lib2.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/test/config/requires_omit_lib/storage/lib2/mbed_lib.json b/tools/test/config/requires_omit_lib/lib2/mbed_lib.json similarity index 100% rename from tools/test/config/requires_omit_lib/storage/lib2/mbed_lib.json rename to tools/test/config/requires_omit_lib/lib2/mbed_lib.json diff --git a/tools/test/config/requires_omit_lib/test_data.json b/tools/test/config/requires_omit_lib/test_data.json index cbbf0e5f25..8f737d8e58 100644 --- a/tools/test/config/requires_omit_lib/test_data.json +++ b/tools/test/config/requires_omit_lib/test_data.json @@ -3,6 +3,8 @@ "exception_msg": "Attempt to override undefined parameter 'lib2.test' in 'application[should_fail]'" }, "should_pass": { - "lib1.test": "GOOD" + "lib1.test": "GOOD", + "excluded_source": ["lib2/lib2.c"], + "included_source": ["lib1/lib1.cpp"] } }