| 
33 | 33 | 
 
  | 
34 | 34 | # Calculate path to Mbed OS JSON files  | 
35 | 35 | THIS_SCRIPT_DIR = pathlib.Path(os.path.dirname(__file__))  | 
 | 36 | +PROJECT_ROOT = THIS_SCRIPT_DIR.parent.parent.parent.parent.parent  | 
36 | 37 | MBED_OS_DIR = THIS_SCRIPT_DIR.parent.parent.parent.parent  | 
37 | 38 | TARGETS_JSON5_PATH = MBED_OS_DIR / "targets" / "targets.json5"  | 
38 | 39 | CMSIS_MCU_DESCRIPTIONS_JSON_PATH = MBED_OS_DIR / "targets" / "cmsis_mcu_descriptions.json5"  | 
39 | 40 | 
 
  | 
40 |  | -PROJECT_ROOT = THIS_SCRIPT_DIR.parent.parent.parent.parent.parent  | 
41 |  | -CUSTOM_TARGETS_JSON_PATH = None  | 
42 |  | - | 
43 | 41 | # Top-level command  | 
44 | 42 | @click.group(  | 
45 | 43 |     name="cmsis-mcu-descr",  | 
@@ -70,6 +68,7 @@ def open_cmsis_cache(*, must_exist: bool = True) -> cmsis_pack_manager.Cache:  | 
70 | 68 | 
 
  | 
71 | 69 |     return cmsis_cache  | 
72 | 70 | 
 
  | 
 | 71 | + | 
73 | 72 | def find_json_files(root_dir, exclude_dirs=[], file_pattern=r".*\.(json|json5)"):  | 
74 | 73 |     """  | 
75 | 74 |     Recursively searches for files matching the specified pattern in a given directory, excluding specified directories.  | 
@@ -107,19 +106,19 @@ def get_mcu_names_used_by_targets_json5() -> Set[str]:  | 
107 | 106 |     file_pattern = r"custom_targets\.(json|json5)"    | 
108 | 107 |     custom_targets_file = find_json_files(PROJECT_ROOT, exclude_dirs, file_pattern)  | 
109 | 108 | 
 
  | 
 | 109 | +    custom_targets_json_path = {}  | 
110 | 110 |     for file in custom_targets_file:  | 
111 | 111 |         if os.path.exists(file):  | 
112 |  | -            global CUSTOM_TARGETS_JSON_PATH   | 
113 |  | -            CUSTOM_TARGETS_JSON_PATH = file  | 
114 |  | -            print(f"File exist {CUSTOM_TARGETS_JSON_PATH}")  | 
 | 112 | +            custom_targets_json_path = file  | 
 | 113 | +            LOGGER.info(f"Custom_targets file detected - {custom_targets_json_path}")  | 
115 | 114 | 
 
  | 
116 | 115 | 
 
  | 
117 | 116 |     used_mcu_names = set()  | 
118 | 117 |     LOGGER.info("Scanning targets.json5 for used MCU names...")  | 
119 | 118 |     json_contents = decode_json_file(TARGETS_JSON5_PATH)  | 
120 | 119 |     if custom_targets_file:  | 
121 | 120 |         LOGGER.info("Scanning custom_targets.json/json5. for used MCU names...")  | 
122 |  | -        json_contents.update(decode_json_file(CUSTOM_TARGETS_JSON_PATH))  | 
 | 121 | +        json_contents.update(decode_json_file(custom_targets_json_path))  | 
123 | 122 | 
 
  | 
124 | 123 |     for target_details in json_contents.values():  | 
125 | 124 |         if "device_name" in target_details:  | 
@@ -235,10 +234,8 @@ def fetch_missing():  | 
235 | 234 |                                f"to be added manually?")  | 
236 | 235 |         missing_mcus_dict[mcu] = cmsis_cache.index[mcu]  | 
237 | 236 | 
 
  | 
238 |  | -    if os.path.exists(CUSTOM_TARGETS_JSON_PATH):  | 
239 |  | -        LOGGER.info(f"Remove 'device_name' and add the 'memories' section as 'memory_banks' section\nfrom following entries to {CUSTOM_TARGETS_JSON_PATH}:")  | 
240 |  | -    else:  | 
241 |  | -       LOGGER.info(f"Add the following entries to {CMSIS_MCU_DESCRIPTIONS_JSON_PATH}:")  | 
242 |  | - | 
 | 237 | +    LOGGER.info(f"In case of Custom target remove 'device_name' from your custom_targets.json5 file and add\n" +  | 
 | 238 | +                    "just the 'memories' section as 'memory_banks' section from content below.\n" +  | 
 | 239 | +                    "Otherwise add the whole following entries to {CMSIS_MCU_DESCRIPTIONS_JSON_PATH}:")  | 
243 | 240 |     print(json.dumps(missing_mcus_dict, indent=4, sort_keys=True))  | 
244 | 241 |     sys.exit(1)   | 
0 commit comments