diff options
| author | ruki <[email protected]> | 2017-04-01 00:07:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-04-01 00:07:03 +0800 |
| commit | 5828c83b8da6c92d0b387d83d94c8abac2dbeb03 (patch) | |
| tree | 283322f602f54b22aea72ab28032b610ff378cd9 | |
| parent | d819b361e585103bfc1fd95db8e0bdd322f59f71 (diff) | |
add set_default api for target
| -rw-r--r-- | xmake/actions/build/builder.lua | 36 | ||||
| -rw-r--r-- | xmake/actions/build/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/build/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/clean/main.lua | 12 | ||||
| -rw-r--r-- | xmake/actions/clean/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/config/configheader.lua | 3 | ||||
| -rw-r--r-- | xmake/actions/config/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/install/install.lua | 14 | ||||
| -rw-r--r-- | xmake/actions/install/install_admin.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/install/main.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/install/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/package/main.lua | 14 | ||||
| -rw-r--r-- | xmake/actions/package/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 19 | ||||
| -rw-r--r-- | xmake/actions/uninstall/main.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/uninstall/uninstall.lua | 9 | ||||
| -rw-r--r-- | xmake/actions/uninstall/uninstall_admin.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/uninstall/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 1 |
19 files changed, 71 insertions, 69 deletions
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua index 347ccd9d1..3053c1fda 100644 --- a/xmake/actions/build/builder.lua +++ b/xmake/actions/build/builder.lua @@ -109,17 +109,17 @@ function _stat_target_count(targetname) -- init targets count _g.targetcount = 0 - -- for all? - if targetname == "all" then - - -- make all targets + -- for the given target? + if targetname then + _stat_target_count_and_deps(project.target(targetname)) + else + -- for default or all targets for _, target in pairs(project.targets()) do - _stat_target_count_and_deps(target) + local default = target:get("default") + if default == nil or default == true then + _stat_target_count_and_deps(target) + end end - else - - -- make target - _stat_target_count_and_deps(project.target(targetname)) end end @@ -138,17 +138,17 @@ function build(targetname) -- init target index _g.targetindex = 0 - -- for all? - if targetname == "all" then - - -- make all targets + -- build the given target? + if targetname then + _build_target_and_deps(project.target(targetname)) + else + -- build default or all targets for _, target in pairs(project.targets()) do - _build_target_and_deps(target) + local default = target:get("default") + if default == nil or default == true then + _build_target_and_deps(target) + end end - else - - -- make target - _build_target_and_deps(project.target(targetname)) end -- leave toolchains environment diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index e0edbc37a..1d5b3b8ba 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -70,7 +70,7 @@ function main() function () -- build - builder.build(targetname or "all") + builder.build(targetname) end, @@ -81,8 +81,10 @@ function main() -- failed if errors then raise(errors) - else + elseif targetname then raise("build target: %s failed!", targetname) + else + raise("build target failed!") end end } diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua index 79e6cee4f..1451249f6 100644 --- a/xmake/actions/build/xmake.lua +++ b/xmake/actions/build/xmake.lua @@ -37,7 +37,7 @@ task("build") usage = "xmake [task] [options] [target]" -- description - , description = "Build the project if no given tasks." + , description = "Build targets if no given tasks." -- options , options = @@ -46,10 +46,10 @@ task("build") , {'r', "rebuild", "k", nil, "Rebuild the project." } , {} - , {'j', "jobs", "kv", "4", "Specifies the number of jobs to build simultaneously" } + , {'j', "jobs", "kv", "4", "Specifies the number of jobs to build simultaneously." } , {} - , {nil, "target", "v", "all", "Build the given target." } + , {nil, "target", "v", nil, "Build the given target." } } } diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index 1950002a8..eb5f85cab 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -119,18 +119,14 @@ function _clean_target_and_deps(target) _g.finished[target:name()] = true end --- clean the given target +-- clean target function _clean(targetname) - -- the target name - if targetname and targetname ~= "all" then - - -- clean target + -- clean the given target + if targetname then _clean_target_and_deps(project.target(targetname)) - else - - -- clean targets + -- clean all targets for _, target in pairs(project.targets()) do _clean_target_and_deps(target) end diff --git a/xmake/actions/clean/xmake.lua b/xmake/actions/clean/xmake.lua index e716a676f..72e4e2058 100644 --- a/xmake/actions/clean/xmake.lua +++ b/xmake/actions/clean/xmake.lua @@ -48,7 +48,7 @@ task("clean") {'a', "all", "k", nil, "Clean all auto-generated files by xmake." } , {} - , {nil, "target", "v", "all", "Clean for the given target." } + , {nil, "target", "v", nil, "Clean for the given target." } } } diff --git a/xmake/actions/config/configheader.lua b/xmake/actions/config/configheader.lua index ec3a9e5ca..cc58c2943 100644 --- a/xmake/actions/config/configheader.lua +++ b/xmake/actions/config/configheader.lua @@ -137,10 +137,9 @@ function make() local files = {} -- make configure for the given target name - if targetname and targetname ~= "all" then + if targetname then _make_for_target_with_deps(files, targetname) else - -- make configure for all targets for _, target in pairs(project.targets()) do _make_for_target(files, target) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 3effd29bb..f452edda7 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -148,7 +148,7 @@ task("config") , {'o', "buildir", "kv", "build", "Set the build directory." } , {} - , {nil, "target", "v", "all", "Configure for the given target." } + , {nil, "target", "v", nil, "Configure for the given target." } } } diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index e3080e5ce..720e300b6 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -79,12 +79,16 @@ function install(targetname) -- init finished states _g.finished = {} - -- install all? - if targetname == "all" then + -- install the given target? + if targetname then + _install_target_and_deps(project.target(targetname)) + else + -- install default or all targets for _, target in pairs(project.targets()) do - _install_target_and_deps(target) + local default = target:get("default") + if default == nil or default == true then + _install_target_and_deps(target) + end end - else - _install_target_and_deps(project.target(targetname)) end end diff --git a/xmake/actions/install/install_admin.lua b/xmake/actions/install/install_admin.lua index 386911027..60a4ba9c0 100644 --- a/xmake/actions/install/install_admin.lua +++ b/xmake/actions/install/install_admin.lua @@ -53,7 +53,7 @@ function main(targetname, installdir) end -- install target - install.install(targetname) + install.install(ifelse(targetname ~= "__all", targetname, nil)) -- restore the previous option context option.restore() diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua index 2b4a4663b..150f90659 100644 --- a/xmake/actions/install/main.lua +++ b/xmake/actions/install/main.lua @@ -73,7 +73,7 @@ function main() if answer == 'y' or answer == '' then -- install target with administrator permission - os.sudol(os.runv, path.join(os.scriptdir(), "install_admin.lua"), {targetname, option.get("installdir")}) + os.sudol(os.runv, path.join(os.scriptdir(), "install_admin.lua"), {targetname or "__all", option.get("installdir")}) -- trace cprint("${bright}install ok!${clear}${ok_hand}") diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua index 9f386a26f..f561fcba7 100644 --- a/xmake/actions/install/xmake.lua +++ b/xmake/actions/install/xmake.lua @@ -37,7 +37,7 @@ task("install") usage = "xmake install|i [options] [target]" -- description - , description = "Package and install the project binary files." + , description = "Package and install the target binary files." -- xmake i , shortname = 'i' @@ -48,7 +48,7 @@ task("install") {'o', "installdir", "kv", nil, "Set the install directory." } , {} - , {nil, "target", "v", "all", "Install the given target." } + , {nil, "target", "v", nil, "Install the given target." } } } diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua index 0597eeb6e..7f931651b 100644 --- a/xmake/actions/package/main.lua +++ b/xmake/actions/package/main.lua @@ -201,12 +201,16 @@ function main() -- init finished states _g.finished = {} - -- package all? - if targetname == "all" then + -- package the given target? + if targetname then + _package_target_and_deps(project.target(targetname)) + else + -- package default or all targets for _, target in pairs(project.targets()) do - _package_target_and_deps(target) + local default = target:get("default") + if default == nil or default == true then + _package_target_and_deps(target) + end end - else - _package_target_and_deps(project.target(targetname)) end end diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index 2a45dffda..60f7b8eb9 100644 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -48,7 +48,7 @@ task("package") {'o', "outputdir", "kv", nil, "Set the output directory." } , {'a', "archs", "kv", nil, "Compile for the given architecture. (deprecated)" } , {} - , {nil, "target", "v", "all", "Package a given target" } + , {nil, "target", "v", nil, "Package a given target" } } } diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 15a0cb1fe..57778985e 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -97,23 +97,18 @@ function main() -- enter project directory local olddir = os.cd(project.directory()) - -- get target - local target = nil + -- run the given target? if targetname then - target = project.target(targetname) + _run(project.target(targetname)) else - -- find the first binary target - for _, t in pairs(project.targets()) do - if t:get("kind") == "binary" then - target = t - break + -- run default or all binary targets + for _, target in pairs(project.targets()) do + local default = target:get("default") + if (default == nil or default == true) and target:get("kind") == "binary" then + _run(target) end end end - assert(target, "target(%s) not found!", targetname or "unknown") - - -- run the given target - _run(target) -- leave project directory os.cd(olddir) diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua index 9063fbda2..a7cfec3db 100644 --- a/xmake/actions/uninstall/main.lua +++ b/xmake/actions/uninstall/main.lua @@ -73,7 +73,7 @@ function main() if answer == 'y' or answer == '' then -- uninstall target with administrator permission - os.sudol(os.runv, path.join(os.scriptdir(), "uninstall_admin.lua"), {targetname, option.get("installdir")}) + os.sudol(os.runv, path.join(os.scriptdir(), "uninstall_admin.lua"), {targetname or "__all", option.get("installdir")}) -- trace cprint("${bright}uninstall ok!${clear}${ok_hand}") diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua index b89aa2440..6ab3d6cc1 100644 --- a/xmake/actions/uninstall/uninstall.lua +++ b/xmake/actions/uninstall/uninstall.lua @@ -79,12 +79,13 @@ function uninstall(targetname) -- init finished states _g.finished = {} - -- uninstall all? - if targetname == "all" then + -- uninstall given target? + if targetname then + _uninstall_target_and_deps(project.target(targetname)) + else + -- uninstall all targets for _, target in pairs(project.targets()) do _uninstall_target_and_deps(target) end - else - _uninstall_target_and_deps(project.target(targetname)) end end diff --git a/xmake/actions/uninstall/uninstall_admin.lua b/xmake/actions/uninstall/uninstall_admin.lua index a0408d38b..8dded1cce 100644 --- a/xmake/actions/uninstall/uninstall_admin.lua +++ b/xmake/actions/uninstall/uninstall_admin.lua @@ -53,7 +53,7 @@ function main(targetname, installdir) end -- uninstall target - uninstall.uninstall(targetname) + uninstall.uninstall(ifelse(targetname ~= "__all", targetname, nil)) -- restore the previous option context option.restore() diff --git a/xmake/actions/uninstall/xmake.lua b/xmake/actions/uninstall/xmake.lua index f4e5e4bd7..300f27321 100644 --- a/xmake/actions/uninstall/xmake.lua +++ b/xmake/actions/uninstall/xmake.lua @@ -48,7 +48,7 @@ task("uninstall") {nil, "installdir", "kv", nil, "Set the install directory." } , {} - , {nil, "target", "v", "all", "Uninstall the given target." } + , {nil, "target", "v", nil, "Uninstall the given target." } } } diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 6c25ed8e7..c71df25db 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -192,6 +192,7 @@ function project._interpreter() -- target.set_xxx , "target.set_kind" , "target.set_strip" + , "target.set_default" , "target.set_options" , "target.set_symbols" , "target.set_basename" |
