summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-05-12 06:15:20 +0800
committerGitHub <[email protected]>2021-05-12 06:15:20 +0800
commit0c8ee70f2cf09156d728decc44a28c756e1beded (patch)
treea0f9258a2f79b6f9960c6eb07365520bf3e92fa9
parent29cf1854c5dd3ceedc4d89aa35ac6b100fd56571 (diff)
parent78778eb35d7b5d9c6fac432d4ed4a67dc4cbd5d3 (diff)
Merge pull request #1404 from xmake-io/jobenvs
improve envs
-rw-r--r--.appveyor.yml1
-rw-r--r--tests/modules/scheduler/runjobs.lua4
-rw-r--r--xmake/actions/build/build.lua26
-rw-r--r--xmake/actions/build/kinds/binary.lua2
-rw-r--r--xmake/actions/build/kinds/object.lua12
-rw-r--r--xmake/actions/build/kinds/shared.lua2
-rw-r--r--xmake/actions/build/kinds/static.lua2
-rw-r--r--xmake/actions/clean/main.lua10
-rw-r--r--xmake/actions/install/install.lua10
-rw-r--r--xmake/actions/package/main.lua10
-rw-r--r--xmake/actions/run/main.lua19
-rw-r--r--xmake/actions/uninstall/uninstall.lua10
-rw-r--r--xmake/core/base/os.lua72
-rw-r--r--xmake/core/base/scheduler.lua60
-rw-r--r--xmake/core/project/target.lua23
-rw-r--r--xmake/core/sandbox/modules/import/core/base/scheduler.lua9
-rw-r--r--xmake/modules/private/action/build/object.lua2
-rw-r--r--xmake/modules/private/action/require/check.lua2
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua7
-rw-r--r--xmake/modules/private/action/require/impl/package.lua1
-rw-r--r--xmake/modules/private/async/jobpool.lua7
-rw-r--r--xmake/modules/private/async/runjobs.lua8
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua4
23 files changed, 166 insertions, 137 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index ca36205c8..884c8c5f3 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -75,7 +75,6 @@ after_build:
- ps: Copy-Item .\core\build\xmake.exe .\xmake
- ps: Copy-Item .\scripts\xrepo.bat .\xmake\xrepo.bat
- ps: Copy-Item .\scripts\xrepo.ps1 .\xmake\xrepo.ps1
- - ps: Copy-Item .\scripts\xrepo-hook.psm1 .\xmake\scripts\xrepo-hook.psm1
- ps: |-
Add-Type -AssemblyName System.Text.Encoding
Add-Type -AssemblyName System.IO.Compression.FileSystem
diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua
index 8659ef6ef..aea365241 100644
--- a/tests/modules/scheduler/runjobs.lua
+++ b/tests/modules/scheduler/runjobs.lua
@@ -28,11 +28,11 @@ function main()
for i = 1, 3 do
local job = jobs:addjob("job/" .. i, function (idx, total)
_jobfunc(idx, total)
- end, root)
+ end, {rootjob = root})
for j = 1, 50 do
jobs:addjob("job/" .. i .. "/" .. j, function (idx, total)
_jobfunc(idx, total)
- end, job)
+ end, {rootjob = job})
end
end
t = os.mclock()
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index a8029e24c..0fc15fd81 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -48,7 +48,7 @@ function _add_batchjobs_builtin(batchjobs, rootjob, target)
else
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
- end, job or rootjob)
+ end, {rootjob = job or rootjob})
end
end
end
@@ -76,7 +76,7 @@ function _add_batchjobs(batchjobs, rootjob, target)
-- on_build(function (target, batchjobs, opt)
-- return batchjobs:addjob("test", function (idx, total)
-- print("build it")
- -- end, opt.rootjob)
+ -- end, {rootjob = opt.rootjob})
-- end, {batch = true})
--
job, job_leaf = assert(script(target, batchjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name())
@@ -91,7 +91,7 @@ function _add_batchjobs(batchjobs, rootjob, target)
--
job = batchjobs:addjob(target:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
end
return job, job_leaf or job
end
@@ -105,7 +105,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
end
-- add after_build job for target
- local oldenvs = {}
+ local oldenvs
local job_after_build = batchjobs:addjob(target:name() .. "/after_build", function (index, total)
-- do after_build
@@ -121,11 +121,12 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
end
end
- -- leave the environments of the target packages
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
+ -- restore environments
+ if oldenvs then
+ os.setenvs(oldenvs)
end
- end, rootjob)
+
+ end, {rootjob = rootjob})
-- add batch jobs for target, @note only on_build script support batch jobs
local job_build, job_build_leaf = _add_batchjobs(batchjobs, job_after_build, target)
@@ -133,11 +134,8 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
-- add before_build job for target
local job_build_before = batchjobs:addjob(target:name() .. "/before_build", function (index, total)
- -- enter the environments of the target packages
- for name, values in pairs(target:pkgenvs()) do
- oldenvs[name] = os.getenv(name)
- os.addenv(name, unpack(values))
- end
+ -- enter package environments
+ oldenvs = os.addenvs(target:pkgenvs())
-- clean target if rebuild
if option.get("rebuild") and not option.get("dry-run") then
@@ -156,7 +154,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
before_build(target, {progress = progress})
end
end
- end, job_build_leaf)
+ end, {rootjob = job_build_leaf})
-- we need do build_before after all dependent targets if across_targets_in_parallel is disabled
return target:policy("build.across_targets_in_parallel") == false and job_build_before or job_build, job_after_build
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index bc4763fd6..dd72fc21a 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -135,7 +135,7 @@ function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
-- we need only return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index 866c9680c..742311370 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -42,7 +42,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
else
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total)
script(target, sourcebatch, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
end
end
@@ -55,7 +55,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
end
end
end
@@ -69,7 +69,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcebatch, {progress = (index * 100) / total})
batchcmds_:runcmds({dryrun = option.get("dry-run")})
- end, rootjob)
+ end, {rootjob = rootjob})
end
end
@@ -84,7 +84,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
batchcmds_:runcmds({dryrun = option.get("dry-run")})
- end, rootjob)
+ end, {rootjob = rootjob})
end
end
end
@@ -102,7 +102,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suff
else
batchjobs:addjob(target:name() .. "/" .. scriptname, function (index, total)
script(target, sourcebatch, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
end
return true
else
@@ -113,7 +113,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target, sourcebatch, suff
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
script(target, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
end
return true
end
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 2c95bd95b..2d2d9e507 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -150,7 +150,7 @@ function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
-- we need only return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 63bc50304..91fba6ed5 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -150,7 +150,7 @@ function main(batchjobs, rootjob, target)
-- add link job
local job_link = batchjobs:addjob(target:name() .. "/link", function (index, total)
_link_target(target, {progress = (index * 100) / total})
- end, rootjob)
+ end, {rootjob = rootjob})
-- we need only return and depend the link job for each target,
-- so we can compile the source files for each target in parallel
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 4dc42437a..e9e574545 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -56,11 +56,7 @@ function _clean_target(target)
end
-- enter the environments of the target packages
- local oldenvs = {}
- for name, values in pairs(target:pkgenvs()) do
- oldenvs[name] = os.getenv(name)
- os.addenv(name, unpack(values))
- end
+ local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
@@ -95,9 +91,7 @@ function _clean_target(target)
end
-- leave the environments of the target packages
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
- end
+ os.setenvs(oldenvs)
end
-- clean the given targets
diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua
index 1a71bda40..b4b0a6628 100644
--- a/xmake/actions/install/install.lua
+++ b/xmake/actions/install/install.lua
@@ -57,11 +57,7 @@ function _install_target(target)
local oldir = os.cd(project.directory())
-- enter the environments of the target packages
- local oldenvs = {}
- for name, values in pairs(target:pkgenvs()) do
- oldenvs[name] = os.getenv(name)
- os.addenv(name, unpack(values))
- end
+ local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
@@ -96,9 +92,7 @@ function _install_target(target)
end
-- leave the environments of the target packages
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
- end
+ os.setenvs(oldenvs)
-- leave project directory
os.cd(oldir)
diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua
index 39078392b..a1fcab5ed 100644
--- a/xmake/actions/package/main.lua
+++ b/xmake/actions/package/main.lua
@@ -147,11 +147,7 @@ function _package_target(target)
local oldir = os.cd(project.directory())
-- enter the environments of the target packages
- local oldenvs = {}
- for name, values in pairs(target:pkgenvs()) do
- oldenvs[name] = os.getenv(name)
- os.addenv(name, unpack(values))
- end
+ local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
@@ -186,9 +182,7 @@ function _package_target(target)
end
-- leave the environments of the target packages
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
- end
+ os.setenvs(oldenvs)
-- leave project directory
os.cd(oldir)
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 04b0d76d4..a74845f95 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -84,19 +84,14 @@ function _on_run_target(target)
end
-- recursively target add env
-function _add_target_pkgenvs(target, oldenvs, targets_added)
+function _add_target_pkgenvs(target, targets_added)
if targets_added[target:name()] then
return
end
targets_added[target:name()] = true
- for name, values in pairs(target:pkgenvs()) do
- if not oldenvs[name] then
- oldenvs[name] = os.getenv(name)
- end
- os.addenv(name, unpack(values))
- end
+ os.addenvs(target:pkgenvs())
for _, dep in ipairs(target:orderdeps()) do
- _add_target_pkgenvs(dep, oldenvs, targets_added)
+ _add_target_pkgenvs(dep, targets_added)
end
end
@@ -109,8 +104,8 @@ function _run(target)
end
-- enter the environments of the target packages
- local oldenvs = {}
- _add_target_pkgenvs(target, oldenvs, {})
+ local oldenvs = os.getenvs()
+ _add_target_pkgenvs(target, {})
-- the target scripts
local scripts =
@@ -145,9 +140,7 @@ function _run(target)
end
-- leave the environments of the target packages
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
- end
+ os.setenvs(oldenvs)
end
-- check targets
diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua
index 08b5067ba..8ce5346a6 100644
--- a/xmake/actions/uninstall/uninstall.lua
+++ b/xmake/actions/uninstall/uninstall.lua
@@ -57,11 +57,7 @@ function _uninstall_target(target)
local oldir = os.cd(project.directory())
-- enter the environments of the target packages
- local oldenvs = {}
- for name, values in pairs(target:pkgenvs()) do
- oldenvs[name] = os.getenv(name)
- os.addenv(name, unpack(values))
- end
+ local oldenvs = os.addenvs(target:pkgenvs())
-- the target scripts
local scripts =
@@ -96,9 +92,7 @@ function _uninstall_target(target)
end
-- leave the environments of the target packages
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
- end
+ os.setenvs(oldenvs)
-- leave project directory
os.cd(oldir)
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index accc6c7dd..e26ac9956 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -191,6 +191,13 @@ function os._sched_chdir_set(chdir)
os._SCHED_CHDIR = chdir
end
+-- notify envs have been changed
+function os._notify_envs_changed(envs)
+ if os._SCHED_CHENVS then
+ os._SCHED_CHENVS(envs)
+ end
+end
+
-- the current host is belong to the given hosts?
function os._is_host(host, ...)
@@ -1012,11 +1019,11 @@ end
-- set all current environment variables
-- e.g. envs["PATH"] = "/xxx:/yyy/foo"
function os.setenvs(envs)
+ local oldenvs = os.getenvs()
if envs then
local changed = false
-- remove new added values
- local curenvs = os.getenvs()
- for name, _ in pairs(curenvs) do
+ for name, _ in pairs(oldenvs) do
if not envs[name] then
if os._setenv(name, "") then
changed = true
@@ -1025,41 +1032,42 @@ function os.setenvs(envs)
end
-- change values
for name, values in pairs(envs) do
- if curenvs[name] ~= values then
+ if oldenvs[name] ~= values then
if os._setenv(name, values) then
changed = true
end
end
end
- -- update envs for scheduler
- if changed and os._SCHED_CHENVS then
- os._SCHED_CHENVS(envs)
+ if changed then
+ os._notify_envs_changed(envs)
end
end
+ return oldenvs
end
-- add environment variables
-- e.g. envs["PATH"] = "/xxx:/yyy/foo"
function os.addenvs(envs)
+ local oldenvs = os.getenvs()
if envs then
local changed = false
for name, values in pairs(envs) do
local ok
- local oldenv = os.getenv(name)
+ local oldenv = oldenvs[name]
if oldenv == "" or oldenv == nil then
ok = os._setenv(name, values)
- else
+ elseif not oldenv:startswith(values) then
ok = os._setenv(name, values .. path.envsep() .. oldenv)
end
if ok then
changed = true
end
end
- -- update envs for scheduler
- if changed and os._SCHED_CHENVS then
- os._SCHED_CHENVS()
+ if changed then
+ os._notify_envs_changed()
end
end
+ return oldenvs
end
-- set values to environment variable
@@ -1072,9 +1080,8 @@ function os.setenv(name, ...)
else
ok = os._setenv(name, path.joinenv(values))
end
- -- update envs for scheduler
- if ok and os._SCHED_CHENVS then
- os._SCHED_CHENVS()
+ if ok then
+ os._notify_envs_changed()
end
return ok
end
@@ -1084,16 +1091,24 @@ function os.addenv(name, ...)
local values = {...}
if #values > 0 then
local ok
+ local changed = false
local oldenv = os.getenv(name)
local appendenv = path.joinenv(values)
if oldenv == "" or oldenv == nil then
ok = os._setenv(name, appendenv)
- else
+ if ok then
+ changed = true
+ end
+ elseif not oldenv:startswith(appendenv) then
ok = os._setenv(name, appendenv .. path.envsep() .. oldenv)
+ if ok then
+ changed = true
+ end
+ else
+ ok = true
end
- -- update envs for scheduler
- if ok and os._SCHED_CHENVS then
- os._SCHED_CHENVS()
+ if changed then
+ os._notify_envs_changed()
end
return ok
else
@@ -1105,9 +1120,8 @@ end
function os.setenvp(name, values, sep)
sep = sep or path.envsep()
local ok = os._setenv(name, table.concat(table.wrap(values), sep))
- -- update envs for scheduler
- if ok and os._SCHED_CHENVS then
- os._SCHED_CHENVS()
+ if ok then
+ os._notify_envs_changed()
end
return ok
end
@@ -1118,16 +1132,24 @@ function os.addenvp(name, values, sep)
values = table.wrap(values)
if #values > 0 then
local ok
+ local changed = false
local oldenv = os.getenv(name)
local appendenv = table.concat(values, sep)
if oldenv == "" or oldenv == nil then
ok = os._setenv(name, appendenv)
- else
+ if ok then
+ changed = true
+ end
+ elseif not oldenv:startswith(appendenv) then
ok = os._setenv(name, appendenv .. sep .. oldenv)
+ if ok then
+ changed = true
+ end
+ else
+ ok = true
end
- -- update envs for scheduler
- if ok and os._SCHED_CHENVS then
- os._SCHED_CHENVS()
+ if changed then
+ os._notify_envs_changed()
end
return ok
else
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index bfdde4b83..c33b5c7f0 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -87,6 +87,16 @@ function _coroutine:is_suspended()
return self:status() == "suspended"
end
+-- is isolated?
+function _coroutine:is_isolated()
+ return self._ISOLATED
+end
+
+-- isolate coroutine environments
+function _coroutine:isolate(isolate)
+ self._ISOLATED = isolate
+end
+
-- get the current timer task
function _coroutine:_timer_task()
return self._TIMER_TASK
@@ -238,26 +248,35 @@ end
-- update the current directory hash of current coroutine
function scheduler:_co_curdir_update(curdir)
+ -- get running coroutine
+ local running = self:co_running()
+ if not running then
+ return
+ end
+
-- save the current directory hash
curdir = curdir or os.curdir()
local curdir_hash = hash.uuid4(path.absolute(curdir)):sub(1, 8)
self._CO_CURDIR_HASH = curdir_hash
-- save the current directory for each coroutine
- local running = self:co_running()
- if running then
- local co_curdirs = self._CO_CURDIRS
- if not co_curdirs then
- co_curdirs = {}
- self._CO_CURDIRS = co_curdirs
- end
- co_curdirs[running] = {curdir_hash, curdir}
+ local co_curdirs = self._CO_CURDIRS
+ if not co_curdirs then
+ co_curdirs = {}
+ self._CO_CURDIRS = co_curdirs
end
+ co_curdirs[running] = {curdir_hash, curdir}
end
-- update the current environments hash of current coroutine
function scheduler:_co_curenvs_update(envs)
+ -- get running coroutine
+ local running = self:co_running()
+ if not running or not running:is_isolated() then
+ return
+ end
+
-- save the current directory hash
local envs_hash = ""
envs = envs or os.getenvs()
@@ -268,15 +287,12 @@ function scheduler:_co_curenvs_update(envs)
self._CO_CURENVS_HASH = envs_hash
-- save the current directory for each coroutine
- local running = self:co_running()
- if running then
- local co_curenvs = self._CO_CURENVS
- if not co_curenvs then
- co_curenvs = {}
- self._CO_CURENVS = co_curenvs
- end
- co_curenvs[running] = {envs_hash, envs}
+ local co_curenvs = self._CO_CURENVS
+ if not co_curenvs then
+ co_curenvs = {}
+ self._CO_CURENVS = co_curenvs
end
+ co_curenvs[running] = {envs_hash, envs}
end
-- resume it's waiting coroutine if all coroutines are dead in group
@@ -328,8 +344,15 @@ end
-- start a new named coroutine task
function scheduler:co_start_named(coname, cotask, ...)
+ return self:co_start_withopt({name = coname}, cotask, ...)
+end
+
+-- start a new coroutine task with options
+function scheduler:co_start_withopt(opt, cotask, ...)
-- check coroutine task
+ opt = opt or {}
+ local coname = opt.name
if not cotask then
return nil, string.format("cannot start coroutine, invalid cotask(%s/%s)", coname and coname or "anonymous", cotask)
end
@@ -345,6 +368,9 @@ function scheduler:co_start_named(coname, cotask, ...)
self._CO_COUNT = self:co_count() - 1
end
end))
+ if opt.isolate then
+ co:isolate(true)
+ end
self:co_tasks()[co:thread()] = co
self._CO_COUNT = self:co_count() + 1
if self._STARTED then
@@ -389,7 +415,7 @@ function scheduler:co_suspend(...)
-- if the current environments has been changed? restore it
local curenvs = self._CO_CURENVS_HASH
local oldenvs = self._CO_CURENVS and self._CO_CURENVS[running] or nil
- if oldenvs and curenvs ~= oldenvs[1] then -- hash changed?
+ if oldenvs and curenvs ~= oldenvs[1] and running:is_isolated() then -- hash changed?
os.setenvs(oldenvs[2])
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index f4bf69efb..4e1f2c5eb 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -140,10 +140,7 @@ end
function _instance:_load_after()
-- enter the environments of the target packages
- local oldenvs = os.getenvs()
- for name, values in pairs(self:pkgenvs()) do
- os.addenv(name, unpack(values))
- end
+ local oldenvs = os.addenvs(self:pkgenvs())
-- do after_load with target rules
local ok, errors = self:_load_rules("after")
@@ -783,23 +780,29 @@ end
-- get the environments of packages
function _instance:pkgenvs()
local pkgenvs = self._PKGENVS
- if not pkgenvs then
- pkgenvs = {}
- self._PKGENVS = pkgenvs
+ if pkgenvs == nil then
for _, pkgname in ipairs(table.wrap(self:get("packages"))) do
local pkg = self:pkg(pkgname)
if pkg then
local envs = pkg:get("envs")
if envs then
for name, values in pairs(envs) do
- pkgenvs[name] = pkgenvs[name] or {}
- table.join2(pkgenvs[name], values)
+ if type(values) == "table" then
+ values = path.joinenv(values)
+ end
+ pkgenvs = pkgenvs or {}
+ if pkgenvs[name] then
+ pkgenvs[name] = pkgenvs[name] .. path.envsep() .. values
+ else
+ pkgenvs[name] = values
+ end
end
end
end
end
+ self._PKGENVS = pkgenvs or false
end
- return pkgenvs
+ return pkgenvs or nil
end
-- get the config info of the given package
diff --git a/xmake/core/sandbox/modules/import/core/base/scheduler.lua b/xmake/core/sandbox/modules/import/core/base/scheduler.lua
index d0fff1504..50832d88c 100644
--- a/xmake/core/sandbox/modules/import/core/base/scheduler.lua
+++ b/xmake/core/sandbox/modules/import/core/base/scheduler.lua
@@ -49,6 +49,15 @@ function sandbox_core_base_scheduler.co_start_named(coname, cotask, ...)
return co
end
+-- start a new coroutine task with options
+function sandbox_core_base_scheduler.co_start_withopt(opt, cotask, ...)
+ local co, errors = scheduler:co_start_withopt(opt, cotask, ...)
+ if not co then
+ raise(errors)
+ end
+ return co
+end
+
-- resume the given coroutine
function sandbox_core_base_scheduler.co_resume(co, ...)
return scheduler:resume(co:thread(), ...)
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index 7a4e3620f..50397cda4 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -114,6 +114,6 @@ function main(target, batchjobs, sourcebatch, opt)
batchjobs:addjob(sourcefile, function (index, total)
local build_opt = table.join({objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = (index * 100) / total}, opt)
_build_object(target, sourcefile, build_opt)
- end, rootjob)
+ end, {rootjob = rootjob})
end
end
diff --git a/xmake/modules/private/action/require/check.lua b/xmake/modules/private/action/require/check.lua
index 9b20b1310..6b37eeb8b 100644
--- a/xmake/modules/private/action/require/check.lua
+++ b/xmake/modules/private/action/require/check.lua
@@ -48,7 +48,7 @@ function main(requires_raw)
instance:fetch()
os.setenvs(oldenvs)
end
- end, {total = #packages})
+ end, {total = #packages, isolate = true})
-- register all required root packages to local cache
register_packages(packages)
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua
index 2b482b0e9..0adea1fc9 100644
--- a/xmake/modules/private/action/require/impl/install_packages.lua
+++ b/xmake/modules/private/action/require/impl/install_packages.lua
@@ -238,7 +238,10 @@ function _install_packages(packages_install, packages_download, installdeps)
packages_installing[index] = nil
packages_downloading[index] = nil
- end, {total = #packages_install, comax = (option.get("verbose") or option.get("diagnosis")) and 1 or 4, on_timer = function (running_jobs_indices)
+ end, {total = #packages_install,
+ comax = (option.get("verbose") or option.get("diagnosis")) and 1 or 4,
+ isolate = true,
+ on_timer = function (running_jobs_indices)
-- do not print progress info if be verbose
if option.get("verbose") or not show_wait then
@@ -385,7 +388,7 @@ function main(requires, opt)
instance:fetch()
os.setenvs(oldenvs)
end
- end, {total = #packages})
+ end, {total = #packages, isolate = true})
-- register all required root packages to local cache
register_packages(packages)
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 8b29a83d7..598acd251 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -22,7 +22,6 @@
import("core.base.semver")
import("core.base.option")
import("core.base.global")
-import("private.async.runjobs")
import("private.utils.progress")
import("core.cache.memcache")
import("core.project.project")
diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua
index eb7d5ffc1..299700534 100644
--- a/xmake/modules/private/async/jobpool.lua
+++ b/xmake/modules/private/async/jobpool.lua
@@ -39,10 +39,11 @@ end
--
-- @param name the job name
-- @param run the run command/script
--- @param rootjob the root job node (optional)
+-- @param opt the options (rootjob)
--
-function jobpool:addjob(name, run, rootjob)
- return self:add({name = name, run = run}, rootjob)
+function jobpool:addjob(name, run, opt)
+ opt = opt or {}
+ return self:add({name = name, run = run}, opt.rootjob)
end
-- add job to the given job node
diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua
index 307adfa55..6a2964a90 100644
--- a/xmake/modules/private/async/runjobs.lua
+++ b/xmake/modules/private/async/runjobs.lua
@@ -46,7 +46,7 @@ end
-- for i = 1, 3 do
-- local job = jobs:addjob("job/" .. i, function (idx, total)
-- print(idx, total)
--- end, root)
+-- end, {rootjob = root})
-- end
-- runjobs("test", jobs, {comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end})
--
@@ -77,7 +77,7 @@ function main(name, jobs, opt)
local stop = false
local running_jobs_indices = {}
if opt.on_timer then
- scheduler.co_start_named(name .. "/timer", function ()
+ scheduler.co_start_withopt({name = name .. "/timer", isolate = opt.isolate}, function ()
while not stop do
os.sleep(timeout)
if not stop then
@@ -90,7 +90,7 @@ function main(name, jobs, opt)
end
end)
elseif showprogress then
- scheduler.co_start_named(name .. "/tips", function ()
+ scheduler.co_start_withopt({name = name .. "/tips", isolate = opt.isolate}, function ()
while not stop do
os.sleep(timeout)
if not stop then
@@ -181,7 +181,7 @@ function main(name, jobs, opt)
-- start this job
index = index + 1
- scheduler.co_start_named(name .. '/' .. jobname, function(i)
+ scheduler.co_start_withopt({name = name .. '/' .. jobname, isolate = opt.isolate}, function(i)
try
{
function()
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index 97803a115..0c96a70ad 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -180,12 +180,12 @@ function _make_targetinfo(mode, arch, target)
local addrunenvs, setrunenvs = make_runenvs(target)
for k, v in pairs(target:pkgenvs()) do
addrunenvs = addrunenvs or {}
- addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), v)
+ addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
end
for _, dep in ipairs(target:orderdeps()) do
for k, v in pairs(dep:pkgenvs()) do
addrunenvs = addrunenvs or {}
- addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), v)
+ addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
end
end
for k, v in pairs(addrunenvs) do