summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-03-05 22:41:06 +0800
committerruki <[email protected]>2021-03-05 22:41:06 +0800
commit97e94809e0ffb871b2e8a7554ad3eb54a034c525 (patch)
tree1f81d3047ff4b7cf615df5dacd044d606fadd5b8
parentecb7b50da9471f2ebc5d44d01c72e7860776e2c9 (diff)
add is_enabled
-rw-r--r--xmake/actions/build/build.lua4
-rw-r--r--xmake/actions/build/build_files.lua2
-rw-r--r--xmake/actions/clean/main.lua2
-rw-r--r--xmake/actions/config/configfiles.lua2
-rw-r--r--xmake/actions/config/main.lua65
-rw-r--r--xmake/actions/install/install.lua2
-rw-r--r--xmake/actions/install/main.lua2
-rw-r--r--xmake/actions/package/main.lua12
-rw-r--r--xmake/actions/run/main.lua26
-rw-r--r--xmake/actions/uninstall/uninstall.lua2
-rw-r--r--xmake/core/project/rule.lua1
-rw-r--r--xmake/core/project/target.lua18
-rw-r--r--xmake/modules/target/action/clean/main.lua2
-rw-r--r--xmake/modules/target/action/install/main.lua2
-rw-r--r--xmake/modules/target/action/uninstall/main.lua2
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua2
-rw-r--r--xmake/plugins/project/clang/compile_flags.lua2
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua2
-rw-r--r--xmake/plugins/project/make/makefile.lua8
-rw-r--r--xmake/plugins/project/ninja/build_ninja.lua2
-rw-r--r--xmake/plugins/project/vstudio/impl/vs200x.lua2
-rw-r--r--xmake/plugins/project/vstudio/impl/vs200x_solution.lua4
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua2
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_solution.lua6
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua6
25 files changed, 98 insertions, 82 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index 79e6ad40e..42d78ad19 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
diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua
index 3d0a48e75..c02537b2b 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
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..a061ce2c6 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
diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua
index 1f990a1b9..16d9ed329 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
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index 62bd9210b..68481f339 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -47,7 +47,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..624b90d5a 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())
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 0974b2f68..fd6510aba 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -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
@@ -184,7 +170,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())
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/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..0c3287eee 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -640,15 +640,22 @@ 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 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 +1890,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..f85ed631b 100644
--- a/xmake/plugins/project/clang/compile_flags.lua
+++ b/xmake/plugins/project/clang/compile_flags.lua
@@ -78,7 +78,7 @@ function _make_all()
_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 (isdefault == nil or isdefault == true) 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..6a8d18650 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())
@@ -426,7 +426,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..041639a40 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
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..968cac080 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -283,7 +283,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..fdd948561 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
@@ -45,7 +45,7 @@ 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
@@ -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..8d36cdbe7 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)
@@ -375,7 +375,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,7 +443,7 @@ 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