diff options
| author | ruki <[email protected]> | 2016-07-10 21:28:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-10 21:28:04 +0800 |
| commit | c0a237b461bb03a73f3ba93c1f6b1637f3d613ce (patch) | |
| tree | c39c2b7e7d0445986bb93276135e2d493726c6bc | |
| parent | 6f0ee30871bde957f6923bdad95ac1c10a39fda3 (diff) | |
fix the current directory changed when building
| -rwxr-xr-x | xmake/actions/build/kinds/object.lua | 40 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 18 | ||||
| -rwxr-xr-x | xmake/plugins/project/makefile.lua | 6 |
3 files changed, 39 insertions, 25 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index ed4806822..2f6721b51 100755 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -70,6 +70,20 @@ function _build(target, g, index) local objectfile = objectfiles[index] local incdepfile = incdepfiles[index] + -- get the source file type + local filetype = path.extension(sourcefile):lower() + + -- calculate percent + local percent = ((g.targetindex + (index - 1) / #objectfiles) * 100 / g.targetcount) + + -- build the object for the *.o/obj source makefile + if filetype == ".o" or filetype == ".obj" then + return _build_from_object(target, sourcefile, objectfile, percent) + -- build the object for the *.[a|lib] source file + elseif filetype == ".a" or filetype == ".lib" then + return _build_from_static(target, sourcefile, objectfile, percent) + end + -- get dependent files local depfiles = {} if incdepfile and os.isfile(incdepfile) then @@ -91,28 +105,8 @@ function _build(target, g, index) return end - -- get the source file type - local filetype = path.extension(sourcefile):lower() - - -- calculate percent - local percent = ((g.targetindex + (index - 1) / #objectfiles) * 100 / g.targetcount) - - -- build the object for the *.o/obj source makefile - if filetype == ".o" or filetype == ".obj" then - return _build_from_object(target, sourcefile, objectfile, percent) - -- build the object for the *.[a|lib] source file - elseif filetype == ".a" or filetype == ".lib" then - return _build_from_static(target, sourcefile, objectfile, percent) - end - - -- get ccache - local ccache = nil - if config.get("ccache") then - ccache = tool.shellname("ccache") - end - -- trace - print("[%02d%%]: %scompiling.$(mode) %s", percent, ifelse(ccache, "ccache ", ""), sourcefile) + print("[%02d%%]: %scompiling.$(mode) %s", percent, ifelse(config.get("ccache"), "ccache ", ""), sourcefile) -- trace verbose info if option.get("verbose") then @@ -161,9 +155,13 @@ function buildall(target, g) tasks = pendings -- produce tasks + local curdir = os.curdir() while #tasks < jobs and index <= total do table.insert(tasks, {coroutine.create(function (index) + -- force to set the current directory first because the other jobs maybe changed it + os.cd(curdir) + -- build object _build(target, g, index) diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 61e19cd84..ae93103eb 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -318,6 +318,11 @@ function os.exec(cmd, outfile, errfile) local waitok = -1 local status = -1 if coroutine.running() then + + -- save the current directory + local curdir = os.curdir() + + -- wait it repeat -- poll it waitok, status = process.wait(proc, 0) @@ -325,6 +330,9 @@ function os.exec(cmd, outfile, errfile) coroutine.yield() end until waitok ~= 0 + + -- resume the current directory + os.cd(curdir) else waitok, status = process.wait(proc, -1) end @@ -354,13 +362,21 @@ function os.execv(shellname, argv, outfile, errfile) local waitok = -1 local status = -1 if coroutine.running() then + + -- save the current directory + local curdir = os.curdir() + + -- wait it repeat -- poll it - waitok, status = process.wait(prpoc, 0) + waitok, status = process.wait(proc, 0) if waitok == 0 then coroutine.yield() end until waitok ~= 0 + + -- resume the current directory + os.cd(curdir) else waitok, status = process.wait(proc, -1) end diff --git a/xmake/plugins/project/makefile.lua b/xmake/plugins/project/makefile.lua index 7620293ae..61300eb4c 100755 --- a/xmake/plugins/project/makefile.lua +++ b/xmake/plugins/project/makefile.lua @@ -25,6 +25,7 @@ import("core.tool.tool") import("core.tool.linker") import("core.tool.archiver") import("core.tool.compiler") +import("core.project.config") import("core.project.project") -- get log makefile @@ -78,8 +79,7 @@ function _make_object(makefile, target, srcfile, objfile) end -- make command - local ccache = tool.shellname("ccache") - local command = compiler.compcmd(srcfile, objfile, target) + local command = compiler.compcmd(srcfile, objfile, target) -- make head makefile:printf("%s:", objfile) @@ -88,7 +88,7 @@ function _make_object(makefile, target, srcfile, objfile) makefile:print(" %s", srcfile) -- make body - makefile:print("\t@echo %scompiling.$(mode) %s", ifelse(ccache, "ccache ", ""), srcfile) + makefile:print("\t@echo %scompiling.$(mode) %s", ifelse(config.get("ccache"), "ccache ", ""), srcfile) makefile:print("\t@xmake l %$(VERBOSE) verbose \"%s\"", command:encode()) makefile:print("\t@xmake l mkdir %s", path.directory(objfile)) makefile:print("\t@%s > %s 2>&1", command, _logfile()) |
