diff options
| author | ruki <[email protected]> | 2018-11-17 00:57:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-16 23:44:55 +0800 |
| commit | c58513ec6ded191db1d97e93d84569d1cdda1282 (patch) | |
| tree | 93d241a93af33183ffedd4323fbb1d8ae842050a | |
| parent | 6b6bcc5b264285b141724ef27dc0075b614cbc3e (diff) | |
improve on_build
| -rw-r--r-- | xmake/actions/build/build.lua | 19 | ||||
| -rw-r--r-- | xmake/actions/clean/main.lua | 51 | ||||
| -rw-r--r-- | xmake/actions/install/install.lua | 43 | ||||
| -rw-r--r-- | xmake/actions/package/main.lua | 42 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 45 | ||||
| -rw-r--r-- | xmake/actions/uninstall/uninstall.lua | 43 |
6 files changed, 141 insertions, 102 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index be9559128..47be3f485 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -36,6 +36,15 @@ function _clean_target(target) end end +-- do build the given target +function _do_build_target(target) + + -- build target + if not target:isphony() then + import("kinds." .. target:targetkind()).build(target, _g) + end +end + -- on build the given target function _on_build_target(target) @@ -49,16 +58,14 @@ function _on_build_target(target) for _, r in ipairs(target:orderules()) do local on_build = r:script("build") if on_build then - on_build(target) + on_build(target, _do_build_target) done = true end end if done then return end - -- build target - if not target:isphony() then - import("kinds." .. target:targetkind()).build(target, _g) - end + -- do build + _do_build_target(target) end -- build the given target @@ -127,7 +134,7 @@ function _build_target(target) for i = 1, 3 do local script = scripts[i] if script ~= nil then - script(target) + script(target, i == 2 and _do_build_target or nil) end end diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index 33451acdd..906cd9fce 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -49,29 +49,8 @@ function _remove(filedirs) end end --- on clean target -function _on_clean_target(target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- build target with rules - local done = false - for _, r in ipairs(target:orderules()) do - local on_clean = r:script("clean") - if on_clean then - on_clean(target) - done = true - end - end - if done then return end - - -- is phony target? - if target:isphony() then - return - end +-- do clean target +function _do_clean_target(target) -- remove the target file _remove(target:targetfile()) @@ -104,6 +83,29 @@ function _on_clean_target(target) end end +-- on clean target +function _on_clean_target(target) + + -- has been disabled? + if target:get("enabled") == false then + return + end + + -- build target with rules + local done = false + for _, r in ipairs(target:orderules()) do + local on_clean = r:script("clean") + if on_clean then + on_clean(target, _do_clean_target) + done = true + end + end + if done then return end + + -- do clean + _do_clean_target(target) +end + -- clean the given target files function _clean_target(target) @@ -149,10 +151,9 @@ function _clean_target(target) for i = 1, 5 do local script = scripts[i] if script ~= nil then - script(target) + script(target, i == 3 and _do_clean_target or nil) end end - end -- clean the given target and all dependent targets diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index 226b4076f..be775597e 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -82,8 +82,26 @@ function _install_library(target) end end --- on install -function _on_install(target) +-- do install target +function _do_install_target(target) + + -- the scripts + local scripts = + { + binary = _install_binary + , static = _install_library + , shared = _install_library + } + + -- call script + local script = scripts[target:get("kind")] + if script then + script(target) + end +end + +-- on install target +function _on_install_target(target) -- has been disabled? if target:get("enabled") == false then @@ -95,25 +113,14 @@ function _on_install(target) for _, r in ipairs(target:orderules()) do local on_install = r:script("install") if on_install then - on_install(target) + on_install(target, _do_install_target) done = true end end if done then return end - -- the scripts - local scripts = - { - binary = _install_binary - , static = _install_library - , shared = _install_library - } - - -- call script - local script = scripts[target:get("kind")] - if script then - script(target) - end + -- do install + _do_install_target(target) end -- install the given target @@ -141,7 +148,7 @@ function _install_target(target) end end end - , target:script("install", _on_install) + , target:script("install", _on_install_target) , function (target) -- has been disabled? @@ -164,7 +171,7 @@ function _install_target(target) for i = 1, 5 do local script = scripts[i] if script ~= nil then - script(target) + script(target, i == 3 and _do_install_target or nil) end end diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua index f8c63c7ed..0c6171dd6 100644 --- a/xmake/actions/package/main.lua +++ b/xmake/actions/package/main.lua @@ -113,19 +113,8 @@ option("[targetname]") end end --- package target -function _on_package(target) - - -- build target with rules - local done = false - for _, r in ipairs(target:orderules()) do - local on_package = r:script("package") - if on_package then - on_package(target) - done = true - end - end - if done then return end +-- do package target +function _do_package_target(target) -- is phony target? if target:isphony() then @@ -150,6 +139,29 @@ function _on_package(target) scripts[kind](target) end +-- package target +function _on_package_target(target) + + -- has been disabled? + if target:get("enabled") == false then + return + end + + -- build target with rules + local done = false + for _, r in ipairs(target:orderules()) do + local on_package = r:script("package") + if on_package then + on_package(target, _do_package_target) + done = true + end + end + if done then return end + + -- do package + _do_package_target(target) +end + -- package the given target function _package(target) @@ -168,7 +180,7 @@ function _package(target) end end end - , target:script("package", _on_package) + , target:script("package", _on_package_target) , function (target) for _, r in ipairs(target:orderules()) do local after_package = r:script("package_after") @@ -184,7 +196,7 @@ function _package(target) for i = 1, 5 do local script = scripts[i] if script ~= nil then - script(target) + script(target, i == 3 and _do_package_target or nil) end end diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index d2f72acd2..bfd9e414b 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -33,25 +33,7 @@ import("core.platform.environment") import("devel.debugger") -- run target -function _on_run_target(target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- build target with rules - local done = false - for _, r in ipairs(target:orderules()) do - local on_run = r:script("run") - if on_run then - on_run(target) - done = true - end - end - if done then return end - - -- get kind +function _do_run_target(target) if target:targetkind() == "binary" then -- get the absolute target file path @@ -95,6 +77,29 @@ function _on_run_target(target) end end +-- run target +function _on_run_target(target) + + -- has been disabled? + if target:get("enabled") == false then + return + end + + -- build target with rules + local done = false + for _, r in ipairs(target:orderules()) do + local on_run = r:script("run") + if on_run then + on_run(target, _do_run_target) + done = true + end + end + if done then return end + + -- do run + _do_run_target(target) +end + -- run the given target function _run(target) @@ -140,7 +145,7 @@ function _run(target) for i = 1, 5 do local script = scripts[i] if script ~= nil then - script(target) + script(target, i == 3 and _do_run_target or nil) end end end diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua index 818136414..c2475ce43 100644 --- a/xmake/actions/uninstall/uninstall.lua +++ b/xmake/actions/uninstall/uninstall.lua @@ -66,8 +66,26 @@ function _uninstall_library(target) end end --- uninstall target -function _on_uninstall(target) +-- do uninstall target +function _do_uninstall_target(target) + + -- the scripts + local scripts = + { + binary = _uninstall_binary + , static = _uninstall_library + , shared = _uninstall_library + } + + -- call script + local script = scripts[target:get("kind")] + if script then + script(target) + end +end + +-- on uninstall target +function _on_uninstall_target(target) -- has been disabled? if target:get("enabled") == false then @@ -79,25 +97,14 @@ function _on_uninstall(target) for _, r in ipairs(target:orderules()) do local on_uninstall = r:script("uninstall") if on_uninstall then - on_uninstall(target) + on_uninstall(target, _do_uninstall_target) done = true end end if done then return end - -- the scripts - local scripts = - { - binary = _uninstall_binary - , static = _uninstall_library - , shared = _uninstall_library - } - - -- call script - local script = scripts[target:get("kind")] - if script then - script(target) - end + -- do uninstall + _do_uninstall_target(target) end -- uninstall the given target @@ -125,7 +132,7 @@ function _uninstall_target(target) end end end - , target:script("uninstall", _on_uninstall) + , target:script("uninstall", _on_uninstall_target) , function (target) -- has been disabled? @@ -148,7 +155,7 @@ function _uninstall_target(target) for i = 1, 5 do local script = scripts[i] if script ~= nil then - script(target) + script(target, i == 3 and _do_uninstall_target or nil) end end |
