Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More .cproject normalization #79

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Run it on the repo
  • Loading branch information
puddly committed Aug 14, 2024
commit 566e57cc2336eadaa3a4e5dae9a4dd00dc024f49
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
Loading