diff options
| author | ruki <[email protected]> | 2021-09-15 14:31:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-15 14:31:50 +0800 |
| commit | d773af81947a9f5a45912777abfbc1a5f0233f9b (patch) | |
| tree | def2ce373735522320a51be9cc8253464a26ea9f | |
| parent | 67c6212a9f7269f17f13f6bf10952c7b1c69d2c5 (diff) | |
| parent | ebe9e105b9ddb55d928c647ce0d15da9bd19c5c5 (diff) | |
Merge pull request #1672 from xmake-io/load
Improve load deps
24 files changed, 74 insertions, 89 deletions
diff --git a/tests/projects/other/build_deps/xmake.lua b/tests/projects/other/build_deps/xmake.lua index 2458ba7df..9fe31c900 100644 --- a/tests/projects/other/build_deps/xmake.lua +++ b/tests/projects/other/build_deps/xmake.lua @@ -4,7 +4,7 @@ target("dep1") set_kind("static") add_deps("dep3") add_files("src/interface.c") - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) os.rm(target:dep("dep3"):targetfile()) end) @@ -20,7 +20,7 @@ target("dep2") set_kind("static") add_deps("dep3") add_files("src/interface.c") - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) os.rm(target:dep("dep3"):targetfile()) end) @@ -36,7 +36,7 @@ target("dep3") set_kind("static") add_files("src/interface.c") add_deps("dep4", "dep5") - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) os.rm(target:dep("dep4"):targetfile()) os.rm(target:dep("dep5"):targetfile()) @@ -51,7 +51,7 @@ target("dep3") target("dep4") set_kind("static") add_files("src/interface.c") - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) end) after_link(function (target) @@ -62,7 +62,7 @@ target("dep4") target("dep5") set_kind("static") add_files("src/interface.c") - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) end) after_link(function (target) @@ -74,7 +74,7 @@ target("test1") set_kind("binary") add_deps("dep1", "dep2") add_files("src/test.c") - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) os.rm(target:dep("dep1"):targetfile()) os.rm(target:dep("dep2"):targetfile()) @@ -94,7 +94,7 @@ target("test2") set_kind("binary") add_deps("dep1") add_files("src/test.c") - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) os.rm(target:dep("dep1"):targetfile()) os.rm(target:dep("dep3"):targetfile()) @@ -120,7 +120,7 @@ target("test3") add_rules("test3") add_files("src/test.c") set_policy("build.across_targets_in_parallel", false) - on_load(function (target) + after_load(function (target) os.rm(target:targetfile()) os.rm(target:dep("dep1"):targetfile()) os.rm(target:dep("dep3"):targetfile()) diff --git a/tests/projects/other/multiplats_vs/xmake.lua b/tests/projects/other/multiplats_vs/xmake.lua index 4e61a20a1..255e2e913 100644 --- a/tests/projects/other/multiplats_vs/xmake.lua +++ b/tests/projects/other/multiplats_vs/xmake.lua @@ -1,7 +1,7 @@ add_rules("mode.debug", "mode.release") rule("vs2015_x86") - before_load(function (target) + on_load(function (target) target:set("arch", "x86") target:set("toolchains", "msvc", {vs = "2015"}) end) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 91982e64a..411845056 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -353,29 +353,6 @@ function project._load_toolchains() return toolchains end --- load target -function project._load_target(t, requires) - - -- do before_load() for target and all rules - local ok, errors = t:_load_before() - if not ok then - return false, errors - end - - -- do on_load() for target and all rules - ok, errors = t:_load() - if not ok then - return false, errors - end - - -- do after_load() for target and all rules - ok, errors = t:_load_after() - if not ok then - return false, errors - end - return true -end - -- load targets function project._load_targets() @@ -409,11 +386,6 @@ function project._load_targets() -- load and attach target deps, rules and packages for _, t in pairs(targets) do - -- load deps - t._DEPS = t._DEPS or {} - t._ORDERDEPS = t._ORDERDEPS or {} - project._load_deps(t, targets, t._DEPS, t._ORDERDEPS, {t:name()}) - -- load rules from target and language -- -- e.g. @@ -458,6 +430,18 @@ function project._load_targets() return nil, nil, string.format("unknown rule(%s) in target(%s)!", rulename, t:name()) end end + + -- we need call on_load() before building deps/rules, + -- so we can use `target:add("deps", "xxx")` to add deps in on_load + ok, errors = t:_load() + if not ok then + return nil, nil, errors + end + + -- load deps + t._DEPS = t._DEPS or {} + t._ORDERDEPS = t._ORDERDEPS or {} + project._load_deps(t, targets, t._DEPS, t._ORDERDEPS, {t:name()}) end -- sort targets for all deps @@ -467,19 +451,13 @@ function project._load_targets() project._sort_targets(targets, ordertargets, targetrefs, t) end - -- do load for each target - local ok = false + -- do after_load() for targets for _, t in ipairs(ordertargets) do - ok, errors = project._load_target(t, requires) + ok, errors = t:_load_after() if not ok then - break + return nil, nil, errors end end - - -- do load failed? - if not ok then - return nil, nil, errors - end return targets, ordertargets end @@ -558,8 +536,6 @@ function project._load_options(disable_filter) opt._ORDERDEPS = opt._ORDERDEPS or {} project._load_deps(opt, options, opt._DEPS, opt._ORDERDEPS, {opt:name()}) end - - -- ok? return options end diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index c155a813f..534bb5f8a 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -180,7 +180,6 @@ function rule.apis() , "rule.on_buildcmd_files" -- rule.before_xxx , "rule.before_run" - , "rule.before_load" , "rule.before_link" , "rule.before_build" , "rule.before_build_file" diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 0ff4222fa..8cfbf0a12 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -105,17 +105,6 @@ function _instance:_load_rules(suffix) return true end --- do before_load target and rules -function _instance:_load_before() - - -- do before_load with target rules - local ok, errors = self:_load_rules("before") - if not ok then - return false, errors - end - return true -end - -- do load target and rules function _instance:_load() @@ -133,6 +122,9 @@ function _instance:_load() return false, errors end end + + -- mark as loaded + self._LOADED = true return true end @@ -142,6 +134,15 @@ function _instance:_load_after() -- enter the environments of the target packages local oldenvs = os.addenvs(self:pkgenvs()) + -- do load for target + local after_load = self:script("load_after") + if after_load then + local ok, errors = sandbox.load(after_load, self) + if not ok then + return false, errors + end + end + -- do after_load with target rules local ok, errors = self:_load_rules("after") if not ok then @@ -608,11 +609,17 @@ end -- get target deps function _instance:deps() + if not self._LOADED then + os.raise("please call target:deps() or target:dep() in after_load()!") + end return self._DEPS end -- get target ordered deps function _instance:orderdeps() + if not self._LOADED then + os.raise("please call target:orderdeps() in after_load()!") + end return self._ORDERDEPS end @@ -2003,6 +2010,7 @@ function target.apis() , "target.before_uninstall" -- target.after_xxx , "target.after_run" + , "target.after_load" , "target.after_link" , "target.after_build" , "target.after_build_file" diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index e6e802d71..96d587e41 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -21,7 +21,7 @@ -- define rule: environment rule("cuda.env") - before_load(function (target) + on_load(function (target) -- imports import("detect.sdks.find_cuda") diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index 0845178fe..b5ebc22d1 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -34,7 +34,7 @@ rule("cuda.gencodes") -- if no available device is found, no `-gencode` flags will be added -- @seealso xmake/modules/lib/detect/find_cudadevices -- - before_load(function (target) + on_load(function (target) -- imports import("core.platform.platform") diff --git a/xmake/rules/luarocks/module/xmake.lua b/xmake/rules/luarocks/module/xmake.lua index e74080912..530e35070 100644 --- a/xmake/rules/luarocks/module/xmake.lua +++ b/xmake/rules/luarocks/module/xmake.lua @@ -19,7 +19,7 @@ -- rule("luarocks.module") - before_load(function (target) + on_load(function (target) -- imports import("core.cache.detectcache") diff --git a/xmake/rules/utils/symbols/export_all/xmake.lua b/xmake/rules/utils/symbols/export_all/xmake.lua index f804e3c3e..b808d63a9 100644 --- a/xmake/rules/utils/symbols/export_all/xmake.lua +++ b/xmake/rules/utils/symbols/export_all/xmake.lua @@ -26,7 +26,7 @@ -- @see https://github.com/xmake-io/xmake/issues/1123 -- rule("utils.symbols.export_all") - before_load(function (target) + on_load(function (target) -- @note it only supports windows/dll now assert(target:is_shared(), 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name()) if target:is_plat("windows") then diff --git a/xmake/rules/wdk/env/xmake.lua b/xmake/rules/wdk/env/xmake.lua index 6b7690933..a9089dc5e 100644 --- a/xmake/rules/wdk/env/xmake.lua +++ b/xmake/rules/wdk/env/xmake.lua @@ -22,7 +22,7 @@ rule("wdk.env") -- before load - before_load(function (target) + on_load(function (target) -- imports import("os.winver", {alias = "os_winver"}) diff --git a/xmake/rules/wdk/inf/xmake.lua b/xmake/rules/wdk/inf/xmake.lua index fe060a10a..6ad91e62d 100644 --- a/xmake/rules/wdk/inf/xmake.lua +++ b/xmake/rules/wdk/inf/xmake.lua @@ -28,7 +28,7 @@ rule("wdk.inf") set_extensions(".inf", ".inx") -- before load - before_load(function (target) + on_load(function (target) -- imports import("core.project.config") diff --git a/xmake/rules/wdk/man/xmake.lua b/xmake/rules/wdk/man/xmake.lua index 25cce9f34..7843542d7 100644 --- a/xmake/rules/wdk/man/xmake.lua +++ b/xmake/rules/wdk/man/xmake.lua @@ -28,7 +28,7 @@ rule("wdk.man") set_extensions(".man") -- before load - before_load(function (target) + on_load(function (target) -- imports import("core.project.config") diff --git a/xmake/rules/wdk/mc/xmake.lua b/xmake/rules/wdk/mc/xmake.lua index 32653dfc2..abc75fdf7 100644 --- a/xmake/rules/wdk/mc/xmake.lua +++ b/xmake/rules/wdk/mc/xmake.lua @@ -28,7 +28,7 @@ rule("wdk.mc") set_extensions(".mc") -- before load - before_load(function (target) + on_load(function (target) -- imports import("core.project.config") diff --git a/xmake/rules/wdk/mof/xmake.lua b/xmake/rules/wdk/mof/xmake.lua index 319eec5d7..8be25de20 100644 --- a/xmake/rules/wdk/mof/xmake.lua +++ b/xmake/rules/wdk/mof/xmake.lua @@ -28,7 +28,7 @@ rule("wdk.mof") set_extensions(".mof") -- before load - before_load(function (target) + on_load(function (target) -- imports import("core.project.config") diff --git a/xmake/rules/wdk/sign/xmake.lua b/xmake/rules/wdk/sign/xmake.lua index 7dcc28785..dd137c5ec 100644 --- a/xmake/rules/wdk/sign/xmake.lua +++ b/xmake/rules/wdk/sign/xmake.lua @@ -34,7 +34,7 @@ rule("wdk.sign") add_deps("wdk.env") -- before load - before_load(function (target) + on_load(function (target) -- imports import("core.project.config") diff --git a/xmake/rules/wdk/tracewpp/xmake.lua b/xmake/rules/wdk/tracewpp/xmake.lua index 0c49bf5d0..52d72827f 100644 --- a/xmake/rules/wdk/tracewpp/xmake.lua +++ b/xmake/rules/wdk/tracewpp/xmake.lua @@ -25,7 +25,7 @@ rule("wdk.tracewpp") add_deps("wdk.env") -- before load - before_load(function (target) + on_load(function (target) -- imports import("core.project.config") diff --git a/xmake/rules/winsdk/dotnet/xmake.lua b/xmake/rules/winsdk/dotnet/xmake.lua index 5274f040a..1cfef7b58 100644 --- a/xmake/rules/winsdk/dotnet/xmake.lua +++ b/xmake/rules/winsdk/dotnet/xmake.lua @@ -22,7 +22,7 @@ rule("win.sdk.dotnet") -- before load - before_load(function (target) + on_load(function (target) -- imports import("core.project.config") diff --git a/xmake/rules/winsdk/mfc/env/xmake.lua b/xmake/rules/winsdk/mfc/env/xmake.lua index f603ebfe2..f553618b5 100644 --- a/xmake/rules/winsdk/mfc/env/xmake.lua +++ b/xmake/rules/winsdk/mfc/env/xmake.lua @@ -22,5 +22,5 @@ rule("win.sdk.mfc.env") -- TODO: before load need check of vs's minverion, if defined - before_load(function (target) + on_load(function (target) end) diff --git a/xmake/rules/winsdk/xmake.lua b/xmake/rules/winsdk/xmake.lua index 0a3b105cc..297dfda75 100644 --- a/xmake/rules/winsdk/xmake.lua +++ b/xmake/rules/winsdk/xmake.lua @@ -27,7 +27,7 @@ rule("win.sdk.resource") rule("win.sdk.application") -- before load - before_load(function (target) + on_load(function (target) target:set("kind", "binary") end) diff --git a/xmake/rules/xcode/application/load.lua b/xmake/rules/xcode/application/load.lua index 3071ccd58..354aa5b0c 100644 --- a/xmake/rules/xcode/application/load.lua +++ b/xmake/rules/xcode/application/load.lua @@ -54,15 +54,4 @@ function main (target) -- register clean files for `xmake clean` target:add("cleanfiles", bundledir) - - -- depend xcode.framework? we need disable `build.across_targets_in_parallel` policy - local across_targets_in_parallel - for _, dep in ipairs(target:orderdeps()) do - if dep:rule("xcode.framework") then - across_targets_in_parallel = false - end - end - if across_targets_in_parallel ~= nil then - target:set("policy", "build.across_targets_in_parallel", across_targets_in_parallel) - end end diff --git a/xmake/rules/xcode/application/xmake.lua b/xmake/rules/xcode/application/xmake.lua index 51232f033..d328262c0 100644 --- a/xmake/rules/xcode/application/xmake.lua +++ b/xmake/rules/xcode/application/xmake.lua @@ -25,7 +25,20 @@ rule("xcode.application") add_deps("xcode.info_plist", "xcode.storyboard", "xcode.xcassets", "xcode.metal") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load("load") + on_load("load") + + -- depend xcode.framework? we need disable `build.across_targets_in_parallel` policy + after_load(function (target) + local across_targets_in_parallel + for _, dep in ipairs(target:orderdeps()) do + if dep:rule("xcode.framework") then + across_targets_in_parallel = false + end + end + if across_targets_in_parallel ~= nil then + target:set("policy", "build.across_targets_in_parallel", across_targets_in_parallel) + end + end) -- build *.app after_build("build") diff --git a/xmake/rules/xcode/bundle/xmake.lua b/xmake/rules/xcode/bundle/xmake.lua index bd8e4329e..1c1cecf99 100644 --- a/xmake/rules/xcode/bundle/xmake.lua +++ b/xmake/rules/xcode/bundle/xmake.lua @@ -25,7 +25,7 @@ rule("xcode.bundle") add_deps("xcode.info_plist") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) + on_load(function (target) -- get bundle directory local targetdir = target:targetdir() diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua index b112dcaf1..6b46b3c97 100644 --- a/xmake/rules/xcode/framework/xmake.lua +++ b/xmake/rules/xcode/framework/xmake.lua @@ -25,7 +25,7 @@ rule("xcode.framework") add_deps("xcode.info_plist") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) + on_load(function (target) -- get framework directory local targetdir = target:targetdir() diff --git a/xmake/rules/xmake_cli/xmake.lua b/xmake/rules/xmake_cli/xmake.lua index 2375c9e3b..a7e21a9e1 100644 --- a/xmake/rules/xmake_cli/xmake.lua +++ b/xmake/rules/xmake_cli/xmake.lua @@ -20,7 +20,7 @@ -- define rule: xmake cli program rule("xmake.cli") - before_load(function (target) + on_load(function (target) target:set("kind", "binary") assert(target:pkg("libxmake"), 'please add_packages("libxmake") to target(%s) first!', target:name()) end) |
