Skip to content

Commit

Permalink
Run it on the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Aug 14, 2024
1 parent 293a8f6 commit 566e57c
Show file tree
Hide file tree
Showing 7 changed files with 11,500 additions and 18 deletions.
1,925 changes: 1,922 additions & 3 deletions misc/firmware-eraser/.cproject

Large diffs are not rendered by default.

1,293 changes: 1,291 additions & 2 deletions src/bootloader-uart-xmodem/.cproject

Large diffs are not rendered by default.

2,142 changes: 2,140 additions & 2 deletions src/ncp-uart-hw/.cproject

Large diffs are not rendered by default.

2,116 changes: 2,114 additions & 2 deletions src/ot-rcp/.cproject

Large diffs are not rendered by default.

2,258 changes: 2,256 additions & 2 deletions src/rcp-uart-802154/.cproject

Large diffs are not rendered by default.

1,768 changes: 1,766 additions & 2 deletions src/zwave_ncp_serial_api_controller/.cproject

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions tools/normalize_cproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import xml.etree.ElementTree as ET


def json_dumps(obj: dict | list) -> str:
"""Compactly dump JSON into a string."""
return json.dumps(obj, separators=(", ", ": "), indent=4)


cproject_path = pathlib.Path(sys.argv[1])
cproject = cproject_path.read_text()

Expand All @@ -20,7 +25,7 @@
copied_files.sort(
key=lambda f: (f["generated"], f["projectPath"], f["version"])
)
storage_module.attrib["projectCommon.copiedFiles"] = json.dumps(copied_files)
storage_module.attrib["projectCommon.copiedFiles"] = json_dumps(copied_files)

if "cppBuildConfig.projectBuiltInState" in storage_module.attrib:
project_built_in_state = json.loads(
Expand All @@ -32,17 +37,17 @@
resolved_options = json.loads(state["resolvedOptionsStr"])
resolved_options.sort(key=lambda o: o["optionId"])

state["resolvedOptionsStr"] = json.dumps(resolved_options)
state["resolvedOptionsStr"] = json_dumps(resolved_options)

storage_module.attrib["cppBuildConfig.projectBuiltInState"] = json.dumps(
storage_module.attrib["cppBuildConfig.projectBuiltInState"] = json_dumps(
project_built_in_state
)

if "projectCommon.referencedModules" in storage_module.attrib:
referenced_modules = json.loads(
storage_module.attrib["projectCommon.referencedModules"]
)
storage_module.attrib["projectCommon.referencedModules"] = json.dumps(
storage_module.attrib["projectCommon.referencedModules"] = json_dumps(
referenced_modules
)

Expand All @@ -52,7 +57,8 @@

# Replace newlines with literals!
xml_text = xml_text.replace("
", "\n")
xml_text = xml_text.replace("\\n", "\n\\n")
# xml_text.replace("\\n", "\n\\n")
xml_text = re.sub(r"\s+\\n\s+", "\n\\n", xml_text, flags=re.MULTILINE)

# Only touch the filesystem if we need to
if processing_instructions + xml_text != cproject:
Expand Down

0 comments on commit 566e57c

Please sign in to comment.