Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstarkos <none@none>2009-01-05 18:40:05 +0300
committerstarkos <none@none>2009-01-05 18:40:05 +0300
commit43660bcca529e492688a3e147a4245c12bba593e (patch)
tree5c4d7b3471e53a056807bcfd47f9428a5f6c2134
parent78392ab8e61eef2523a07819a0cdd50ea1461c0f (diff)
Support absolute paths in scripts, to reference a different Windows drive letter.
-rw-r--r--samples/project/CppConsoleApp/premake4.lua2
-rw-r--r--src/base/path.lua29
-rw-r--r--src/tools/gcc.lua2
-rw-r--r--tests/test_path.lua20
4 files changed, 48 insertions, 5 deletions
diff --git a/samples/project/CppConsoleApp/premake4.lua b/samples/project/CppConsoleApp/premake4.lua
index ced2554..e46c6d4 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 6dd5bd7..14bc9c3 100644
--- a/src/base/path.lua
+++ b/src/base/path.lua
@@ -68,6 +68,20 @@
--
+-- 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 9a8092f..4040b03 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 e19587c..44e8975 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