Skip to content

Commit f6bd94f

Browse files
authored
fixed #13895/13896/13897 - improved extension handling in platform lookup (#7564)
- only append extension to platform if missing and fixed a case it was missing - do not look for extension-less platform files
1 parent 0fca962 commit f6bd94f

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

lib/platform.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,24 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st
191191

192192
bool Platform::loadFromFile(const char exename[], const std::string &filename, bool debug)
193193
{
194-
// TODO: only append .xml if missing
194+
std::string fullfilename(filename);
195+
if (Path::getFilenameExtension(fullfilename).empty())
196+
fullfilename += ".xml";
197+
195198
// TODO: use native separators
196199
std::vector<std::string> filenames{
197-
filename,
198-
filename + ".xml",
199-
"platforms/" + filename,
200-
"platforms/" + filename + ".xml"
200+
fullfilename,
201+
"platforms/" + fullfilename,
201202
};
202203
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) {
203-
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
204-
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);
205-
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename + ".xml");
204+
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + fullfilename);
205+
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + fullfilename);
206206
}
207207
#ifdef FILESDIR
208208
std::string filesdir = FILESDIR;
209209
if (!filesdir.empty() && filesdir[filesdir.size()-1] != '/')
210210
filesdir += '/';
211-
filenames.push_back(filesdir + ("platforms/" + filename));
212-
filenames.push_back(filesdir + ("platforms/" + filename + ".xml"));
211+
filenames.push_back(filesdir + ("platforms/" + fullfilename));
213212
#endif
214213

215214
// open file..

test/cli/lookup_test.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ def test_platform_lookup(tmpdir):
284284
lines = stdout.splitlines()
285285
assert lines == [
286286
"looking for platform 'avr8' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
287-
"try to load platform file 'avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8",
288287
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml",
289-
"try to load platform file 'platforms/avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/avr8",
290288
"try to load platform file 'platforms/avr8.xml' ... Success",
291289
'Checking {} ...'.format(test_file)
292290
]
@@ -308,7 +306,6 @@ def test_platform_lookup_ext(tmpdir):
308306
assert lines == [
309307
"looking for platform 'avr8.xml' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
310308
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml",
311-
"try to load platform file 'avr8.xml.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml.xml", # TODO: the extension is incorrectly appended
312309
"try to load platform file 'platforms/avr8.xml' ... Success",
313310
'Checking {} ...'.format(test_file)
314311
]
@@ -329,13 +326,9 @@ def test_platform_lookup_notfound(tmpdir):
329326
lines = stdout.splitlines()
330327
assert lines == [
331328
"looking for platform 'none' in '{}'".format(exepath_bin), # TODO: this is not the path *of* the executable but the the path *to* the executable
332-
"try to load platform file 'none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none",
333329
"try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml",
334-
"try to load platform file 'platforms/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none",
335330
"try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml",
336-
"try to load platform file '{}/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none".format(exepath, exepath),
337-
# TODO: lookup of '{exepath}/none.xml' missing
338-
"try to load platform file '{}/platforms/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none".format(exepath, exepath),
331+
"try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(exepath, exepath),
339332
"try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(exepath, exepath),
340333
"cppcheck: error: unrecognized platform: 'none'."
341334
]
@@ -357,12 +350,9 @@ def test_platform_lookup_ext_notfound(tmpdir):
357350
assert lines == [
358351
"looking for platform 'none.xml' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
359352
"try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml",
360-
"try to load platform file 'none.xml.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml.xml", # TODO: the extension is incorrectly appended
361353
"try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml",
362-
"try to load platform file 'platforms/none.xml.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml.xml", # TODO: the extension is incorrectly appended
363354
"try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(exepath, exepath),
364355
"try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(exepath, exepath),
365-
"try to load platform file '{}/platforms/none.xml.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml.xml".format(exepath, exepath), # TODO: the extension is incorrectly appended
366356
"cppcheck: error: unrecognized platform: 'none.xml'."
367357
]
368358

@@ -383,12 +373,9 @@ def test_platform_lookup_relative_notfound(tmpdir):
383373
assert lines == [
384374
"looking for platform 'platform/none.xml' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
385375
"try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml",
386-
"try to load platform file 'platform/none.xml.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml.xml", # TODO: the extension is incorrectly appended
387376
"try to load platform file 'platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/platform/none.xml",
388-
"try to load platform file 'platforms/platform/none.xml.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/platform/none.xml.xml", # TODO: the extension is incorrectly appended
389377
"try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(exepath, exepath),
390378
"try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(exepath, exepath),
391-
"try to load platform file '{}/platforms/platform/none.xml.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml.xml".format(exepath, exepath), # TODO: the extension is incorrectly appended
392379
"cppcheck: error: unrecognized platform: 'platform/none.xml'."
393380
]
394381

@@ -408,12 +395,9 @@ def test_platform_lookup_relative_noext_notfound(tmpdir):
408395
lines = stdout.splitlines()
409396
assert lines == [
410397
"looking for platform 'platform/none' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
411-
"try to load platform file 'platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none",
412398
"try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml",
413-
"try to load platform file 'platforms/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/platform/none",
414399
"try to load platform file 'platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/platform/none.xml",
415-
"try to load platform file '{}/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none".format(exepath, exepath),
416-
"try to load platform file '{}/platforms/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none".format(exepath, exepath),
400+
"try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(exepath, exepath),
417401
"try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(exepath, exepath),
418402
"cppcheck: error: unrecognized platform: 'platform/none'."
419403
]
@@ -472,8 +456,6 @@ def test_platform_lookup_nofile(tmpdir):
472456
pass
473457

474458
# make sure we do not produce an error when the attempted lookup path is a directory and not a file
475-
avr8_dir = os.path.join(tmpdir, 'avr8')
476-
os.mkdir(avr8_dir)
477459
avr8_cfg_dir = os.path.join(tmpdir, 'avr8.xml')
478460
os.mkdir(avr8_cfg_dir)
479461

@@ -486,9 +468,7 @@ def test_platform_lookup_nofile(tmpdir):
486468
lines = stdout.splitlines()
487469
assert lines == [
488470
"looking for platform 'avr8' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
489-
"try to load platform file 'avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8",
490471
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml",
491-
"try to load platform file 'platforms/avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/avr8",
492472
"try to load platform file 'platforms/avr8.xml' ... Success",
493473
'Checking {} ...'.format(test_file)
494474
]
@@ -514,7 +494,6 @@ def test_platform_lookup_invalid(tmpdir):
514494
lines = stdout.splitlines()
515495
assert lines == [
516496
"looking for platform 'avr8' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
517-
"try to load platform file 'avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8",
518497
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_PARSING_TEXT ErrorID=8 (0x8) Line number=1",
519498
"cppcheck: error: unrecognized platform: 'avr8'."
520499
]

0 commit comments

Comments
 (0)