Skip to content

Commit c357e4e

Browse files
Respond to comments
1 parent c9afa6a commit c357e4e

File tree

4 files changed

+40
-81
lines changed

4 files changed

+40
-81
lines changed

tools/python/mbed_tools/build/_internal/config/schemas.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ConfigEntryDetails(BaseModel):
3131
macro_name: str | None = None
3232
"""
3333
Name of the macro that this setting shall generate. If unset, defaults to
34-
'MBED_CONF_<namespace uppercase>_<config entry name uppercase>', where
34+
``'MBED_CONF_<namespace uppercase>_<config entry name uppercase>'``, where
3535
<namespace> is the current namespace, i.e. the value of the "name" property for mbed_lib.json5 files,
3636
"target" for targets.json5 entries, and "app" in mbed_app.json5.
3737
"""
@@ -127,7 +127,7 @@ class BaseJSONConfig(BaseModel):
127127
"""
128128
List of overrides to unconditionally apply when this lib is included.
129129
130-
Overrides take the form "[<namespace>.]<setting>": <value> and cause the value of the given config
130+
Overrides take the form ``"[<namespace>.]<setting>": <value>`` and cause the value of the given config
131131
setting to be changed to the given value. If the namespace is omitted, it will be set to the current
132132
namespace (i.e. the value of the "name" property for mbed_lib.json5 files, "target" for targets.json5 entries, and
133133
"app" in mbed_app.json5).
@@ -188,13 +188,13 @@ class MbedLibJSON(BaseJSONConfig):
188188
List of overrides applied based on target labels. This is similar to the "overrides" section,
189189
but allows applying the override only if the target has a specific label. Labels generally
190190
come from the names of the target and its parents, but targets can also add extra ones.
191-
For example:
191+
For example::
192192
193-
"target_overrides": {
194-
"MIMXRT105X": {
195-
"some-setting": some-value
193+
"target_overrides": {
194+
"MIMXRT105X": {
195+
"some-setting": some-value
196+
}
196197
}
197-
}
198198
199199
would apply the override only for targets in the MIMXRT105X target family.
200200
@@ -279,14 +279,14 @@ class TargetJSON(BaseJSONConfig):
279279
from the "closest" ancestor is used, and all other values are discarded.
280280
281281
To determine the attribute's value, the inheritance tree is flattened into a list using a depth-first traversal
282-
that visits the first parent of each target first. For example, the inheritance tree diagram for target "A" below:
282+
that visits the first parent of each target first. For example, the inheritance tree diagram for target "A" below::
283283
284-
D E
285-
| |
286-
B C
287-
|_____|
288-
|
289-
A
284+
D E
285+
| |
286+
B C
287+
|_____|
288+
|
289+
A
290290
291291
Would give us an inheritance order of [A, B, D, C, E]. Then, the overriding attribute's value would be taken
292292
from the first target in this list to contain the attribute.
@@ -301,14 +301,14 @@ class TargetJSON(BaseJSONConfig):
301301
302302
UNLIKE overriding and merging attributes, accumulating attributes use a breadth-first search to flatten
303303
the inheritance hierarchy. (why? no idea! Probably for legacy compatibility...). For example, an inheritance
304-
tree diagram for the target "A" below
304+
tree diagram for the target "A" below::
305305
306-
D E
307-
| |
308-
B C
309-
|_____|
310-
|
311-
A
306+
D E
307+
| |
308+
B C
309+
|_____|
310+
|
311+
A
312312
313313
Would give us an inheritance order of [A, B, C, D, E]. To process this, the first occurrence of the bare
314314
attribute name in the above list is found, and then we work backwards towards target A processing "_add" and
@@ -366,14 +366,14 @@ class TargetJSON(BaseJSONConfig):
366366
367367
Note that this specific attribute has some special behavior, in that the value after the "=" in the macro
368368
definition can be ignored when finding matches to remove. So if the parent target adds a macro "FOO=7", then
369-
doing "macros_remove": ["FOO"] in a child target is enough to remove it.
369+
doing ``"macros_remove": ["FOO"]`` in a child target is enough to remove it.
370370
"""
371371

