Support absolute paths in scripts, to reference a different Windows drive letter.

This commit is contained in:
starkos 2009-01-05 15:40:05 +00:00
parent 5fca9b101a
commit e0186be6ae
4 changed files with 48 additions and 5 deletions

View File

@ -5,5 +5,7 @@ project "CppConsoleApp"
files "*.cpp"
includedirs { "I:/Code" }
libdirs { "../lib" }
links { "CppSharedLib" }

View File

@ -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 .. "../"

View File

@ -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

View File

@ -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