Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,24 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st

bool Platform::loadFromFile(const char exename[], const std::string &filename, bool debug)
{
// TODO: only append .xml if missing
std::string fullfilename(filename);
if (Path::getFilenameExtension(fullfilename).empty())
fullfilename += ".xml";

// TODO: use native separators
std::vector<std::string> filenames{
filename,
filename + ".xml",
"platforms/" + filename,
"platforms/" + filename + ".xml"
fullfilename,
"platforms/" + fullfilename,
};
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) {
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename + ".xml");
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + fullfilename);
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + fullfilename);
}
#ifdef FILESDIR
std::string filesdir = FILESDIR;
if (!filesdir.empty() && filesdir[filesdir.size()-1] != '/')
filesdir += '/';
filenames.push_back(filesdir + ("platforms/" + filename));
filenames.push_back(filesdir + ("platforms/" + filename + ".xml"));
filenames.push_back(filesdir + ("platforms/" + fullfilename));
#endif

// open file..
Expand Down
25 changes: 2 additions & 23 deletions test/cli/lookup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ def test_platform_lookup(tmpdir):
lines = stdout.splitlines()
assert lines == [
"looking for platform 'avr8' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
"try to load platform file 'avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8",
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml",
"try to load platform file 'platforms/avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/avr8",
"try to load platform file 'platforms/avr8.xml' ... Success",
'Checking {} ...'.format(test_file)
]
Expand All @@ -308,7 +306,6 @@ def test_platform_lookup_ext(tmpdir):
assert lines == [
"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
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml",
"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
"try to load platform file 'platforms/avr8.xml' ... Success",
'Checking {} ...'.format(test_file)
]
Expand All @@ -329,13 +326,9 @@ def test_platform_lookup_notfound(tmpdir):
lines = stdout.splitlines()
assert lines == [
"looking for platform 'none' in '{}'".format(exepath_bin), # TODO: this is not the path *of* the executable but the the path *to* the executable
"try to load platform file 'none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none",
"try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml",
"try to load platform file 'platforms/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none",
"try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml",
"try to load platform file '{}/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none".format(exepath, exepath),
# TODO: lookup of '{exepath}/none.xml' missing
"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),
"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),
"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),
"cppcheck: error: unrecognized platform: 'none'."
]
Expand All @@ -357,12 +350,9 @@ def test_platform_lookup_ext_notfound(tmpdir):
assert lines == [
"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
"try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml",
"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
"try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml",
"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
"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),
"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),
"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
"cppcheck: error: unrecognized platform: 'none.xml'."
]

Expand All @@ -383,12 +373,9 @@ def test_platform_lookup_relative_notfound(tmpdir):
assert lines == [
"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
"try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml",
"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
"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",
"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
"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),
"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),
"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
"cppcheck: error: unrecognized platform: 'platform/none.xml'."
]

Expand All @@ -408,12 +395,9 @@ def test_platform_lookup_relative_noext_notfound(tmpdir):
lines = stdout.splitlines()
assert lines == [
"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
"try to load platform file 'platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none",
"try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml",
"try to load platform file 'platforms/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/platform/none",
"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",
"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),
"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),
"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),
"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),
"cppcheck: error: unrecognized platform: 'platform/none'."
]
Expand Down Expand Up @@ -472,8 +456,6 @@ def test_platform_lookup_nofile(tmpdir):
pass

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

Expand All @@ -486,9 +468,7 @@ def test_platform_lookup_nofile(tmpdir):
lines = stdout.splitlines()
assert lines == [
"looking for platform 'avr8' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
"try to load platform file 'avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8",
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml",
"try to load platform file 'platforms/avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/avr8",
"try to load platform file 'platforms/avr8.xml' ... Success",
'Checking {} ...'.format(test_file)
]
Expand All @@ -514,7 +494,6 @@ def test_platform_lookup_invalid(tmpdir):
lines = stdout.splitlines()
assert lines == [
"looking for platform 'avr8' in '{}'".format(exepath_bin), # TODO: this not not the path *of* the executable but the the path *to* the executable
"try to load platform file 'avr8' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8",
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_PARSING_TEXT ErrorID=8 (0x8) Line number=1",
"cppcheck: error: unrecognized platform: 'avr8'."
]
Expand Down
Loading