summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-04-01 13:47:48 +0800
committerruki <[email protected]>2017-04-01 13:47:48 +0800
commitcb5af728adf9d0d2f125c3054d1b6670d3debb9a (patch)
tree59b0520b235d9fafc8f119c3d102c84d856b7065
parente7673022575cb315c7f443b79641e08f761bb12b (diff)
find the project directory automatically
-rw-r--r--xmake/core/main.lua30
-rw-r--r--xmake/core/tool/compiler.lua4
-rw-r--r--xmake/core/tool/linker.lua4
3 files changed, 34 insertions, 4 deletions
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index a5f3d520f..8f0f2d1e6 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -99,6 +99,36 @@ function main._init()
end
xmake._PROJECT_FILE = projectfile
assert(projectfile)
+
+ -- xmake.lua not found? attempt to find it from the parent directory
+ if not os.isfile(projectfile) then
+
+ -- make all parent directories
+ local dirs = {}
+ local dir = path.directory(projectfile)
+ while os.isdir(dir) do
+ table.insert(dirs, 1, dir)
+ local parentdir = path.directory(dir)
+ if parentdir ~= dir then
+ dir = parentdir
+ else
+ break
+ end
+ end
+
+ -- find the first `xmake.lua`
+ for _, dir in ipairs(dirs) do
+ local file = path.join(dir, "xmake.lua")
+ if os.isfile(file) then
+
+ -- switch to the project directory
+ xmake._PROJECT_DIR = dir
+ xmake._PROJECT_FILE = file
+ os.cd(dir)
+ break
+ end
+ end
+ end
end
-- check run command as root
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 0fe79c6a4..a550564da 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -181,10 +181,10 @@ function compiler:compflags(target)
self:_addflags_from_language(flags, target)
-- add flags from the platform
- self:_addflags_from_platform(flags, target:targetkind())
+ self:_addflags_from_platform(flags, target:get("kind"))
-- add flags from the compiler
- self:_addflags_from_compiler(flags, target:targetkind())
+ self:_addflags_from_compiler(flags, target:get("kind"))
-- remove repeat
flags = table.unique(flags)
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 7f3e2c178..0ddf3165b 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -215,10 +215,10 @@ function linker:linkflags(target)
self:_addflags_from_language(flags, target)
-- add flags from the platform
- self:_addflags_from_platform(flags, target:targetkind())
+ self:_addflags_from_platform(flags, target:get("kind"))
-- add flags from the compiler
- self:_addflags_from_compiler(flags, target:targetkind(), target:sourcekinds())
+ self:_addflags_from_compiler(flags, target:get("kind"), target:sourcekinds())
-- add flags from the linker
self:_addflags_from_linker(flags)