diff --git a/samples/project/CppConsoleApp/premake4.lua b/samples/project/CppConsoleApp/premake4.lua index ced25543..e46c6d49 100644 --- a/samples/project/CppConsoleApp/premake4.lua +++ b/samples/project/CppConsoleApp/premake4.lua @@ -5,5 +5,7 @@ project "CppConsoleApp" files "*.cpp" + includedirs { "I:/Code" } + libdirs { "../lib" } links { "CppSharedLib" } diff --git a/src/base/path.lua b/src/base/path.lua index 6dd5bd74..14bc9c39 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -67,6 +67,20 @@ end +-- +-- Retrieve the drive letter, if a Windows path. +-- + + function path.getdrive(p) + local ch1 = p:sub(1,1) + local ch2 = p:sub(2,2) + if ch2 == ":" then + return ch1 + end + end + + + -- -- Retrieve the file extension. -- @@ -101,17 +115,23 @@ -- function path.getrelative(src, dst) - local result = "" - -- normalize the two paths - src = path.getabsolute(src) .. "/" - dst = path.getabsolute(dst) .. "/" + src = path.getabsolute(src) + dst = path.getabsolute(dst) -- same directory? if (src == dst) then return "." end + -- different drives? Must use absolute path + if path.getdrive(src) ~= path.getdrive(dst) then + return dst + end + + src = src .. "/" + dst = dst .. "/" + -- trim off the common directories from the front local i = src:find("/") while (i) do @@ -125,6 +145,7 @@ end -- back up from dst to get to this common parent + local result = "" i = src:find("/") while (i) do result = result .. "../" diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 9a8092f2..4040b033 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -134,7 +134,7 @@ function premake.gcc.getincludedirs(includedirs) local result = { } for _,dir in ipairs(includedirs) do - table.insert(result, '-I "' .. dir .. '"') + table.insert(result, "-I" .. _MAKE.esc(dir)) end return result end diff --git a/tests/test_path.lua b/tests/test_path.lua index e19587c5..44e8975b 100644 --- a/tests/test_path.lua +++ b/tests/test_path.lua @@ -56,6 +56,21 @@ end + +-- +-- path.getdrive() tests +-- + + function T.path.getdrive_ReturnsNil_OnNotWindows() + test.isnil(path.getdrive("/hello")) + end + + function T.path.getdrive_ReturnsLetter_OnWindowsAbsolute() + test.isequal("x", path.getdrive("x:/hello")) + end + + + -- -- path.getextension() tests -- @@ -97,6 +112,11 @@ test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug")) end + function T.path.getrelative_ReturnsAbsPath_OnDifferentDriveLetters() + test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files")) + end + + -- -- path.isabsolute() tests