summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-06-16 23:12:56 +0800
committerruki <[email protected]>2020-06-16 13:17:40 +0800
commit973f85fd0f602b868a90725408507bd99ceb210a (patch)
tree7171d875de4b962a2a9c68437013f47e53837657
parent0d8d98df820f46e2bcfb187105efbbe464cce056 (diff)
improve os.execv to support chdir
-rw-r--r--xmake/core/base/os.lua9
-rw-r--r--xmake/modules/core/tools/ar.lua8
2 files changed, 10 insertions, 7 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 44b11a6f7..e681c0065 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -701,9 +701,18 @@ function os.execv(program, argv, opt)
-- init open options
local openopt = {envs = envs, stdout = opt.stdout, stderr = opt.stderr}
+ -- change the current working directory for child process
+ local oldir
+ if opt.curdir then
+ oldir = os.cd(opt.curdir)
+ end
+
-- open command
local ok = -1
local proc = process.openv(filename, argv or {}, openopt)
+ if oldir then
+ os.cd(oldir)
+ end
if proc ~= nil then
-- wait process
diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua
index e034924dc..7cf5a2351 100644
--- a/xmake/modules/core/tools/ar.lua
+++ b/xmake/modules/core/tools/ar.lua
@@ -83,23 +83,17 @@ function extract(self, libraryfile, objectdir)
-- get the absolute path of this library
libraryfile = path.absolute(libraryfile)
- -- enter the object directory
- local oldir = os.cd(objectdir)
-
-- extract it
os.runv(self:program(), {"-x", libraryfile})
-- check repeat object name
local repeats = {}
- local objectfiles = os.iorunv(self:program(), {"-t", libraryfile})
+ local objectfiles = os.iorunv(self:program(), {"-t", libraryfile}, {curdir = objectdir})
for _, objectfile in ipairs(objectfiles:split('\n')) do
if repeats[objectfile] then
raise("object name(%s) conflicts in library: %s", objectfile, libraryfile)
end
repeats[objectfile] = true
end
-
- -- leave the object directory
- os.cd(oldir)
end