@@ -118,10 +118,9 @@ def main():
118
118
metavar = "<platform>" ,
119
119
action = "append" ,
120
120
default = [],
121
- help = "Add the specified platform to the analysis. "
122
- + "May be a name or a path to a compilation database. "
121
+ help = "Include the specified platform in the analysis. "
123
122
+ "May be specified multiple times. "
124
- + "If not specified, all known platforms will be included." ,
123
+ + "If not specified, all platforms will be included." ,
125
124
)
126
125
# The analysis-file argument is optional while we support the -c option.
127
126
parser .add_argument (
@@ -175,33 +174,9 @@ def main():
175
174
"Cannot use --config (-c) with TOML analysis files." ,
176
175
)
177
176
178
- # Process the -p flag first to infer wider context.
179
- filtered_platforms = []
180
- additional_platforms = []
181
- for p in args .platforms :
182
- # If it's a path, it has to be a compilation database.
183
- if os .path .exists (p ):
184
- if not os .path .splitext (p )[1 ] == ".json" :
185
- raise RuntimeError (f"Platform file { p } must end in .json." )
186
- additional_platforms .append (p )
187
- continue
188
-
189
- # Otherwise, treat it as a name in the configuration file.
190
- # Explain the logic above in cases that look suspiciously like paths.
191
- if "/" in p or os .path .splitext (p )[1 ] == ".json" :
192
- logging .getLogger ("codebasin" ).warning (
193
- f"{ p } doesn't exist, so will be treated as a name." ,
194
- )
195
- filtered_platforms .append (p )
196
-
197
- # A legacy config file is required if:
198
- # - No additional platforms are specified; and
199
- # - No TOML analysis file is specified
177
+ # If no file is specified, legacy behavior checks for config.yaml
200
178
config_file = args .config_file
201
- config_required = (
202
- len (additional_platforms ) == 0 and args .analysis_file is None
203
- )
204
- if config_file is None and config_required :
179
+ if args .config_file is None and args .analysis_file is None :
205
180
warnings .warn (
206
181
"Implicitly defined configuration files are deprecated." ,
207
182
DeprecationWarning ,
@@ -236,15 +211,15 @@ def main():
236
211
config_file ,
237
212
rootdir ,
238
213
exclude_patterns = args .excludes ,
239
- filtered_platforms = filtered_platforms ,
214
+ filtered_platforms = args . platforms ,
240
215
)
241
216
242
217
# Load the analysis file if it exists.
243
218
if args .analysis_file is not None :
244
219
path = os .path .realpath (args .analysis_file )
245
220
if os .path .exists (path ):
246
221
if not os .path .splitext (path )[1 ] == ".toml" :
247
- raise RuntimeError (f"Analysis file { p } must end in .toml." )
222
+ raise RuntimeError (f"Analysis file { path } must end in .toml." )
248
223
249
224
with util .safe_open_read_nofollow (path , "rb" ) as f :
250
225
try :
@@ -257,23 +232,23 @@ def main():
257
232
excludes = analysis_toml ["codebase" ]["exclude" ]
258
233
codebase ["exclude_patterns" ] += excludes
259
234
235
+ for name in args .platforms :
236
+ if name not in analysis_toml ["platform" ].keys ():
237
+ raise RuntimeError (
238
+ f"Platform { name } requested on the command line "
239
+ + "does not exist in the configuration file." ,
240
+ )
241
+
260
242
for name in analysis_toml ["platform" ].keys ():
261
- if filtered_platforms and name not in filtered_platforms :
243
+ if args . platforms and name not in args . platforms :
262
244
continue
263
245
if "commands" not in analysis_toml ["platform" ][name ]:
264
246
raise ValueError (f"Missing 'commands' for platform { name } " )
265
247
p = analysis_toml ["platform" ][name ]["commands" ]
266
248
db = config .load_database (p , rootdir )
249
+ codebase ["platforms" ].append (name )
267
250
configuration .update ({name : db })
268
251
269
- # Extend configuration with any additional platforms.
270
- for p in additional_platforms :
271
- name = os .path .splitext (os .path .basename (p ))[0 ]
272
- if name in codebase ["platforms" ]:
273
- raise RuntimeError (f"Platform name { p } conflicts with { name } ." )
274
- db = config .load_database (p , rootdir )
275
- configuration .update ({name : db })
276
-
277
252
# Parse the source tree, and determine source line associations.
278
253
# The trees and associations are housed in state.
279
254
legacy_warnings = True if config_file else False
0 commit comments