From 6a323fc26309e4428b6c184e7b2abd61dd4c49ea Mon Sep 17 00:00:00 2001 From: starkos Date: Tue, 8 Dec 2009 20:25:35 +0000 Subject: [PATCH] Bug 2903430: Using relative instead of absolute paths with $() macro --- CHANGES.txt | 1 + premake4.lua | 2 +- src/base/configs.lua | 2 +- src/base/path.lua | 6 ++++ tests/base/test_path.lua | 67 +++++++++++++++++++++------------------- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3b66a8ee..7beaf1c9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,7 @@ - Clean action now removes MonoDevelop .pidb files correctly - Added os.executef() - Bug 2909463: Fix Xcode handling of Obj-C++ .mm files +- Bug 2903430: Using relative instead of absolute paths with $() macro ------- diff --git a/premake4.lua b/premake4.lua index b62a130f..e4b18ce7 100644 --- a/premake4.lua +++ b/premake4.lua @@ -34,7 +34,7 @@ files { - "src/**.h", "src/**.c", "**.lua", + "*.txt", "**.lua", "src/**.h", "src/**.c", } excludes diff --git a/src/base/configs.lua b/src/base/configs.lua index 5380e38e..ade786fc 100644 --- a/src/base/configs.lua +++ b/src/base/configs.lua @@ -133,7 +133,7 @@ if field.kind == "path" then obj[name] = path.getrelative(location, value) elseif field.kind == "dirlist" or field.kind == "filelist" then - for i, p in ipairs(value) do + for i, p in ipairs(value) do value[i] = path.getrelative(location, p) end end diff --git a/src/base/path.lua b/src/base/path.lua index f4243b1d..7e92f0c6 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -129,6 +129,12 @@ return dst end + -- dollar macro? Can't tell what the real path is; use absolute + -- This enables paths like $(SDK_ROOT)/include to work correctly. + if dst:startswith("$") then + return dst + end + src = src .. "/" dst = dst .. "/" diff --git a/tests/base/test_path.lua b/tests/base/test_path.lua index 75edc7f4..fc592cfd 100644 --- a/tests/base/test_path.lua +++ b/tests/base/test_path.lua @@ -5,26 +5,27 @@ -- T.path = { } + local suite = T.path -- -- path.getabsolute() tests -- - function T.path.getabsolute_ReturnsCorrectPath_OnMissingSubdir() + function suite.getabsolute_ReturnsCorrectPath_OnMissingSubdir() local expected = path.translate(os.getcwd(), "/") .. "/a/b/c" test.isequal(expected, path.getabsolute("a/b/c")) end - function T.path.getabsolute_RemovesDotDots_OnWindowsAbsolute() + function suite.getabsolute_RemovesDotDots_OnWindowsAbsolute() test.isequal("c:/ProjectB/bin", path.getabsolute("c:/ProjectA/../ProjectB/bin")) end - function T.path.getabsolute_RemovesDotDots_OnPosixAbsolute() + function suite.getabsolute_RemovesDotDots_OnPosixAbsolute() test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin")) end - function T.path.getabsolute_OnTrailingSlash() + function suite.getabsolute_OnTrailingSlash() local expected = path.translate(os.getcwd(), "/") .. "/a/b/c" test.isequal(expected, path.getabsolute("a/b/c/")) end @@ -34,7 +35,7 @@ -- path.getbasename() tests -- - function T.path.getbasename_ReturnsCorrectName_OnDirAndExtension() + function suite.getbasename_ReturnsCorrectName_OnDirAndExtension() test.isequal("filename", path.getbasename("folder/filename.ext")) end @@ -43,19 +44,19 @@ -- path.getdirectory() tests -- - function T.path.getdirectory_ReturnsEmptyString_OnNoDirectory() + function suite.getdirectory_ReturnsEmptyString_OnNoDirectory() test.isequal(".", path.getdirectory("filename.ext")) end - function T.path.getdirectory_ReturnsDirectory_OnSingleLevelPath() + function suite.getdirectory_ReturnsDirectory_OnSingleLevelPath() test.isequal("dir0", path.getdirectory("dir0/filename.ext")) end - function T.path.getdirectory_ReturnsDirectory_OnMultiLeveLPath() + function suite.getdirectory_ReturnsDirectory_OnMultiLeveLPath() test.isequal("dir0/dir1/dir2", path.getdirectory("dir0/dir1/dir2/filename.ext")) end - function T.path.getdirectory_ReturnsRootPath_OnRootPathOnly() + function suite.getdirectory_ReturnsRootPath_OnRootPathOnly() test.isequal("/", path.getdirectory("/filename.ext")) end @@ -65,11 +66,11 @@ -- path.getdrive() tests -- - function T.path.getdrive_ReturnsNil_OnNotWindows() + function suite.getdrive_ReturnsNil_OnNotWindows() test.isnil(path.getdrive("/hello")) end - function T.path.getdrive_ReturnsLetter_OnWindowsAbsolute() + function suite.getdrive_ReturnsLetter_OnWindowsAbsolute() test.isequal("x", path.getdrive("x:/hello")) end @@ -79,15 +80,15 @@ -- path.getextension() tests -- - function T.path.getextension_ReturnsEmptyString_OnNoExtension() + function suite.getextension_ReturnsEmptyString_OnNoExtension() test.isequal("", path.getextension("filename")) end - function T.path.getextension_ReturnsExtension() + function suite.getextension_ReturnsExtension() test.isequal(".txt", path.getextension("filename.txt")) end - function T.path.getextension_OnMultipleDots() + function suite.getextension_OnMultipleDots() test.isequal(".txt", path.getextension("filename.mod.txt")) end @@ -96,49 +97,53 @@ -- path.getrelative() tests -- - function T.path.getrelative_ReturnsDot_OnMatchingPaths() + function suite.getrelative_ReturnsDot_OnMatchingPaths() test.isequal(".", path.getrelative("/a/b/c", "/a/b/c")) end - function T.path.getrelative_ReturnsDoubleDot_OnChildToParent() + function suite.getrelative_ReturnsDoubleDot_OnChildToParent() test.isequal("..", path.getrelative("/a/b/c", "/a/b")) end - function T.path.getrelative_ReturnsDoubleDot_OnSiblingToSibling() + function suite.getrelative_ReturnsDoubleDot_OnSiblingToSibling() test.isequal("../d", path.getrelative("/a/b/c", "/a/b/d")) end - function T.path.getrelative_ReturnsChildPath_OnParentToChild() + function suite.getrelative_ReturnsChildPath_OnParentToChild() test.isequal("d", path.getrelative("/a/b/c", "/a/b/c/d")) end - function T.path.getrelative_ReturnsChildPath_OnWindowsAbsolute() + function suite.getrelative_ReturnsChildPath_OnWindowsAbsolute() test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug")) end - function T.path.getrelative_ReturnsAbsPath_OnDifferentDriveLetters() + function suite.getrelative_ReturnsAbsPath_OnDifferentDriveLetters() test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files")) end + function suite.getrelative_ReturnsAbsPath_OnDollarMacro() + test.isequal("$(SDK_HOME)/include", path.getrelative("C:/Code/Premake4", "$(SDK_HOME)/include")) + end + -- -- path.isabsolute() tests -- - function T.path.isabsolute_ReturnsTrue_OnAbsolutePosixPath() + function suite.isabsolute_ReturnsTrue_OnAbsolutePosixPath() test.istrue(path.isabsolute("/a/b/c")) end - function T.path.isabsolute_ReturnsTrue_OnAbsoluteWindowsPathWithDrive() + function suite.isabsolute_ReturnsTrue_OnAbsoluteWindowsPathWithDrive() test.istrue(path.isabsolute("C:/a/b/c")) end - function T.path.isabsolute_ReturnsFalse_OnRelativePath() + function suite.isabsolute_ReturnsFalse_OnRelativePath() test.isfalse(path.isabsolute("a/b/c")) end - function T.path.isabsolute_ReturnsTrue_OnDollarSign() + function suite.isabsolute_ReturnsTrue_OnDollarSign() test.istrue(path.isabsolute("$(SDK_HOME)/include")) end @@ -147,19 +152,19 @@ -- path.join() tests -- - function T.path.join_OnValidParts() + function suite.join_OnValidParts() test.isequal("leading/trailing", path.join("leading", "trailing")) end - function T.path.join_OnAbsoluteUnixPath() + function suite.join_OnAbsoluteUnixPath() test.isequal("/trailing", path.join("leading", "/trailing")) end - function T.path.join_OnAbsoluteWindowsPath() + function suite.join_OnAbsoluteWindowsPath() test.isequal("C:/trailing", path.join("leading", "C:/trailing")) end - function T.path.join_OnCurrentDirectory() + function suite.join_OnCurrentDirectory() test.isequal("trailing", path.join(".", "trailing")) end @@ -168,7 +173,7 @@ -- path.rebase() tests -- - function T.path.rebase_WithEndingSlashOnPath() + function suite.rebase_WithEndingSlashOnPath() local cwd = os.getcwd() test.isequal("src", path.rebase("../src/", cwd, path.getdirectory(cwd))) end @@ -178,11 +183,11 @@ -- path.translate() tests -- - function T.path.translate_ReturnsTranslatedPath_OnValidPath() + function suite.translate_ReturnsTranslatedPath_OnValidPath() test.isequal("dir/dir/file", path.translate("dir\\dir\\file", "/")) end - function T.path.translate_ReturnsCorrectSeparator_OnMixedPath() + function suite.translate_ReturnsCorrectSeparator_OnMixedPath() local actual = path.translate("dir\\dir/file") if (os.is("windows")) then test.isequal("dir\\dir\\file", actual)