diff options
| author | ruki <[email protected]> | 2021-03-06 08:20:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-06 08:20:25 +0800 |
| commit | 5f3ed1310bf369c12d6fe0e3d93325f2a3f8b7f9 (patch) | |
| tree | a2b4529897a3b40fb036e93fe5d0aee68b2fece0 | |
| parent | f3f916ee0494069c42b7ad604d5ff1e968f156d8 (diff) | |
| parent | 5a7702689c2ca00d77fb922c3c03ab0c7778ffad (diff) | |
Merge pull request #1265 from xmake-io/config
improve config
38 files changed, 223 insertions, 187 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index 79e6ad40e..a8029e24c 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -54,7 +54,7 @@ function _add_batchjobs_builtin(batchjobs, rootjob, target) end -- uses the builtin target script - if not job and not target:isphony() then + if not job and not target:is_phony() then job, job_leaf = import("kinds." .. target:kind(), {anonymous = true})(batchjobs, rootjob, target) end job = job or rootjob @@ -100,7 +100,7 @@ end function _add_batchjobs_for_target(batchjobs, rootjob, target) -- has been disabled? - if target:get("enabled") == false then + if not target:is_enabled() then return end @@ -189,8 +189,7 @@ function get_batchjobs(targetname) local depset = hashset.new() local targets = {} for _, target in pairs(project.targets()) do - local default = target:get("default") - if default == nil or default == true or option.get("all") then + if target:is_default() or option.get("all") then for _, depname in ipairs(target:get("deps")) do depset:insert(depname) end diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua index 3d0a48e75..ca061b2c8 100644 --- a/xmake/actions/build/build_files.lua +++ b/xmake/actions/build/build_files.lua @@ -89,7 +89,7 @@ end function _add_batchjobs_for_target(batchjobs, rootjob, target, filepatterns) -- has been disabled? - if target:get("enabled") == false then + if not target:is_enabled() then return end @@ -124,8 +124,7 @@ function _get_batchjobs(targetname, filepatterns) local depset = hashset.new() local targets = {} for _, target in pairs(project.targets()) do - local default = target:get("default") - if default == nil or default == true or option.get("all") then + if target:is_default() or option.get("all") then for _, depname in ipairs(target:get("deps")) do depset:insert(depname) end diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index c72f82a6f..4dc42437a 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -51,7 +51,7 @@ end function _clean_target(target) -- has been disabled? - if target:get("enabled") == false then + if not target:is_enabled() then return end diff --git a/xmake/actions/config/configfiles.lua b/xmake/actions/config/configfiles.lua index b7bb17d25..7233ca0a4 100644 --- a/xmake/actions/config/configfiles.lua +++ b/xmake/actions/config/configfiles.lua @@ -29,7 +29,7 @@ import("core.platform.platform") function _get_configfiles() local configfiles = {} for _, target in pairs(project.targets()) do - if target:get("enabled") ~= false then + if target:is_enabled() then -- get configuration files for target local srcfiles, dstfiles, fileinfos = target:configfiles() diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index be96692a3..4a8cfc2ed 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -100,38 +100,27 @@ function _need_check(changed) return changed end --- check dependent target -function _check_target_deps(target) - - -- check +-- check target +function _check_target(target) for _, depname in ipairs(target:get("deps")) do - - -- check dependent target name assert(depname ~= target:name(), "the target(%s) cannot depend self!", depname) - - -- get dependent target local deptarget = project.target(depname) - - -- check dependent target name assert(deptarget, "unknown target(%s) for %s.deps!", depname, target:name()) - - -- check the dependent targets - _check_target_deps(deptarget) + _check_target(deptarget) end end --- check target -function _check_target(targetname) - assert(targetname) +-- check targets +function _check_targets(targetname) assert(not project.is_loaded(), "project and targets may have been loaded early!") if targetname == "all" then for _, target in pairs(project.targets()) do - _check_target_deps(target) + _check_target(target) end else local target = project.target(targetname) assert(target, "unknown target: %s", targetname) - _check_target_deps(target) + _check_target(target) end end @@ -140,9 +129,9 @@ function _check_target_toolchains() -- check toolchains configuration for all target in the current project -- @note we must check targets after loading options for _, target in pairs(project.targets()) do - if target:get("enabled") ~= false and (target:get("toolchains") or - not target:is_plat(config.get("plat")) or - not target:is_arch(config.get("arch"))) then + if target:is_enabled() and (target:get("toolchains") or + not target:is_plat(config.get("plat")) or + not target:is_arch(config.get("arch"))) then local target_toolchains = target:get("toolchains") if target_toolchains then target_toolchains = hashset.from(table.wrap(target_toolchains)) @@ -163,6 +152,38 @@ function _check_target_toolchains() end end +-- config target +function _config_target(target) + for _, rule in ipairs(target:orderules()) do + local on_config = rule:script("config") + if on_config then + on_config(target) + end + end + local on_config = target:script("config") + if on_config then + on_config(target) + end +end + +-- config targets +function _config_targets(targetname) + if targetname == "all" then + for _, target in ipairs(project.ordertargets()) do + if target:is_enabled() then + _config_target(target) + end + end + else + local target = project.target(targetname) + assert(target, "unknown target: %s", targetname) + for _, dep in ipairs(target:orderdeps()) do + _config_target(dep) + end + _config_target(target) + end +end + -- main entry function main(opt) @@ -311,7 +332,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- check target and ensure to load all targets, @note we must load targets after installing required packages, -- otherwise has_package() will be invalid. - _check_target(targetname) + _check_targets(targetname) -- update the config files if recheck then @@ -325,6 +346,9 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end + -- config targets + _config_targets(targetname) + -- dump config if option.get("verbose") and not opt.disable_dump then config.dump() diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index 1f990a1b9..1a71bda40 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -49,7 +49,7 @@ end function _install_target(target) -- has been disabled? - if target:get("enabled") == false then + if not target:is_enabled() then return end @@ -122,8 +122,7 @@ function main(targetname) else -- install default or all targets for _, target in ipairs(project.ordertargets()) do - local default = target:get("default") - if default == nil or default == true or targetname == "__all" then + if target:is_default() or targetname == "__all" then _install_target(target) end end diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua index 62bd9210b..7d61ecaa4 100644 --- a/xmake/actions/install/main.lua +++ b/xmake/actions/install/main.lua @@ -37,8 +37,7 @@ function _check_targets(targetname) else -- install default or all targets for _, target in pairs(project.targets()) do - local default = target:get("default") - if default == nil or default == true or targetname == "__all" then + if target:is_default() or targetname == "__all" then table.insert(targets, target) end end @@ -47,7 +46,7 @@ function _check_targets(targetname) -- filter and check targets with builtin-install script local targetnames = {} for _, target in ipairs(targets) do - if not target:isphony() and target:get("enabled") ~= false and not target:script("install") then + if not target:is_phony() and target:is_enabled() and not target:script("install") then local targetfile = target:targetfile() if targetfile and not os.isfile(targetfile) then table.insert(targetnames, target:name()) diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua index 6f93562bc..39078392b 100644 --- a/xmake/actions/package/main.lua +++ b/xmake/actions/package/main.lua @@ -95,7 +95,7 @@ end function _do_package_target(target) -- is phony target? - if target:isphony() then + if target:is_phony() then return end @@ -120,11 +120,6 @@ 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 @@ -143,6 +138,11 @@ end -- package the given target function _package_target(target) + -- has been disabled? + if not target:is_enabled() then + return + end + -- enter project directory local oldir = os.cd(project.directory()) @@ -231,8 +231,7 @@ function main() else -- package default or all targets for _, target in ipairs(project.ordertargets()) do - local default = target:get("default") - if default == nil or default == true or option.get("all") then + if target:is_default() or option.get("all") then _package_target(target) end end diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 0974b2f68..04b0d76d4 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -32,7 +32,7 @@ import("private.action.run.make_runenvs") function _do_run_target(target) -- only for binary program - if target:kind() ~= "binary" then + if not target:is_binary() then return end @@ -68,11 +68,6 @@ 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 @@ -108,6 +103,11 @@ end -- run the given target function _run(target) + -- has been disabled? + if not target:is_enabled() then + return + end + -- enter the environments of the target packages local oldenvs = {} _add_target_pkgenvs(target, oldenvs, {}) @@ -117,13 +117,6 @@ function _run(target) { target:script("run_before") , function (target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- run rules for _, r in ipairs(target:orderules()) do local before_run = r:script("run_before") if before_run then @@ -133,13 +126,6 @@ function _run(target) end , target:script("run", _on_run_target) , function (target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- run rules for _, r in ipairs(target:orderules()) do local after_run = r:script("run_after") if after_run then @@ -174,8 +160,7 @@ function _check_targets(targetname) else -- install default or all targets for _, target in ipairs(project.ordertargets()) do - local default = target:get("default") - if (default == nil or default == true or option.get("all")) and target:kind() == "binary" then + if (target:is_default() or option.get("all")) and target:is_binary() then table.insert(targets, target) end end @@ -184,7 +169,7 @@ function _check_targets(targetname) -- filter and check targets with builtin-run script local targetnames = {} for _, target in ipairs(targets) do - if not target:isphony() and target:get("enabled") ~= false and not target:script("run") then + if not target:is_phony() and target:is_enabled() and not target:script("run") then local targetfile = target:targetfile() if targetfile and not os.isfile(targetfile) then table.insert(targetnames, target:name()) @@ -219,8 +204,7 @@ function main() else -- run default or all binary targets for _, target in ipairs(project.ordertargets()) do - local default = target:get("default") - if (default == nil or default == true or option.get("all")) and target:kind() == "binary" then + if (target:is_default() or option.get("all")) and target:is_binary() then _run(target) end end diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua index bc7468030..08b5067ba 100644 --- a/xmake/actions/uninstall/uninstall.lua +++ b/xmake/actions/uninstall/uninstall.lua @@ -49,7 +49,7 @@ end function _uninstall_target(target) -- has been disabled? - if target:get("enabled") == false then + if not target:is_enabled() then return end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 75cfa106e..86990a2cb 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -935,6 +935,7 @@ function project.ordertargets() if not ordertargets then -- ensure ordertargets to be cached project.targets() + ordertargets = project._memcache():get("ordertargets") end return ordertargets end diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 81ef99148..87a082888 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -165,6 +165,7 @@ function rule.apis() -- rule.on_xxx "rule.on_run" , "rule.on_load" + , "rule.on_config" , "rule.on_link" , "rule.on_build" , "rule.on_build_file" diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 4b14c8a13..079199b47 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -640,15 +640,37 @@ function _instance:rule(name) end -- is phony target? -function _instance:isphony() - - -- get target kind +function _instance:is_phony() local targetkind = self:kind() - - -- is phony? return not targetkind or targetkind == "phony" end +-- is binary target? +function _instance:is_binary() + return self:kind() == "binary" +end + +-- is shared library target? +function _instance:is_shared() + return self:kind() == "shared" +end + +-- is static library target? +function _instance:is_static() + return self:kind() == "static" +end + +-- is default target? +function _instance:is_default() + local default = self:get("default") + return default == nil or default == true +end + +-- is enabled? +function _instance:is_enabled() + return self:get("enabled") ~= false +end + -- get the enabled option function _instance:opt(name) return self:opts()[name] @@ -1883,6 +1905,7 @@ function target.apis() -- target.on_xxx "target.on_run" , "target.on_load" + , "target.on_config" , "target.on_link" , "target.on_build" , "target.on_build_file" diff --git a/xmake/modules/target/action/clean/main.lua b/xmake/modules/target/action/clean/main.lua index 443c3bd0a..8cbc9599c 100644 --- a/xmake/modules/target/action/clean/main.lua +++ b/xmake/modules/target/action/clean/main.lua @@ -26,7 +26,7 @@ import("private.action.clean.remove_files") function main(target) -- is phony? - if target:isphony() then + if target:is_phony() then return end diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 64dec9f18..289d258f0 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -47,7 +47,7 @@ function main(target, opt) print("installing %s to %s ..", target:name(), installdir) -- call script - if not target:isphony() then + if not target:is_phony() then local install_style = target:is_plat("windows", "mingw") and "windows" or "unix" local script = import(install_style, {anonymous = true})["install_" .. target:kind()] if script then diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 5e7e26a9b..cc5feb3ac 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -39,7 +39,7 @@ function main(target, opt) print("uninstalling %s from %s ..", target:name(), installdir) -- call script - if not target:isphony() then + if not target:is_phony() then local install_style = target:is_plat("windows", "mingw") and "windows" or "unix" local script = import(install_style, {anonymous = true})["uninstall_" .. target:kind()] if script then diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 41d83bd57..9c25789d5 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -175,7 +175,7 @@ function _make_all(jsonfile) -- make commands _g.firstline = true for _, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then _make_target(jsonfile, target) end end diff --git a/xmake/plugins/project/clang/compile_flags.lua b/xmake/plugins/project/clang/compile_flags.lua index 9662943e3..3f521b916 100644 --- a/xmake/plugins/project/clang/compile_flags.lua +++ b/xmake/plugins/project/clang/compile_flags.lua @@ -74,11 +74,9 @@ end -- make all function _make_all() - -- make flags _g.firstline = true for _, target in pairs(project.targets()) do - local isdefault = target:get("default") - if not target:isphony() and (isdefault == nil or isdefault == true) then + if not target:is_phony() and target:is_default() then _make_target(target) end end diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 502b5bc51..022e9fd88 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -477,7 +477,7 @@ function _add_target(cmakelists, target) -- is phony target? local targetkind = target:kind() - if target:isphony() then + if target:is_phony() then return _add_target_phony(cmakelists, target) elseif targetkind == "binary" then _add_target_binary(cmakelists, target) diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua index 68098563d..75afafa92 100644 --- a/xmake/plugins/project/make/makefile.lua +++ b/xmake/plugins/project/make/makefile.lua @@ -214,7 +214,7 @@ end function _make_target(makefile, target, targetflags) -- is phony target? - if target:isphony() then + if target:is_phony() then return _make_phony(makefile, target) end @@ -226,7 +226,7 @@ function _make_target(makefile, target, targetflags) -- make dependence for the dependent targets for _, depname in ipairs(target:get("deps")) do local dep = project.target(depname) - makefile:write(" " .. (dep:isphony() and depname or dep:targetfile())) + makefile:write(" " .. (dep:is_phony() and depname or dep:targetfile())) end -- make dependence for objects @@ -359,7 +359,7 @@ function _make_all(makefile) -- make variables for target local targetflags = {} for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then -- make target linker local program = _get_program_from_target(target, target:linker():kind()) @@ -392,8 +392,7 @@ function _make_all(makefile) -- make all local default = "" for targetname, target in pairs(project.targets()) do - local isdefault = target:get("default") - if isdefault == nil or isdefault == true then + if target:is_default() then default = default .. " " .. targetname end end @@ -426,7 +425,7 @@ function _clean_target(makefile, target) makefile:print("") -- make body - if not target:isphony() then + if not target:is_phony() then -- remove the target file _remove(makefile, target:targetfile()) diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua index 9ca2d8e42..72bb44a1d 100644 --- a/xmake/plugins/project/ninja/build_ninja.lua +++ b/xmake/plugins/project/ninja/build_ninja.lua @@ -228,7 +228,7 @@ end function _add_build_for_target(ninjafile, target) -- is phony target? - if target:isphony() then + if target:is_phony() then return _add_build_for_phony(ninjafile, target) end @@ -306,8 +306,7 @@ function _add_build_for_targets(ninjafile) -- build default local default = "" for targetname, target in pairs(project.targets()) do - local isdefault = target:get("default") - if isdefault == nil or isdefault == true then + if target:is_default() then default = default .. " " .. targetname end end diff --git a/xmake/plugins/project/vstudio/impl/vs200x.lua b/xmake/plugins/project/vstudio/impl/vs200x.lua index f9251dbe3..d1f220c8a 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x.lua @@ -44,7 +44,7 @@ function make(outputdir, vsinfo) -- make vsprojs for _, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then vs200x_vcproj.make(vsinfo, target) end end diff --git a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua index f2585764c..48b10445f 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua @@ -36,7 +36,7 @@ function _make_projects(slnfile, vsinfo) -- make all targets for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then -- enter project slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcproj\", \"{%s}\"", vctool, targetname, targetname, targetname, hash.uuid4(targetname)) @@ -68,7 +68,7 @@ function _make_global(slnfile, vsinfo) -- add project configuration platforms slnfile:enter("GlobalSection(ProjectConfigurationPlatforms) = postSolution") for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then slnfile:print("{%s}.$(mode)|Win32.ActiveCfg = $(mode)|Win32", hash.uuid4(targetname)) slnfile:print("{%s}.$(mode)|Win32.Build.0 = $(mode)|Win32", hash.uuid4(targetname)) end diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index cbc93e2c9..a66761d4d 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -220,6 +220,29 @@ function _make_vsinfo_archs() return vsinfo_archs end +-- config target +function _config_target(target) + for _, rule in ipairs(target:orderules()) do + local on_config = rule:script("config") + if on_config then + on_config(target) + end + end + local on_config = target:script("config") + if on_config then + on_config(target) + end +end + +-- config targets +function _config_targets() + for _, target in ipairs(project.ordertargets()) do + if target:is_enabled() then + _config_target(target) + end + end +end + -- make vstudio project function make(outputdir, vsinfo) @@ -273,6 +296,9 @@ function make(outputdir, vsinfo) -- install and update requires install_requires() + -- config targets + _config_targets() + -- update config files generate_configfiles() generate_configheader() @@ -283,7 +309,7 @@ function make(outputdir, vsinfo) -- save targets for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then -- make target with the given mode and arch targets[targetname] = targets[targetname] or {} diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua index 4aeaa204a..8b018a5d4 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua @@ -45,12 +45,12 @@ function _make_projects(slnfile, vsinfo) local targets = {} local vctool = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then -- we need set startup project for default or binary target -- @see https://github.com/xmake-io/xmake/issues/1249 if target:get("default") == true then table.insert(targets, 1, target) - elseif target:kind() == "binary" then + elseif target:is_binary() then local first_target = targets[1] if not first_target or first_target:get("default") ~= true then table.insert(targets, 1, target) @@ -105,7 +105,7 @@ function _make_global(slnfile, vsinfo) -- add project configuration platforms slnfile:enter("GlobalSection(ProjectConfigurationPlatforms) = postSolution") for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then for _, mode in ipairs(vsinfo.modes) do for _, arch in ipairs(vsinfo.archs) do local vs_arch = _vs_arch(arch) @@ -126,7 +126,7 @@ function _make_global(slnfile, vsinfo) slnfile:enter("GlobalSection(NestedProjects) = preSolution") local subgroups = {} for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then local group_path = target:get("group") if group_path then -- target -> group diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index e5cbaa196..f2d54fdfe 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -270,7 +270,7 @@ function _make_vsinfo_groups() local groups = {} local group_deps = {} for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then local group_path = target:get("group") if group_path then local group_name = path.filename(group_path) @@ -291,6 +291,29 @@ function _make_vsinfo_groups() return groups, group_deps end +-- config target +function _config_target(target) + for _, rule in ipairs(target:orderules()) do + local on_config = rule:script("config") + if on_config then + on_config(target) + end + end + local on_config = target:script("config") + if on_config then + on_config(target) + end +end + +-- config targets +function _config_targets() + for _, target in ipairs(project.ordertargets()) do + if target:is_enabled() then + _config_target(target) + end + end +end + -- make vstudio project function main(outputdir, vsinfo) @@ -366,6 +389,9 @@ function main(outputdir, vsinfo) -- install and update requires install_requires() + -- config targets + _config_targets() + -- update config files generate_configfiles() generate_configheader() @@ -375,7 +401,7 @@ function main(outputdir, vsinfo) -- save targets for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then -- make target with the given mode and arch targets[targetname] = targets[targetname] or {} @@ -443,10 +469,10 @@ function main(outputdir, vsinfo) -- @see https://github.com/xmake-io/xmake/issues/1249 local targetnames = {} for targetname, target in pairs(project.targets()) do - if not target:isphony() then + if not target:is_phony() then if target:get("default") == true then table.insert(targetnames, 1, targetname) - elseif target:kind() == "binary" then + elseif target:is_binary() then local first_target = targetnames[1] and project.target(targetnames[1]) if not first_target or first_target:get("default") ~= true then table.insert(targetnames, 1, targetname) diff --git a/xmake/rules/mode/xmake.lua b/xmake/rules/mode/xmake.lua index 932e47ae2..d68d8e42c 100644 --- a/xmake/rules/mode/xmake.lua +++ b/xmake/rules/mode/xmake.lua @@ -20,7 +20,7 @@ -- define rule: debug mode rule("mode.debug") - after_load(function (target) + on_config(function (target) -- is debug mode now? xmake f -m debug if is_mode("debug") then @@ -39,7 +39,7 @@ rule("mode.debug") -- define rule: release mode rule("mode.release") - after_load(function (target) + on_config(function (target) -- is release mode now? xmake f -m release if is_mode("release") then @@ -70,7 +70,7 @@ rule("mode.release") -- define rule: release with debug symbols mode rule("mode.releasedbg") - after_load(function (target) + on_config(function (target) -- is releasedbg mode now? xmake f -m releasedbg if is_mode("releasedbg") then @@ -101,7 +101,7 @@ rule("mode.releasedbg") -- define rule: release with minsize mode rule("mode.minsizerel") - after_load(function (target) + on_config(function (target) -- is minsizerel mode now? xmake f -m minsizerel if is_mode("minsizerel") then @@ -128,7 +128,7 @@ rule("mode.minsizerel") -- define rule: profile mode rule("mode.profile") - after_load(function (target) + on_config(function (target) -- is profile mode now? xmake f -m profile if is_mode("profile") then @@ -159,7 +159,7 @@ rule("mode.profile") -- define rule: coverage mode rule("mode.coverage") - after_load(function (target) + on_config(function (target) -- is coverage mode now? xmake f -m coverage if is_mode("coverage") then @@ -183,7 +183,7 @@ rule("mode.coverage") -- define rule: asan mode rule("mode.asan") - after_load(function (target) + on_config(function (target) -- is asan mode now? xmake f -m asan if is_mode("asan") then @@ -212,7 +212,7 @@ rule("mode.asan") -- define rule: tsan mode rule("mode.tsan") - after_load(function (target) + on_config(function (target) -- is tsan mode now? xmake f -m tsan if is_mode("tsan") then @@ -241,7 +241,7 @@ rule("mode.tsan") -- define rule: msan mode rule("mode.msan") - after_load(function (target) + on_config(function (target) -- is msan mode now? xmake f -m msan if is_mode("msan") then @@ -270,7 +270,7 @@ rule("mode.msan") -- define rule: lsan mode rule("mode.lsan") - after_load(function (target) + on_config(function (target) -- is lsan mode now? xmake f -m lsan if is_mode("lsan") then @@ -299,7 +299,7 @@ rule("mode.lsan") -- define rule: ubsan mode rule("mode.ubsan") - after_load(function (target) + on_config(function (target) -- is ubsan mode now? xmake f -m ubsan if is_mode("ubsan") then @@ -328,7 +328,7 @@ rule("mode.ubsan") -- define rule: valgrind mode rule("mode.valgrind") - after_load(function (target) + on_config(function (target) -- is valgrind mode now? xmake f -m valgrind if is_mode("valgrind") then @@ -351,7 +351,7 @@ rule("mode.valgrind") -- define rule: check mode (deprecated) rule("mode.check") - after_load(function (target) + on_config(function (target) -- is check mode now? xmake f -m check if is_mode("check") then diff --git a/xmake/rules/platform/windows/def/xmake.lua b/xmake/rules/platform/windows/def/xmake.lua index 97c356c28..06e960380 100644 --- a/xmake/rules/platform/windows/def/xmake.lua +++ b/xmake/rules/platform/windows/def/xmake.lua @@ -21,8 +21,7 @@ -- add *.def for windows/dll rule("platform.windows.def") set_extensions(".def") - --[[FIXME - after_load("windows", function (target) + on_config("windows", function (target) local _, toolname = target:tool("ld") if toolname == "link" then for _, sourcebatch in pairs(target:sourcebatches()) do @@ -33,11 +32,5 @@ rule("platform.windows.def") end end end - end)]] - before_build_file("windows", function (target, sourcefile) - local _, toolname = target:tool("ld") - if toolname == "link" then - target:add("shflags", "/def:" .. path.translate(sourcefile), {force = true}) - end end) diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua index 77546e25e..efb750edd 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -22,8 +22,7 @@ -- https://github.com/xmake-io/xmake/issues/1241 rule("platform.windows.manifest") set_extensions(".manifest") - --[[FIXME - after_load("windows", function (target) + on_config("windows", function (target) local _, toolname = target:tool("ld") if toolname == "link" then local manifest = false @@ -39,10 +38,4 @@ rule("platform.windows.manifest") target:add("ldflags", "/manifest", {force = true}) end end - end)]] - before_build_file("windows", function (target, sourcefile) - local _, toolname = target:tool("ld") - if toolname == "link" then - target:add("ldflags", "/manifest", "/ManifestFile:" .. path.translate(sourcefile), {force = true}) - end end) diff --git a/xmake/rules/qt/env/xmake.lua b/xmake/rules/qt/env/xmake.lua index 38fd503fc..4cc39794c 100644 --- a/xmake/rules/qt/env/xmake.lua +++ b/xmake/rules/qt/env/xmake.lua @@ -18,11 +18,8 @@ -- @file xmake.lua -- --- define rule: environment rule("qt.env") - - -- before load - before_load(function (target) + on_load(function (target) -- imports import("detect.sdks.find_qt") @@ -33,11 +30,11 @@ rule("qt.env") qt = assert(find_qt(nil, {verbose = true}), "Qt SDK not found!") target:data_set("qt", qt) end - if is_plat("windows") or (is_plat("mingw") and is_host("windows")) then + if target:is_plat("windows") or (target:is_plat("mingw") and is_host("windows")) then target:add("runenvs", "PATH", qt.bindir) target:set("runenv", "QML2_IMPORT_PATH", qt.qmldir) target:set("runenv", "QML_IMPORT_TRACE", "1") - elseif is_plat("msys", "cygwin") then + elseif target:is_plat("msys", "cygwin") then raise("please run `xmake f -p mingw --mingw=/mingw64` to support Qt/Mingw64 on Msys!") end end) diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index 2ad3d969c..46ff73dfa 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -18,16 +18,9 @@ -- @file xmake.lua -- --- define rule: moc rule("qt.moc") - - -- add rule: qt environment add_deps("qt.env") - - -- set extensions set_extensions(".h", ".hpp") - - -- before build file (we need compile it first if exists Q_PRIVATE_SLOT) before_buildcmd_file(function (target, batchcmds, sourcefile, opt) -- imports diff --git a/xmake/rules/qt/qrc/xmake.lua b/xmake/rules/qt/qrc/xmake.lua index fa5d85743..2529ef118 100644 --- a/xmake/rules/qt/qrc/xmake.lua +++ b/xmake/rules/qt/qrc/xmake.lua @@ -18,17 +18,10 @@ -- @file xmake.lua -- --- define rule: *.qrc rule("qt.qrc") - - -- add rule: qt environment add_deps("qt.env") - - -- set extensions set_extensions(".qrc") - - -- before load - before_load(function (target) + on_load(function (target) -- get rcc local rcc = path.join(target:data("qt").bindir, is_host("windows") and "rcc.exe" or "rcc") @@ -38,7 +31,6 @@ rule("qt.qrc") target:data_set("qt.rcc", rcc) end) - -- on build file on_buildcmd_file(function (target, batchcmds, sourcefile_qrc, opt) -- get rcc diff --git a/xmake/rules/qt/ui/xmake.lua b/xmake/rules/qt/ui/xmake.lua index d6811092c..b1ce103e5 100644 --- a/xmake/rules/qt/ui/xmake.lua +++ b/xmake/rules/qt/ui/xmake.lua @@ -18,17 +18,10 @@ -- @file xmake.lua -- --- define rule: *.ui rule("qt.ui") - - -- add rule: qt environment add_deps("qt.env") - - -- set extensions set_extensions(".ui") - - -- before load - before_load(function (target) + on_load(function (target) -- get uic local uic = path.join(target:data("qt").bindir, is_host("windows") and "uic.exe" or "uic") @@ -49,7 +42,6 @@ rule("qt.ui") target:data_set("qt.uic", uic) end) - -- before build file before_buildcmd_file(function (target, batchcmds, sourcefile_ui, opt) local uic = target:data("qt.uic") local headerfile_dir = path.join(target:autogendir(), "rules", "qt", "ui") diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index fd5b5a41e..ed4deedb7 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -41,11 +41,11 @@ rule("qt.static") add_deps("qt.qrc", "qt.ui", "qt.moc") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) + on_load(function (target) target:set("kind", "static") end) - after_load(function (target) + on_config(function (target) import("load")(target, {frameworks = {"QtCore"}}) end) @@ -54,11 +54,11 @@ rule("qt.shared") add_deps("qt.qrc", "qt.ui", "qt.moc") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) + on_load(function (target) target:set("kind", "shared") end) - after_load(function (target) + on_config(function (target) import("load")(target, {frameworks = {"QtCore"}}) end) @@ -67,11 +67,11 @@ rule("qt.console") add_deps("qt.qrc", "qt.ui", "qt.moc") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) + on_load(function (target) target:set("kind", "binary") end) - after_load(function (target) + on_config(function (target) import("load")(target, {frameworks = {"QtCore"}}) end) @@ -82,11 +82,11 @@ rule("qt.widgetapp") add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - target:set("kind", is_plat("android") and "shared" or "binary") + on_load(function (target) + target:set("kind", target:is_plat("android") and "shared" or "binary") end) - after_load(function (target) + on_config(function (target) import("load")(target, {gui = true, frameworks = {"QtGui", "QtWidgets", "QtCore"}}) end) @@ -103,11 +103,11 @@ rule("qt.widgetapp_static") add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - target:set("kind", is_plat("android") and "shared" or "binary") + on_load(function (target) + target:set("kind", target:is_plat("android") and "shared" or "binary") end) - after_load(function (target) + on_config(function (target) -- get qt sdk version local qt = target:data("qt") @@ -153,11 +153,11 @@ rule("qt.quickapp") add_deps("qt.qrc", "qt.moc", "qt._wasm_app") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - target:set("kind", is_plat("android") and "shared" or "binary") + on_load(function (target) + target:set("kind", target:is_plat("android") and "shared" or "binary") end) - after_load(function (target) + on_config(function (target) import("load")(target, {gui = true, frameworks = {"QtGui", "QtQuick", "QtQml", "QtCore", "QtNetwork"}}) end) @@ -174,11 +174,11 @@ rule("qt.quickapp_static") add_deps("qt.qrc", "qt.moc", "qt._wasm_app") -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - target:set("kind", is_plat("android") and "shared" or "binary") + on_load(function (target) + target:set("kind", target:is_plat("android") and "shared" or "binary") end) - after_load(function (target) + on_config(function (target) -- get qt sdk version local qt = target:data("qt") diff --git a/xmake/rules/utils/compiler_runtime/xmake.lua b/xmake/rules/utils/compiler_runtime/xmake.lua index a00ef170e..f8e3d39d0 100644 --- a/xmake/rules/utils/compiler_runtime/xmake.lua +++ b/xmake/rules/utils/compiler_runtime/xmake.lua @@ -20,7 +20,7 @@ -- define rule: utils.compiler.runtime rule("utils.compiler.runtime") - after_load(function (target) + on_config(function (target) -- set vs runtime local vs_runtime = get_config("vs_runtime") diff --git a/xmake/rules/utils/inherit_links/xmake.lua b/xmake/rules/utils/inherit_links/xmake.lua index 1ba06ea3c..a6b13a9df 100644 --- a/xmake/rules/utils/inherit_links/xmake.lua +++ b/xmake/rules/utils/inherit_links/xmake.lua @@ -20,5 +20,5 @@ -- define rule: utils.inherit.links rule("utils.inherit.links") - after_load("inherit_links") + on_config("inherit_links") diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua index 52408957c..5d14e979b 100644 --- a/xmake/rules/utils/symbols/export_all/export_all.lua +++ b/xmake/rules/utils/symbols/export_all/export_all.lua @@ -30,7 +30,7 @@ import("private.utils.progress") function main (target, opt) -- @note it only supports windows/dll now - assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name()) + assert(target:is_shared(), 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name()) if not target:is_plat("windows") or option.get("dry-run") then return end diff --git a/xmake/rules/utils/symbols/export_all/xmake.lua b/xmake/rules/utils/symbols/export_all/xmake.lua index 9d766356e..f804e3c3e 100644 --- a/xmake/rules/utils/symbols/export_all/xmake.lua +++ b/xmake/rules/utils/symbols/export_all/xmake.lua @@ -28,7 +28,7 @@ rule("utils.symbols.export_all") before_load(function (target) -- @note it only supports windows/dll now - assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name()) + assert(target:is_shared(), 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name()) if target:is_plat("windows") then assert(target:get("optimize") ~= "smallest", 'rule("utils.symbols.export_all"): does not support set_optimize("smallest") for target(%s)!', target:name()) local allsymbols_filepath = path.join(target:autogendir(), "rules", "symbols", "export_all.def") |
