Skip to content

Commit

Permalink
Utility: fix Tweakable to work correctly with __FILE__ being absolute.
Browse files Browse the repository at this point in the history
This is what I get for testing *exclusively* with Ninja.
  • Loading branch information
mosra committed Mar 29, 2019
1 parent b5028eb commit edeeedb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/corrade-changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ namespace Corrade {
[mosra/corrade#51](https://github.com/mosra/corrade/issues/51))
- Fixed @ref CORRADE_COMPARE_WITH() to be callable with expressions such as
@cpp *comparator @ce
- Fixed @ref Utility::Tweakable to work correctly with buildsystems using
absolute paths for `__FILE__` macros (such as Makefiles, Ninja is using
relative paths). See [mosra/corrade#61](https://github.com/mosra/corrade/issues/61).

@subsection corrade-changelog-latest-deprecated Deprecated APIs

Expand Down
5 changes: 3 additions & 2 deletions src/Corrade/Utility/Tweakable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ std::pair<bool, void*> Tweakable::registerVariable(const char* const file, const
if(found == _data->files.end()) {
/* Strip the directory prefix from the file. If that means the filename
would then start with a slash, strip that too so Directory::join()
works correctly. */
works correctly -- but don't do that in case the directory prefix
was empty, in that case the file path was absolute. */
/** @todo maybe some Directory utility for this? */
std::string stripped = String::stripPrefix(Directory::fromNativeSeparators(file), _data->prefix);
if(!stripped.empty() && stripped.front() == '/')
if(!_data->prefix.empty() && !stripped.empty() && stripped.front() == '/')
stripped.erase(0, 1);

const std::string watchPath = Directory::join(_data->replace, stripped);
Expand Down

0 comments on commit edeeedb

Please sign in to comment.