Skip to content

Commit da2ee4a

Browse files
author
Gin
committed
update add_new_file script for the new file storing code file path list
1 parent 92bd83b commit da2ee4a

File tree

2 files changed

+12
-72
lines changed

2 files changed

+12
-72
lines changed
Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/python3
22

33
"""
4-
Add a new file to CMakeList.txt and SerialPrograms.pro
4+
Add a new file to SourceFiles.cmake, the CMake file that sets all code paths
55
66
Usage: python3 add_new_file.py <path to new file relative to Arduino-Source/
77
88
The script will try to find the root code folder "Arduino-Source/" from the path of the current directory
99
where this script is executed.
1010
11-
Then it will add the new file path (as the input parameter of this program) to proper places in CMakeList.txt
12-
and SerialPrograms.pro.
11+
Then it will add the new file path (as the input parameter of this program) to proper places in SourceFiles.cmake.
1312
1413
Example usage:
1514
python3 add_new_file.py Source/PokemonSV/Inference/Map/PokemonSV_MapFlyMenuDetectorDetector.h
@@ -75,92 +74,33 @@ def get_code_file_range(file_lines: List[str], starting_line: str, ending_line:
7574

7675

7776

78-
cmakelists_path = os.path.join(code_root_path, "SerialPrograms", "CMakeLists.txt")
79-
pro_path = os.path.join(code_root_path, "SerialPrograms", "SerialPrograms.pro")
80-
print(f"CMakeLists path: {cmakelists_path}")
81-
print(f"QT Pro project file path: {pro_path}")
77+
cmake_file_path = os.path.join(code_root_path, "SerialPrograms", "SourceFiles.cmake")
78+
print(f"SourceFiles.cmake path: {cmake_file_path}")
8279

83-
file_lines = read_lines(cmakelists_path)
80+
file_lines = read_lines(cmake_file_path)
8481
old_file_lines = file_lines
8582

8683
code_file_start, code_file_end = get_code_file_range(file_lines, "file(GLOB MAIN_SOURCES", ")")
8784
code_file_lines = set(file_lines[code_file_start:code_file_end])
8885
old_num_code_files = len(code_file_lines)
89-
print(f"{old_num_code_files} lines from CMakeLists are for code file paths")
86+
print(f"{old_num_code_files} lines from SourceFiles.cmake are for code file paths")
9087

9188
# Add new file
9289
if len(target_path) > 0:
9390
code_file_lines.add(" " + target_path)
9491

9592
code_file_lines = list(code_file_lines)
9693
code_file_lines.sort()
97-
if len(code_file_lines) == old_num_code_files:
94+
if len(target_path) > 0 and len(code_file_lines) == old_num_code_files:
9895
print("Warning: you are adding an existing file! The added file is ignored")
9996

10097
# print(f"\"{code_file_lines[0]}\"")
10198

10299
file_lines = file_lines[0:code_file_start] + code_file_lines + file_lines[code_file_end:]
103100
file_lines = [line + "\r\n" for line in file_lines]
104-
with open(cmakelists_path, "w") as f:
101+
with open(cmake_file_path, "w") as f:
105102
f.writelines(file_lines)
106-
print(f"Writed changes back to {cmakelists_path}")
107-
108-
if not os.path.exists(pro_path):
109-
print(f"Pro file not found. End.")
110-
exit(0)
111-
112-
file_lines = read_lines(pro_path)
113-
114-
# print("\n".join(file_lines[0:70]))
115-
116-
# lines = [line for line in file_lines if line.startswith("SOURCES")]
117-
# print(lines)
118-
119-
120-
def process_pro_lines(file_lines: List[str], starting_line: str, new_path: str) -> List[str]:
121-
122-
code_file_start, code_file_end = get_code_file_range(file_lines, starting_line, "")
123-
# print(code_file_start, code_file_end)
124-
# print(f"Starting line {file_lines[code_file_start]}")
125-
126-
code_file_lines = file_lines[code_file_start:code_file_end]
127-
128-
code_file_lines = [ line[0:-1].rstrip() if line.endswith("\\") else line for line in code_file_lines]
129-
130-
if len(new_path) > 0:
131-
code_file_lines.append(" " + new_path)
132-
133-
# Remove duplicates and sort
134-
code_file_lines = list(set(code_file_lines))
135-
code_file_lines.sort()
136-
137-
# Add back " \\":
138-
code_file_lines = [line + " \\" for line in code_file_lines]
139-
code_file_lines[-1] = code_file_lines[-1][0:-2]
140-
141-
# print("\n".join(code_file_lines[0:10]))
142-
143-
file_lines = file_lines[0:code_file_start] + code_file_lines + file_lines[code_file_end:]
144-
145-
return file_lines
146-
147-
if target_path.endswith(".cpp"):
148-
file_lines = process_pro_lines(file_lines, "SOURCES += \\", target_path)
149-
elif target_path.endswith(".h") or target_path.endswith(".tpp"):
150-
file_lines = process_pro_lines(file_lines, "HEADERS += \\", target_path)
151-
else:
152-
file_lines = process_pro_lines(file_lines, "SOURCES += \\", "")
153-
file_lines = process_pro_lines(file_lines, "HEADERS += \\", "")
154-
155-
# print("\n".join(file_lines[0:30]))
156-
157-
# Add back CRLF
158-
file_lines = [line + "\r\n" for line in file_lines]
159-
160-
with open(pro_path, "w") as f:
161-
f.writelines(file_lines)
162-
print(f"Writed changes back to {pro_path}")
163-
103+
print(f"Writed changes back to {cmake_file_path}")
164104

165105

166106

SerialPrograms/SourceFiles.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,13 @@ file(GLOB MAIN_SOURCES
683683
Source/Controllers/SerialPABotBase/SerialPABotBase_StatusThread.h
684684
Source/Controllers/StandardHid/StandardHid_Keyboard.cpp
685685
Source/Controllers/StandardHid/StandardHid_Keyboard.h
686+
Source/Controllers/StandardHid/StandardHid_KeyboardWithScheduler.cpp
687+
Source/Controllers/StandardHid/StandardHid_KeyboardWithScheduler.h
686688
Source/Controllers/StandardHid/StandardHid_Keyboard_ControllerButtons.h
687689
Source/Controllers/StandardHid/StandardHid_Keyboard_KeyMappings.cpp
688690
Source/Controllers/StandardHid/StandardHid_Keyboard_KeyMappings.h
689691
Source/Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.cpp
690692
Source/Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.h
691-
Source/Controllers/StandardHid/StandardHid_KeyboardWithScheduler.cpp
692-
Source/Controllers/StandardHid/StandardHid_KeyboardWithScheduler.h
693693
Source/Integrations/DiscordIntegrationSettings.cpp
694694
Source/Integrations/DiscordIntegrationSettings.h
695695
Source/Integrations/DiscordIntegrationTable.cpp
@@ -2377,4 +2377,4 @@ file(GLOB MAIN_SOURCES
23772377
Source/ZeldaTotK/ZeldaTotK_Panels.h
23782378
Source/ZeldaTotK/ZeldaTotK_Settings.cpp
23792379
Source/ZeldaTotK/ZeldaTotK_Settings.h
2380-
)
2380+
)

0 commit comments

Comments
 (0)