summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-04-10 06:48:50 +0800
committerGitHub <[email protected]>2023-04-10 06:48:50 +0800
commitb1ec1d62069685ccc6a250b8f2dd05785d40cdcf (patch)
treeaea60e5fdf33fb916bc8c198df14692c69697ebc
parent4409050621e7872e50634cf0e331ffc70b69ddb6 (diff)
parent5b68e4d38230e0f89a97047ab916b6a9c2bbe942 (diff)
Merge pull request #3615 from xmake-io/project
load targets for run/install
-rw-r--r--xmake/actions/config/main.lua76
-rw-r--r--xmake/actions/install/main.lua6
-rw-r--r--xmake/actions/run/main.lua3
-rw-r--r--xmake/actions/uninstall/main.lua1
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua74
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua71
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua71
7 files changed, 89 insertions, 213 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index d24987348..bfe69da6d 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -155,72 +155,6 @@ function _check_target_toolchains()
end
end
--- config target
-function _config_target(target)
- local oldenvs = os.addenvs(target:pkgenvs())
- 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
- if oldenvs then
- os.setenvs(oldenvs)
- 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
-
--- load rules in the required packages for target
-function _load_package_rules_for_target(target)
- for _, rulename in ipairs(target:get("rules")) do
- local packagename = rulename:match("@(.-)/")
- if packagename then
- local pkginfo = project.required_package(packagename)
- if pkginfo then
- local r = pkginfo:rule(rulename)
- if r then
- target:rule_add(r)
- for _, dep in pairs(r:deps()) do
- target:rule_add(dep)
- end
- end
- end
- end
- end
-end
-
--- load rules in the required packages for targets
--- @see https://github.com/xmake-io/xmake/issues/2374
---
--- @code
--- add_requires("zlib", {system = false})
--- target("test")
--- set_kind("binary")
--- add_files("src/*.cpp")
--- add_packages("zlib")
--- add_rules("@zlib/test")
--- @endcode
---
-function _load_package_rules_for_targets()
- for _, target in ipairs(project.ordertargets()) do
- if target:is_enabled() then
- _load_package_rules_for_target(target)
- end
- end
-end
-
-- find default mode
function _find_default_mode()
local mode = config.mode()
@@ -275,7 +209,6 @@ function _export_configs()
end
end
--- main entry
function main(opt)
-- do action for remote?
@@ -431,7 +364,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir())
-- check project options
if not trybuild then
- project.check()
+ project.check_options()
end
end
@@ -466,11 +399,8 @@ force to build in current directory via run `xmake -P .`]], os.projectdir())
_check_target_toolchains()
end
- -- load package rules for targets
- _load_package_rules_for_targets()
-
- -- config targets
- _config_targets()
+ -- load targets
+ project.load_targets()
-- update the config files
generate_configfiles({force = recheck})
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index 5d15a4c40..1d9f8b1c1 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -62,12 +62,14 @@ function _check_targets(targetname, group_pattern)
end
end
--- main
function main()
- -- local config first
+ -- load config first
config.load()
+ -- load targets
+ project.load_targets()
+
-- check targets first
local targetname
local group_pattern = option.get("group")
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 9e2a9ce40..e2f754846 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -213,6 +213,9 @@ function main()
-- load config first
config.load()
+ -- load targets
+ project.load_targets()
+
-- check targets first
local targetname
local group_pattern = option.get("group")
diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua
index 8dc0664e6..5c403b85e 100644
--- a/xmake/actions/uninstall/main.lua
+++ b/xmake/actions/uninstall/main.lua
@@ -26,7 +26,6 @@ import("core.base.privilege")
import("privilege.sudo")
import("uninstall")
--- main
function main()
-- config it first
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index a5778bc9e..f43590bb3 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -72,7 +72,7 @@ sandbox_core_project.tmpfile = project.tmpfile
sandbox_core_project.is_loaded = project.is_loaded
-- check project options
-function sandbox_core_project.check()
+function sandbox_core_project.check_options()
-- get project options
local options = {}
@@ -124,6 +124,78 @@ function sandbox_core_project.check()
end
end
+-- config target
+function sandbox_core_project._config_target(target)
+ for _, rule in ipairs(table.wrap(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 sandbox_core_project._config_targets()
+ for _, target in ipairs(table.wrap(project.ordertargets())) do
+ if target:is_enabled() then
+ sandbox_core_project._config_target(target)
+ end
+ end
+end
+
+-- load rules in the required packages for target
+function sandbox_core_project._load_package_rules_for_target(target)
+ for _, rulename in ipairs(table.wrap(target:get("rules"))) do
+ local packagename = rulename:match("@(.-)/")
+ if packagename then
+ local pkginfo = project.required_package(packagename)
+ if pkginfo then
+ local r = pkginfo:rule(rulename)
+ if r then
+ target:rule_add(r)
+ for _, dep in pairs(table.wrap(r:deps())) do
+ target:rule_add(dep)
+ end
+ end
+ end
+ end
+ end
+end
+
+-- load rules in the required packages for targets
+-- @see https://github.com/xmake-io/xmake/issues/2374
+--
+-- @code
+-- add_requires("zlib", {system = false})
+-- target("test")
+-- set_kind("binary")
+-- add_files("src/*.cpp")
+-- add_packages("zlib")
+-- add_rules("@zlib/test")
+-- @endcode
+--
+function sandbox_core_project._load_package_rules_for_targets()
+ for _, target in ipairs(table.wrap(project.ordertargets())) do
+ if target:is_enabled() then
+ sandbox_core_project._load_package_rules_for_target(target)
+ end
+ end
+end
+
+-- load project targets
+function sandbox_core_project.load_targets()
+
+ -- load package rules for targets
+ sandbox_core_project._load_package_rules_for_targets()
+
+ -- config targets
+ sandbox_core_project._config_targets()
+end
+
-- get the filelock of the whole project directory
function sandbox_core_project.filelock()
local filelock, errors = project.filelock()
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 4811a0f74..0b491ad65 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -495,68 +495,6 @@ 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
-
--- load rules in the required packages for target
-function _load_package_rules_for_target(target)
- for _, rulename in ipairs(target:get("rules")) do
- local packagename = rulename:match("@(.-)/")
- if packagename then
- local pkginfo = project.required_package(packagename)
- if pkginfo then
- local r = pkginfo:rule(rulename)
- if r then
- target:rule_add(r)
- for _, dep in pairs(r:deps()) do
- target:rule_add(dep)
- end
- end
- end
- end
- end
-end
-
--- load rules in the required packages for targets
--- @see https://github.com/xmake-io/xmake/issues/2374
---
--- @code
--- add_requires("zlib", {system = false})
--- target("test")
--- set_kind("binary")
--- add_files("src/*.cpp")
--- add_packages("zlib")
--- add_rules("@zlib/test")
--- @endcode
---
-function _load_package_rules_for_targets()
- for _, target in ipairs(project.ordertargets()) do
- if target:is_enabled() then
- _load_package_rules_for_target(target)
- end
- end
-end
-
-- make vstudio project
function make(outputdir, vsinfo)
@@ -605,16 +543,13 @@ function make(outputdir, vsinfo)
platform.load(config.plat(), arch):check()
-- check project options
- project.check()
+ project.check_options()
-- install and update requires
install_requires()
- -- load package rules for targets
- _load_package_rules_for_targets()
-
- -- config targets
- _config_targets()
+ -- load targets
+ project.load_targets()
-- update config files
generate_configfiles()
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index abfbe2538..9f32fccbb 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -306,68 +306,6 @@ 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
-
--- load rules in the required packages for target
-function _load_package_rules_for_target(target)
- for _, rulename in ipairs(target:get("rules")) do
- local packagename = rulename:match("@(.-)/")
- if packagename then
- local pkginfo = project.required_package(packagename)
- if pkginfo then
- local r = pkginfo:rule(rulename)
- if r then
- target:rule_add(r)
- for _, dep in pairs(r:deps()) do
- target:rule_add(dep)
- end
- end
- end
- end
- end
-end
-
--- load rules in the required packages for targets
--- @see https://github.com/xmake-io/xmake/issues/2374
---
--- @code
--- add_requires("zlib", {system = false})
--- target("test")
--- set_kind("binary")
--- add_files("src/*.cpp")
--- add_packages("zlib")
--- add_rules("@zlib/test")
--- @endcode
---
-function _load_package_rules_for_targets()
- for _, target in ipairs(project.ordertargets()) do
- if target:is_enabled() then
- _load_package_rules_for_target(target)
- end
- end
-end
-
-- make filter
function _make_filter(filepath, target, vcxprojdir)
local filter
@@ -503,16 +441,13 @@ function main(outputdir, vsinfo)
platform.load(config.plat(), arch):check()
-- check project options
- project.check()
+ project.check_options()
-- install and update requires
install_requires()
- -- load package rules for targets
- _load_package_rules_for_targets()
-
- -- config targets
- _config_targets()
+ -- load targets
+ project.load_targets()
-- update config files
generate_configfiles()