372372
extra_labels: list[str] = Field(default_factory=list)
373373
"""
374374
Additional labels to add for this target and targets that inherit from it.
375-
Labels are added to the `MBED_TARGET_LABELS` list in CMake, and become compile definitions
376-
in the format `TARGET_<label>`.
375+
Labels are added to the ``MBED_TARGET_LABELS`` list in CMake, and become compile definitions
376+
in the format ``TARGET_<label>``.
377377
They are also used to control which directories in the source code are scanned for mbed_lib.json5 files.
378378
379379
This is an accumulating attribute in its base form.
@@ -464,7 +464,7 @@ class TargetJSON(BaseJSONConfig):
464464
465465
See mbed-os/targets/drivers.json5 for a full list of recognized peripheral names.
466466
467-
The peripheral list becomes compile definitions in the format `DEVICE_<name>`.
467+
The peripheral list becomes compile definitions in the format ``DEVICE_<name>``.
468468
469469
This is an accumulating attribute in its base form.
470470
"""
@@ -598,13 +598,13 @@ class MbedAppJSON(BaseJSONConfig):
598598
List of overrides applied based on target labels. This is similar to the "overrides" section,
599599
but allows applying the override only if the target has a specific label. Labels generally
600600
come from the names of the target and its parents, but targets can also add extra ones.
601-
For example:
601+
For example::
602602
603-
"target_overrides": {
604-
"MIMXRT105X": {
605-
"some-setting": some-value
603+
"target_overrides": {
604+
"MIMXRT105X": {
605+
"some-setting": some-value
606+
}
606607
}
607-
}
608608
609609
would apply the override only for targets in the MIMXRT105X target family.
610610

tools/python/mbed_tools/build/_internal/config/source.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def check_and_transform_config_name(context: str, config_name: str) -> str:
9090
"""
9191
if config_name.lower() != config_name:
9292
logger.warning(
93-
f"Config setting '{config_name}' in {context} contains uppercase letters. This style is not recommended."
93+
f"Config setting '{config_name}' in {context} contains uppercase letters. This style is not recommended and these will be replaced by lowercase letters."
9494
)
9595
if "." in config_name:
9696
logger.warning(
@@ -101,7 +101,7 @@ def check_and_transform_config_name(context: str, config_name: str) -> str:
101101
f"Config setting '{config_name}' in {context} contains an underscore. This style is not recommended as it may cause confusion (config names should be in skewer-case). Underscores are replaced by hyphens when Mbed processes JSON settings."
102102
)
103103

104-
return config_name.replace("_", "-")
104+
return config_name.replace("_", "-").lower()
105105

106106

107107
def from_mbed_lib_json_file(

tools/python/mbed_tools/targets/_internal/targets_json_parsers/accumulating_attribute_parser.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,15 @@ def _add_attribute_element(accumulator: Dict[str, Any], attribute_name: str, ele
9797
accumulator[attribute_name].append(element)
9898

9999

100-
def _macros_element_matches(element_to_remove: str, element_to_check: str) -> bool:
101-
"""
102-
Checks if an element meets the criteria to be removed from list.
103-
104-
Some attribute elements (eg. macros) can be defined with a number value
105-
eg. MACRO_SOMETHING=5. If we are then instructed to remove
106-
MACRO_SOMETHING then this element needs to be recognised and removed
107-
in addition to exact matches.
108-
109-
Args:
110-
element_to_remove: the element as taken from list to be removed from an attribute
111-
element_to_check: an element that currently makes up part of an attribute definition
112-
113-
Returns:
114-
A boolean reflecting whether the element is a match and should be removed
115-
"""
116-
return element_to_check == element_to_remove or element_to_check.startswith(f"{element_to_remove}=")
117-
118-
119100
def _remove_attribute_element(accumulator: Dict[str, Any], attribute_name: str, elements_to_remove: List[Any]) -> None:
120101
"""
121102
Removes an attribute element from an attribute.
122103
104+
Note that macros can be defined with a number value
105+
eg. "MACRO_SOMETHING=5". If we are then instructed to remove
106+
MACRO_SOMETHING then this element needs to be recognised and removed
107+
in addition to exact matches. This logic is specific to the "macros" attribute_name
108+
123109
Args:
124110
accumulator: a store of attributes to be updated
125111
attribute_name: name of the attribute to update
@@ -129,9 +115,9 @@ def _remove_attribute_element(accumulator: Dict[str, Any], attribute_name: str,
129115
combinations_to_check = itertools.product(existing_elements, elements_to_remove)
130116
checked_elements_to_remove = [
131117
existing_element
132-
for existing_element, element in combinations_to_check
133-
if (attribute_name == "macros" and _macros_element_matches(element, existing_element))
134-
or (element == existing_element)
118+
for existing_element, element_to_remove in combinations_to_check
119+
if (attribute_name == "macros" and existing_element.startswith(f"{element_to_remove}="))
120+
or (element_to_remove == existing_element)
135121
]
136122

137123
for element in checked_elements_to_remove:

tools/python_tests/mbed_tools/targets/_internal/targets_json_parsers/test_accumulating_attribute_parser.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
_targets_accumulate_hierarchy,
1515
_determine_accumulated_attributes,
1616
_remove_attribute_element,
17-
_macros_element_matches,
1817
)
1918

2019

@@ -162,32 +161,6 @@ def test_determine_accumulated_attributes_basic_add(self):
162161
self.assertEqual(orig_accumulation_order, accumulation_order)
163162

164163

165-
class TestElementMatches(TestCase):
166-
def test_element_matches_exactly(self):
167-
element_to_remove = "SOMETHING"
168-
element_to_check = "SOMETHING"
169-
170-
self.assertTrue(_macros_element_matches(element_to_remove, element_to_check))
171-
172-
def test_element_no_match(self):
173-
element_to_remove = "SOMETHING"
174-
element_to_check = "SOMETHING_ELSE"
175-
176-
self.assertFalse(_macros_element_matches(element_to_remove, element_to_check))
177-
178-
def test_element_matches_with_number_arg(self):
179-
element_to_remove = "SOMETHING"
180-
element_to_check = "SOMETHING=5"
181-
182-
self.assertTrue(_macros_element_matches(element_to_remove, element_to_check))
183-
184-
def test_element_no_match_with_number_arg(self):
185-
element_to_remove = "SOMETHING"
186-
element_to_check = "SOMETHING_DIFFERENT=5"
187-
188-
self.assertFalse(_macros_element_matches(element_to_remove, element_to_check))
189-
190-
191164
class TestRemoveAttributeElement(TestCase):
192165
def test_remove_element_without_numbers(self):
193166
current_attribute_state = {"attribute_1": ["ONE", "TWO=2", "THREE"]}

0 commit comments

Comments
 (0)