summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-26 15:11:38 +0800
committerGitHub <[email protected]>2022-10-26 15:11:38 +0800
commit572663ccd26ca864df5524ebff8c69de9a865077 (patch)
tree1ff65a362b0d32d5f3bf2645beee2dd7af01e1e8
parent70c2712a6d3436e7611d8596809e36df518f746d (diff)
parentc4a0ed84e0612446316d33f542d69bc550361292 (diff)
Merge pull request #2971 from xmake-io/sort
Stabilize vs and vsxmake project generation #2959
-rw-r--r--xmake/core/base/hashset.lua49
-rw-r--r--xmake/core/base/table.lua3
-rw-r--r--xmake/core/project/package.lua6
-rw-r--r--xmake/core/project/project.lua4
-rw-r--r--xmake/core/project/target.lua6
-rw-r--r--xmake/modules/private/action/require/impl/register_packages.lua4
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua22
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_solution.lua8
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua2
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua22
10 files changed, 93 insertions, 33 deletions
diff --git a/xmake/core/base/hashset.lua b/xmake/core/base/hashset.lua
index c2d5e131e..2a0449ad4 100644
--- a/xmake/core/base/hashset.lua
+++ b/xmake/core/base/hashset.lua
@@ -109,10 +109,53 @@ function hashset_impl:to_array()
end
-- iterate keys of hashtable
--- for _, key in instance:keys() do ... end
+--
+-- @code
+-- for _, key in instance:keys() do
+-- ...
+-- end
+-- @endcode
+--
function hashset_impl:keys()
- return function (table, key)
- local k, _ = next(table._DATA, key)
+ return function (t, key)
+ local k, _ = next(t._DATA, key)
+ if k == hashset._NIL then
+ return k, nil
+ else
+ return k, k
+ end
+ end, self, nil
+end
+
+-- order keys iterator
+--
+-- @code
+-- for _, key in instance:orderkeys() do
+-- ...
+-- end
+-- @endcode
+--
+function hashset_impl:orderkeys()
+ local orderkeys = table.keys(self._DATA)
+ table.sort(orderkeys, function (a, b)
+ if a == hashset._NIL then
+ a = math.inf
+ end
+ if b == hashset._NIL then
+ b = math.inf
+ end
+ if type(a) == "table" then
+ a = tostring(a)
+ end
+ if type(b) == "table" then
+ b = tostring(b)
+ end
+ return a < b
+ end)
+ local i = 1
+ return function (t, k)
+ k = orderkeys[i]
+ i = i + 1
if k == hashset._NIL then
return k, nil
else
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index a360f7b42..84caf1bfa 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -440,6 +440,9 @@ end
-- TODO
-- end
function table.orderpairs(t)
+ if type(t) ~= "table" then
+ t = t ~= nil and {t} or {}
+ end
local orderkeys = table.orderkeys(t)
local i = 1
return function (t, k)
diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua
index 5db816e29..7181480c4 100644
--- a/xmake/core/project/package.lua
+++ b/xmake/core/project/package.lua
@@ -256,6 +256,12 @@ function _instance:_sort_componentdeps(name)
return orderdeps
end
+-- we need sort package set keys by this string
+-- @see https://github.com/xmake-io/xmake/pull/2971#issuecomment-1290052169
+function _instance:__tostring()
+ return "<package: " .. self:name() .. ">"
+end
+
-- get cache
function package._cache()
return localcache.cache("package")
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 8e53dbc4e..da1966e8c 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -899,7 +899,7 @@ function project.ordertargets()
local targets = project.targets()
ordertargets = {}
local targetrefs = {}
- for _, t in pairs(targets) do
+ for _, t in table.orderpairs(targets) do
instance_deps.sort_deps(targets, ordertargets, targetrefs, t)
end
project._memcache():set("ordertargets", ordertargets)
@@ -1191,7 +1191,7 @@ function project.modes()
modes = allowed_modes:to_array()
else
modes = {}
- for _, target in pairs(table.wrap(project.targets())) do
+ for _, target in table.orderpairs(table.wrap(project.targets())) do
for _, rule in ipairs(target:orderules()) do
local name = rule:name()
if name:startswith("mode.") then
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 9fc02ff19..ddbd2927a 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -775,7 +775,7 @@ function _instance:orderules()
if orderules == nil and rules then
orderules = {}
local rulerefs = {}
- for _, r in pairs(rules) do
+ for _, r in table.orderpairs(rules) do
instance_deps.sort_deps(rules, orderules, rulerefs, r)
end
self._ORDERULES = orderules
@@ -979,10 +979,10 @@ function _instance:pkgenvs()
end
end
end
- for _, pkg in pkgs:keys() do
+ for _, pkg in pkgs:orderkeys() do
local envs = pkg:get("envs")
if envs then
- for name, values in pairs(envs) do
+ for name, values in table.orderpairs(envs) do
if type(values) == "table" then
values = path.joinenv(values)
end
diff --git a/xmake/modules/private/action/require/impl/register_packages.lua b/xmake/modules/private/action/require/impl/register_packages.lua
index 4b92b75d8..26918e0aa 100644
--- a/xmake/modules/private/action/require/impl/register_packages.lua
+++ b/xmake/modules/private/action/require/impl/register_packages.lua
@@ -24,7 +24,7 @@ import("core.project.project")
-- register required package environments
-- envs: bin path for *.dll, program ..
function _register_required_package_envs(instance, envs)
- for name, values in pairs(instance:envs()) do
+ for name, values in table.orderpairs(instance:envs()) do
envs[name] = envs[name] or {}
table.join2(envs[name], values)
end
@@ -67,7 +67,7 @@ function _register_required_package_libs(instance, required_package, is_deps)
if required_components then
fetchinfo.libfiles = nil
local components_base = required_components.__base or {}
- for k, v in pairs(fetchinfo) do
+ for k, v in table.orderpairs(fetchinfo) do
local values = table.wrap(components_base[k])
components_base[k] = table.unwrap(table.unique(table.join(values, v)))
end
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 116ca689f..aad60542d 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -213,7 +213,7 @@ function _make_custom_commands(target, vcxprojdir)
local commands = {}
_make_custom_commands_for_target(commands, target, vcxprojdir, "before")
_make_custom_commands_for_target(commands, target, vcxprojdir)
- for _, sourcebatch in pairs(target:sourcebatches()) do
+ for _, sourcebatch in table.orderpairs(target:sourcebatches()) do
local rulename = sourcebatch.rulename
local sourcekind = sourcebatch.sourcekind
if rulename ~= "c.build" and rulename ~= "c++.build" and rulename ~= "asm.build" and rulename ~= "cuda.build" and sourcekind ~= "mrc" then
@@ -281,7 +281,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
local firstcompflags = nil
targetinfo.compflags = {}
targetinfo.compargvs = {}
- for _, sourcebatch in pairs(target:sourcebatches()) do
+ for _, sourcebatch in table.orderpairs(target:sourcebatches()) do
local sourcekind = sourcebatch.sourcekind
local rulename = sourcebatch.rulename
if sourcekind then
@@ -324,24 +324,24 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
-- save runenvs
local runenvs = {}
local addrunenvs, setrunenvs = make_runenvs(target)
- for k, v in pairs(target:pkgenvs()) do
+ for k, v in table.orderpairs(target:pkgenvs()) do
addrunenvs = addrunenvs or {}
addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
end
for _, dep in ipairs(target:orderdeps()) do
- for k, v in pairs(dep:pkgenvs()) do
+ for k, v in table.orderpairs(dep:pkgenvs()) do
addrunenvs = addrunenvs or {}
addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
end
end
- for k, v in pairs(addrunenvs) do
+ for k, v in table.orderpairs(addrunenvs) do
if k:upper() == "PATH" then
runenvs[k] = _translate_path(v, vcxprojdir) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .. "'))"
else
runenvs[k] = path.joinenv(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .."'))"
end
end
- for k, v in pairs(setrunenvs) do
+ for k, v in table.orderpairs(setrunenvs) do
if #v == 1 then
v = v[1]
if path.is_absolute(v) and v:startswith(project.directory()) then
@@ -354,7 +354,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
end
end
local runenvstr = {}
- for k, v in pairs(runenvs) do
+ for k, v in table.orderpairs(runenvs) do
table.insert(runenvstr, k .. "=" .. v)
end
targetinfo.runenvs = table.concat(runenvstr, "\n")
@@ -612,7 +612,7 @@ function make(outputdir, vsinfo)
os.cd(project.directory())
-- save targets
- for targetname, target in pairs(project.targets()) do
+ for targetname, target in table.orderpairs(project.targets()) do
-- make target with the given mode and arch
targets[targetname] = targets[targetname] or {}
@@ -636,6 +636,10 @@ function make(outputdir, vsinfo)
_target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles())))
_target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles())))
+ -- sort them to stabilize generation
+ table.sort(_target.sourcefiles)
+ table.sort(_target.headerfiles)
+
-- save file groups
_target.filegroups = target:get("filegroups")
_target.filegroups_extraconf = target:extraconf("filegroups")
@@ -650,7 +654,7 @@ function make(outputdir, vsinfo)
vs201x_solution.make(vsinfo)
-- make .vcxproj
- for _, target in pairs(targets) do
+ for _, target in table.orderpairs(targets) do
vs201x_vcxproj.make(vsinfo, target)
vs201x_vcxproj_filters.make(vsinfo, target)
end
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
index 2156edc4b..599d2b38d 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
@@ -36,7 +36,7 @@ function _make_projects(slnfile, vsinfo)
local groups = {}
local targets = {}
local vctool = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"
- for targetname, target in pairs(project.targets()) do
+ for targetname, target in table.orderpairs(project.targets()) do
-- 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
@@ -71,7 +71,7 @@ function _make_projects(slnfile, vsinfo)
-- make all groups
local project_group_uuid = "2150E333-8FDC-42A3-9474-1A3956D46DE8"
- for group_name, group_uuid in pairs(groups) do
+ for group_name, group_uuid in table.orderpairs(groups) do
slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\", \"{%s}\"", project_group_uuid, group_name, group_name, group_uuid)
slnfile:leave("EndProject")
end
@@ -94,7 +94,7 @@ function _make_global(slnfile, vsinfo)
-- add project configuration platforms
slnfile:enter("GlobalSection(ProjectConfigurationPlatforms) = postSolution")
- for targetname, target in pairs(project.targets()) do
+ for targetname, target in table.orderpairs(project.targets()) do
for _, mode in ipairs(vsinfo.modes) do
for _, arch in ipairs(vsinfo.archs) do
local vs_arch = vsutils.vsarch(arch)
@@ -113,7 +113,7 @@ function _make_global(slnfile, vsinfo)
-- add project groups
slnfile:enter("GlobalSection(NestedProjects) = preSolution")
local subgroups = {}
- for targetname, target in pairs(project.targets()) do
+ for targetname, target in table.orderpairs(project.targets()) do
local group_path = target:get("group")
if group_path then
-- target -> group
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index 24b680b0d..e4bfddae3 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -1331,7 +1331,7 @@ function _make_source_files(vcxprojfile, vsinfo, target)
end
-- make source files
- for sourcefile, sourceinfo in pairs(sourceinfos) do
+ for sourcefile, sourceinfo in table.orderpairs(sourceinfos) do
if #sourceinfo == #target.info then
_make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourceinfo)
else
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index c02f83eea..b13900690 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -161,24 +161,24 @@ function _make_targetinfo(mode, arch, target)
-- save runenvs
local runenvs = {}
local addrunenvs, setrunenvs = make_runenvs(target)
- for k, v in pairs(target:pkgenvs()) do
+ for k, v in table.orderpairs(target:pkgenvs()) do
addrunenvs = addrunenvs or {}
addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
end
for _, dep in ipairs(target:orderdeps()) do
- for k, v in pairs(dep:pkgenvs()) do
+ for k, v in table.orderpairs(dep:pkgenvs()) do
addrunenvs = addrunenvs or {}
addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
end
end
- for k, v in pairs(addrunenvs) do
+ for k, v in table.orderpairs(addrunenvs) do
if k:upper() == "PATH" then
runenvs[k] = _make_dirs(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .. "'))"
else
runenvs[k] = path.joinenv(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .."'))"
end
end
- for k, v in pairs(setrunenvs) do
+ for k, v in table.orderpairs(setrunenvs) do
if #v == 1 then
v = v[1]
if path.is_absolute(v) and v:startswith(project.directory()) then
@@ -191,7 +191,7 @@ function _make_targetinfo(mode, arch, target)
end
end
local runenvstr = {}
- for k, v in pairs(runenvs) do
+ for k, v in table.orderpairs(runenvs) do
table.insert(runenvstr, k .. "=" .. v)
end
targetinfo.runenvs = table.concat(runenvstr, "\n")
@@ -272,7 +272,7 @@ end
function _make_vsinfo_groups()
local groups = {}
local group_deps = {}
- for targetname, target in pairs(project.targets()) do
+ for targetname, target in table.orderpairs(project.targets()) do
local group_path = target:get("group")
if group_path then
local group_name = path.filename(group_path)
@@ -442,7 +442,7 @@ function main(outputdir, vsinfo)
-- init config flags
local flags = {}
- for k, v in pairs(localcache.get("config", "options")) do
+ for k, v in table.orderpairs(localcache.get("config", "options")) do
if k ~= "plat" and k ~= "mode" and k ~= "arch" and k ~= "clean" and k ~= "buildir" then
table.insert(flags, "--" .. k .. "=" .. tostring(v))
end
@@ -502,7 +502,7 @@ function main(outputdir, vsinfo)
os.cd(project.directory())
-- save targets
- for targetname, target in pairs(project.targets()) do
+ for targetname, target in table.orderpairs(project.targets()) do
-- https://github.com/xmake-io/xmake/issues/2337
target:data_set("plugin.project.kind", "vsxmake")
@@ -532,6 +532,10 @@ function main(outputdir, vsinfo)
_target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles())))
_target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles())))
+ -- sort them to stabilize generation
+ table.sort(_target.sourcefiles)
+ table.sort(_target.headerfiles)
+
-- save file groups
_target.filegroups = target:get("filegroups")
_target.filegroups_extraconf = target:extraconf("filegroups")
@@ -542,7 +546,7 @@ function main(outputdir, vsinfo)
end
end
os.cd(oldir)
- for _, target in pairs(targets) do
+ for _, target in table.orderpairs(targets) do
target._paths = {}
local dirs = {}
local projectdir = project.directory()