Skip to content

Commit fe1cd87

Browse files
committed
Remove flags safely in uvisions
1 parent 4965e61 commit fe1cd87

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

tools/export/uvision4.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from tools.export.exporters import Exporter, ExporterTargetsProperty
2121
from tools.targets import TARGET_MAP, TARGET_NAMES
22+
from tools.utils import remove_if_in
2223

2324
# If you wish to add a new target, add it to project_generator_definitions, and then
2425
# define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
@@ -87,11 +88,11 @@ def generate(self):
8788
+ self.flags['c_flags']
8889
+ self.flags['cxx_flags']))
8990
# not compatible with c99 flag set in the template
90-
project_data['misc']['c_flags'].remove("--c99")
91+
remove_if_in(project_data['misc']['c_flags'], "--c99")
9192
# cpp is not required as it's implicit for cpp files
92-
project_data['misc']['c_flags'].remove("--cpp")
93+
remove_if_in(project_data['misc']['c_flags'], "--cpp")
9394
# we want no-vla for only cxx, but it's also applied for C in IDE, thus we remove it
94-
project_data['misc']['c_flags'].remove("--no_vla")
95+
remove_if_in(project_data['misc']['c_flags'], "--no_vla")
9596
project_data['misc']['ld_flags'] = self.flags['ld_flags']
9697

9798
project_data['build_dir'] = project_data['build_dir'] + '\\' + 'uvision4'

tools/export/uvision5.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from tools.export.exporters import Exporter, ExporterTargetsProperty
2121
from tools.targets import TARGET_MAP, TARGET_NAMES
22+
from tools.utils import remove_if_in
2223

2324
# If you wish to add a new target, add it to project_generator_definitions, and then
2425
# define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
@@ -83,14 +84,12 @@ def generate(self):
8384
+ self.flags['c_flags']
8485
+ self.flags['cxx_flags']))
8586
# not compatible with c99 flag set in the template
86-
try:project_data['misc']['c_flags'].remove("--c99")
87-
except ValueError: pass
87+
remove_if_in(project_data['misc']['c_flags'], "--c99")
8888
# cpp is not required as it's implicit for cpp files
89-
try:project_data['misc']['c_flags'].remove("--cpp")
90-
except ValueError: pass
91-
# we want no-vla for only cxx, but it's also applied for C in IDE, thus we remove it=
92-
try:project_data['misc']['c_flags'].remove("--no_vla")
93-
except ValueError: pass
89+
remove_if_in(project_data['misc']['c_flags'], "--cpp")
90+
# we want no-vla for only cxx, but it's also applied for C in IDE, thus we remove it
91+
remove_if_in(project_data['misc']['c_flags'], "--no_vla")
92+
# not compatible with c99 flag set in the template
9493
project_data['misc']['ld_flags'] = self.flags['ld_flags']
9594

9695
i = 0

tools/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
from collections import OrderedDict
2929
import logging
3030

31+
def remove_if_in(lst, thing):
32+
if thing in lst:
33+
lst.remove(thing)
34+
3135
def compile_worker(job):
3236
"""Standard task runner used for compiling
3337

0 commit comments

Comments
 (0)