Skip to content

Commit 03a49dc

Browse files
fix: sort workspace configs and projects alphabetically for deterministic output (#2675)
1 parent 1449873 commit 03a49dc

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

modules/codelite/tests/test_codelite_workspace.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@
206206
<CodeLite_Workspace Name="MyWorkspace" Database="" Version="10000">
207207
<Project Name="MyProject" Path="MyProject.project"/>
208208
<BuildMatrix>
209-
<WorkspaceConfiguration Name="x86_64-Debug" Selected="yes">
210-
<Project Name="MyProject" ConfigName="x86_64-Debug"/>
211-
</WorkspaceConfiguration>
212-
<WorkspaceConfiguration Name="x86-Debug" Selected="no">
209+
<WorkspaceConfiguration Name="x86-Debug" Selected="yes">
213210
<Project Name="MyProject" ConfigName="x86-Debug"/>
214211
</WorkspaceConfiguration>
215-
<WorkspaceConfiguration Name="x86_64-Release" Selected="no">
216-
<Project Name="MyProject" ConfigName="x86_64-Release"/>
212+
<WorkspaceConfiguration Name="x86_64-Debug" Selected="no">
213+
<Project Name="MyProject" ConfigName="x86_64-Debug"/>
217214
</WorkspaceConfiguration>
218215
<WorkspaceConfiguration Name="x86-Release" Selected="no">
219216
<Project Name="MyProject" ConfigName="x86-Release"/>
220217
</WorkspaceConfiguration>
218+
<WorkspaceConfiguration Name="x86_64-Release" Selected="no">
219+
<Project Name="MyProject" ConfigName="x86_64-Release"/>
220+
</WorkspaceConfiguration>
221221
</BuildMatrix>
222222
</CodeLite_Workspace>
223223
]]

modules/ninja/tests/test_ninja_workspace.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ default TestProject_Debug
261261
test.capture [[
262262
263263
# Default build target
264-
default TestProject_Debug_x86
264+
default TestProject_Debug_x64
265265
]]
266266
end
267267

@@ -294,5 +294,3 @@ build all: phony
294294
build ProjectB: phony
295295
]]
296296
end
297-
298-

src/base/workspace.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@
5050
function workspace.eachconfig(self)
5151
self = p.oven.bakeWorkspace(self)
5252

53+
local sorted = {}
54+
for _, item in ipairs(self.configs) do
55+
table.insert(sorted, item)
56+
end
57+
table.sort(sorted, function(a,b) return a.name < b.name end)
58+
5359
local i = 0
5460
return function()
5561
i = i + 1
56-
if i > #self.configs then
62+
if i > #sorted then
5763
return nil
5864
else
59-
return self.configs[i]
65+
return sorted[i]
6066
end
6167
end
6268
end
@@ -70,11 +76,17 @@
7076
--
7177

7278
function workspace.eachproject(self)
79+
local sorted = {}
80+
for id, _ in ipairs(self.projects) do
81+
table.insert(sorted, p.workspace.getproject(self, id))
82+
end
83+
table.sort(sorted, function(a,b) return a.name < b.name end)
84+
7385
local i = 0
7486
return function ()
7587
i = i + 1
76-
if i <= #self.projects then
77-
return p.workspace.getproject(self, i)
88+
if i <= #sorted then
89+
return sorted[i]
7890
end
7991
end
8092
end

0 commit comments

Comments
 (0)