Support absolute paths in scripts, to reference a different Windows drive letter.
This commit is contained in:
parent
5fca9b101a
commit
e0186be6ae
@ -5,5 +5,7 @@ project "CppConsoleApp"
|
|||||||
|
|
||||||
files "*.cpp"
|
files "*.cpp"
|
||||||
|
|
||||||
|
includedirs { "I:/Code" }
|
||||||
|
|
||||||
libdirs { "../lib" }
|
libdirs { "../lib" }
|
||||||
links { "CppSharedLib" }
|
links { "CppSharedLib" }
|
||||||
|
@ -67,6 +67,20 @@
|
|||||||
end
|
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.
|
-- Retrieve the file extension.
|
||||||
--
|
--
|
||||||
@ -101,17 +115,23 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
function path.getrelative(src, dst)
|
function path.getrelative(src, dst)
|
||||||
local result = ""
|
|
||||||
|
|
||||||
-- normalize the two paths
|
-- normalize the two paths
|
||||||
src = path.getabsolute(src) .. "/"
|
src = path.getabsolute(src)
|
||||||
dst = path.getabsolute(dst) .. "/"
|
dst = path.getabsolute(dst)
|
||||||
|
|
||||||
-- same directory?
|
-- same directory?
|
||||||
if (src == dst) then
|
if (src == dst) then
|
||||||
return "."
|
return "."
|
||||||
end
|
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
|
-- trim off the common directories from the front
|
||||||
local i = src:find("/")
|
local i = src:find("/")
|
||||||
while (i) do
|
while (i) do
|
||||||
@ -125,6 +145,7 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- back up from dst to get to this common parent
|
-- back up from dst to get to this common parent
|
||||||
|
local result = ""
|
||||||
i = src:find("/")
|
i = src:find("/")
|
||||||
while (i) do
|
while (i) do
|
||||||
result = result .. "../"
|
result = result .. "../"
|
||||||
|
@ -134,7 +134,7 @@
|
|||||||
function premake.gcc.getincludedirs(includedirs)
|
function premake.gcc.getincludedirs(includedirs)
|
||||||
local result = { }
|
local result = { }
|
||||||
for _,dir in ipairs(includedirs) do
|
for _,dir in ipairs(includedirs) do
|
||||||
table.insert(result, '-I "' .. dir .. '"')
|
table.insert(result, "-I" .. _MAKE.esc(dir))
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
@ -56,6 +56,21 @@
|
|||||||
end
|
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
|
-- path.getextension() tests
|
||||||
--
|
--
|
||||||
@ -97,6 +112,11 @@
|
|||||||
test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug"))
|
test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function T.path.getrelative_ReturnsAbsPath_OnDifferentDriveLetters()
|
||||||
|
test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files"))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- path.isabsolute() tests
|
-- path.isabsolute() tests
|
||||||
|
Loading…
Reference in New Issue
Block a user