Skip to content

Commit 10f4260

Browse files
committed
clean up
1 parent a8905fd commit 10f4260

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

builder/frameworks/component_manager.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,64 +1275,63 @@ def print_changes_summary(self) -> None:
12751275
def remove_no_lto_flags(self) -> bool:
12761276
"""
12771277
Remove all -fno-lto flags from pioarduino-build.py.
1278-
1278+
12791279
Removes all occurrences of -fno-lto from CCFLAGS, CFLAGS, CXXFLAGS,
12801280
and LINKFLAGS in the Arduino build script.
1281-
1281+
12821282
Returns:
12831283
bool: True if successful, False otherwise
12841284
"""
12851285
build_py_path = str(Path(self.config.arduino_libs_mcu) / "pioarduino-build.py")
1286-
1286+
12871287
if not os.path.exists(build_py_path):
12881288
print(f"Warning: pioarduino-build.py not found at {build_py_path}")
12891289
return False
1290-
1290+
12911291
try:
12921292
with open(build_py_path, 'r', encoding='utf-8') as f:
12931293
content = f.read()
1294-
1294+
12951295
# Remove all -fno-lto flags
12961296
modified_content = re.sub(r'["\']?-fno-lto["\']?,?\s*', '', content)
1297-
1297+
12981298
# Clean up any resulting empty strings or double commas
12991299
modified_content = re.sub(r',\s*,', ',', modified_content)
13001300
modified_content = re.sub(r'\[\s*,', '[', modified_content)
13011301
modified_content = re.sub(r',\s*\]', ']', modified_content)
1302-
1302+
13031303
with open(build_py_path, 'w', encoding='utf-8') as f:
13041304
f.write(modified_content)
1305-
1306-
print("*** Removed -fno-lto flags from pioarduino-build.py ***")
1305+
13071306
return True
1308-
1307+
13091308
except (IOError, OSError) as e:
13101309
print(f"Error removing -fno-lto flags: {e}")
13111310
return False
13121311

13131312
def add_lto_flags(self) -> bool:
13141313
"""
13151314
Add LTO flags to pioarduino-build.py.
1316-
1315+
13171316
Adds -flto=auto to CCFLAGS, CFLAGS, CXXFLAGS and -flto to LINKFLAGS
13181317
in the Arduino build script. Flags are inserted right after the opening bracket.
1319-
1318+
13201319
Returns:
13211320
bool: True if successful, False otherwise
13221321
"""
13231322
build_py_path = str(Path(self.config.arduino_libs_mcu) / "pioarduino-build.py")
1324-
1323+
13251324
if not os.path.exists(build_py_path):
13261325
print(f"Warning: pioarduino-build.py not found at {build_py_path}")
13271326
return False
1328-
1327+
13291328
try:
13301329
with open(build_py_path, 'r', encoding='utf-8') as f:
13311330
content = f.read()
1332-
1331+
13331332
original_content = content
13341333
modified = False
1335-
1334+
13361335
# Add -flto=auto to CCFLAGS right after the opening bracket
13371336
if 'CCFLAGS=[' in content:
13381337
ccflags_start = content.find('CCFLAGS=[')
@@ -1341,7 +1340,7 @@ def add_lto_flags(self) -> bool:
13411340
'\n "-flto=auto",' +
13421341
content[ccflags_section_start:])
13431342
modified = True
1344-
1343+
13451344
# Add -flto=auto to CFLAGS right after the opening bracket
13461345
if 'CFLAGS=[' in content:
13471346
cflags_start = content.find('CFLAGS=[')
@@ -1350,7 +1349,7 @@ def add_lto_flags(self) -> bool:
13501349
'\n "-flto=auto",' +
13511350
content[cflags_section_start:])
13521351
modified = True
1353-
1352+
13541353
# Add -flto=auto to CXXFLAGS right after the opening bracket
13551354
if 'CXXFLAGS=[' in content:
13561355
cxxflags_start = content.find('CXXFLAGS=[')
@@ -1359,7 +1358,7 @@ def add_lto_flags(self) -> bool:
13591358
'\n "-flto=auto",' +
13601359
content[cxxflags_section_start:])
13611360
modified = True
1362-
1361+
13631362
# Add -flto to LINKFLAGS right after the opening bracket
13641363
if 'LINKFLAGS=[' in content:
13651364
linkflags_start = content.find('LINKFLAGS=[')
@@ -1368,21 +1367,14 @@ def add_lto_flags(self) -> bool:
13681367
'\n "-flto",' +
13691368
content[linkflags_section_start:])
13701369
modified = True
1371-
1370+
13721371
if modified:
13731372
with open(build_py_path, 'w', encoding='utf-8') as f:
13741373
f.write(content)
1375-
1376-
print("*** Added LTO flags to pioarduino-build.py ***")
1377-
print(" CCFLAGS: -flto=auto")
1378-
print(" CFLAGS: -flto=auto")
1379-
print(" CXXFLAGS: -flto=auto")
1380-
print(" LINKFLAGS: -flto")
1381-
return True
1382-
else:
1383-
print("*** LTO flags already present in pioarduino-build.py ***")
1374+
1375+
print("*** Added LTO flags for Arduino compile ***")
13841376
return True
1385-
1377+
13861378
except (IOError, OSError) as e:
13871379
print(f"Error adding LTO flags: {e}")
13881380
return False

0 commit comments

Comments
 (0)