Skip to content

Commit 7fa8361

Browse files
committed
Resolve comments from review
1 parent 04943ab commit 7fa8361

File tree

7 files changed

+143
-105
lines changed

7 files changed

+143
-105
lines changed

src/base/oven.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
function p.global.bake(self)
8888
p.container.bakeChildren(self)
8989

90-
9190
-- now we can post process the projects for 'uses' entries and apply the
9291
-- corresponding 'usage' block to the project.
9392
oven.applyUsages()

src/base/project.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@
572572
end
573573

574574

575+
---
576+
-- Retrieve the project's usage information for a particular usage.
577+
-- @param name
578+
-- The name of the usage to retrieve.
579+
-- @return
580+
-- The usage object with the specified name or nil if not found.
581+
---
582+
575583
function project.findusage(self, name)
576584
for _, usage in ipairs(self.usages or self.project.usages) do
577585
if name == usage.name then
@@ -580,4 +588,4 @@
580588
end
581589

582590
return nil
583-
end
591+
end

src/base/usage.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,21 @@
5454
-- The usage object.
5555
-- @return
5656
-- True if the usage is a special usage.
57+
---
58+
5759
function usage.isSpecial(self)
5860
return usage.isSpecialName(self.name)
5961
end
6062

6163

64+
---
65+
-- Find a usage with the provided name in the global scope.
66+
--
67+
-- @param name
68+
-- The name of the usage to find.
69+
-- @return
70+
-- A list of usages with the provided name.
71+
---
6272
function usage.findglobal(name)
6373
-- First, try to find a project with the provided name in the global scope
6474
for wks in p.global.eachWorkspace() do
@@ -92,4 +102,4 @@
92102
end
93103

94104
return {}
95-
end
105+
end

tests/api/test_containers.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@
105105
end
106106

107107
function suite.usage_onStar()
108-
project("MyProject")
108+
local prj = project("MyProject")
109109
usage "MyUsage"
110110
usage "*"
111111
test.isnil(api.scope.usage)
112+
test.issame(api.scope.project, prj)
112113
end
113114

114115
function suite.usage_findusage()
@@ -117,4 +118,4 @@
117118
test.isnotnil(p.project.findusage(api.scope.project, "MyUsage"))
118119
test.issame(p.project.findusage(api.scope.project, "MyUsage").project, api.scope.project)
119120
test.issame(p.project.findusage(api.scope.project, "MyUsage"), api.scope.usage)
120-
end
121+
end

tests/oven/test_usages.lua

Lines changed: 99 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,137 +12,140 @@
1212
-- Setup
1313
---
1414

15-
local wks, prj
16-
17-
function suite.setup()
18-
wks = workspace("MyWorkspace")
19-
configurations { "Debug", "Release" }
20-
platforms { "x86", "x86_64" }
21-
22-
prj = project "MyProject1"
23-
usage "PUBLIC"
24-
defines { "PROJECT_1_PUBLIC" }
25-
usage "INTERFACE"
26-
defines { "PROJECT_1_INTERFACE" }
27-
usage "PRIVATE"
28-
defines { "PROJECT_1_PRIVATE" }
29-
end
15+
local wks, prj
16+
17+
function suite.setup()
18+
wks = workspace("MyWorkspace")
19+
configurations { "Debug", "Release" }
20+
platforms { "x86", "x86_64" }
21+
22+
prj = project "MyProject1"
23+
usage "PUBLIC"
24+
defines { "PROJECT_1_PUBLIC" }
25+
usage "INTERFACE"
26+
defines { "PROJECT_1_INTERFACE" }
27+
usage "PRIVATE"
28+
defines { "PROJECT_1_PRIVATE" }
29+
end
30+
3031

3132
---
3233
-- Tests to ensure that the PUBLIC and PRIVATE usages are correctly applied to the owning project
3334
---
34-
function suite.singleproject_checkusages()
35-
p.oven.bake()
35+
function suite.singleproject_checkusages()
36+
p.oven.bake()
37+
38+
local cfg = test.getconfig(prj, "Debug", "x86")
39+
test.contains({ "PROJECT_1_PUBLIC", "PROJECT_1_PRIVATE" }, cfg.defines)
40+
test.excludes({ "PROJECT_1_INTERFACE" }, cfg.defines)
41+
end
3642

37-
local cfg = test.getconfig(prj, "Debug", "x86")
38-
test.isequal({ "PROJECT_1_PUBLIC", "PROJECT_1_PRIVATE" }, cfg.defines) -- Interface defines should not be included
39-
end
4043

4144
---
4245
-- Tests to ensure that the PUBLIC and INTERFACE usages are correctly applied to the dependent project
4346
---
44-
function suite.twoprojects_withdependency()
45-
prj2 = project "MyProject2"
46-
usage "PUBLIC"
47-
defines { "PROJECT_2_PUBLIC" }
48-
usage "INTERFACE"
49-
defines { "PROJECT_2_INTERFACE" }
50-
usage "PRIVATE"
51-
defines { "PROJECT_2_PRIVATE" }
52-
53-
uses { "MyProject1" }
47+
function suite.twoprojects_withdependency()
48+
prj2 = project "MyProject2"
49+
usage "PUBLIC"
50+
defines { "PROJECT_2_PUBLIC" }
51+
usage "INTERFACE"
52+
defines { "PROJECT_2_INTERFACE" }
53+
usage "PRIVATE"
54+
defines { "PROJECT_2_PRIVATE" }
55+
56+
uses { "MyProject1" }
57+
58+
p.oven.bake()
5459

55-
p.oven.bake()
60+
local cfg = test.getconfig(prj2, "Debug", "x86")
5661

57-
local cfg = test.getconfig(prj2, "Debug", "x86")
62+
test.contains({ "PROJECT_2_PUBLIC", "PROJECT_1_PUBLIC", "PROJECT_1_INTERFACE", "PROJECT_2_PRIVATE" }, cfg.defines)
63+
test.excludes({ "PROJECT_1_PRIVATE" }, cfg.defines)
64+
end
5865

59-
-- Order is important here, as the test treats different order as a failure
60-
-- However, the order of the defines is not important in the actual implementation
61-
test.isequal({ "PROJECT_2_PUBLIC", "PROJECT_1_PUBLIC", "PROJECT_1_INTERFACE", "PROJECT_2_PRIVATE" }, cfg.defines) -- Interface defines should not be included
62-
end
6366

6467
---
6568
-- Tests to ensure that the PUBLIC and INTERFACE usages are correctly applied to the dependent project via a transitve dependency
6669
---
67-
function suite.multipleprojects_transitivedependency()
68-
prj2 = project "MyProject2"
69-
usage "PUBLIC"
70-
defines { "PROJECT_2_PUBLIC" }
71-
uses { "MyProject1" }
72-
usage "INTERFACE"
73-
defines { "PROJECT_2_INTERFACE" }
74-
usage "PRIVATE"
75-
defines { "PROJECT_2_PRIVATE" }
76-
77-
prj3 = project "MyProject3"
78-
uses { "MyProject2" }
79-
defines { "PROJECT_3" }
70+
function suite.multipleprojects_transitivedependency()
71+
prj2 = project "MyProject2"
72+
usage "PUBLIC"
73+
defines { "PROJECT_2_PUBLIC" }
74+
uses { "MyProject1" }
75+
usage "INTERFACE"
76+
defines { "PROJECT_2_INTERFACE" }
77+
usage "PRIVATE"
78+
defines { "PROJECT_2_PRIVATE" }
8079

81-
p.oven.bake()
80+
prj3 = project "MyProject3"
81+
uses { "MyProject2" }
82+
defines { "PROJECT_3" }
8283

83-
local cfg = test.getconfig(prj3, "Debug", "x86")
84+
p.oven.bake()
85+
86+
local cfg = test.getconfig(prj3, "Debug", "x86")
87+
88+
test.isequal({ "PROJECT_3", "PROJECT_1_PUBLIC", "PROJECT_1_INTERFACE", "PROJECT_2_PUBLIC", "PROJECT_2_INTERFACE" }, cfg.defines)
89+
test.excludes({ "PROJECT_1_PRIVATE", "PROJECT_2_PRIVATE" }, cfg.defines)
90+
end
8491

85-
-- Order is important here, as the test treats different order as a failure
86-
-- However, the order of the defines is not important in the actual implementation
87-
test.isequal({ "PROJECT_3", "PROJECT_1_PUBLIC", "PROJECT_1_INTERFACE", "PROJECT_2_PUBLIC", "PROJECT_2_INTERFACE" }, cfg.defines)
88-
end
8992

9093
---
91-
-- Test to ensure that usages with custom names
94+
-- Test to ensure that usages with custom names are correctly applied to the dependent project
9295
---
93-
function suite.twoprojects_customname()
94-
prj2 = project "MyProject2"
95-
uses { "Custom" }
96-
usage "Custom"
97-
defines { "MY_CUSTOM_USAGE" }
96+
function suite.twoprojects_customname()
97+
prj2 = project "MyProject2"
98+
uses { "Custom" }
99+
usage "Custom"
100+
defines { "MY_CUSTOM_USAGE" }
98101

99-
p.oven.bake()
102+
p.oven.bake()
100103

101-
local cfg = test.getconfig(prj2, "Debug", "x86")
104+
local cfg = test.getconfig(prj2, "Debug", "x86")
102105

103-
-- Order is important here, as the test treats different order as a failure
104-
-- However, the order of the defines is not important in the actual implementation
105-
test.isequal({ "MY_CUSTOM_USAGE" }, cfg.defines)
106-
end
106+
test.contains({ "MY_CUSTOM_USAGE" }, cfg.defines)
107+
end
107108

108109

109-
function suite.multipleprojects_customname_transitive()
110-
prj2 = project "MyProject2"
111-
usage "Custom"
112-
defines { "MY_CUSTOM_USAGE" }
113-
114-
prj3 = project "MyProject3"
115-
usage "Custom2"
116-
uses { "Custom" }
110+
---
111+
-- Test to ensure that usages with custom names are correctly applied to the dependent project via a transitve dependency
112+
---
113+
function suite.multipleprojects_customname_transitive()
114+
prj2 = project "MyProject2"
115+
usage "Custom"
116+
defines { "MY_CUSTOM_USAGE" }
117117

118-
prj4 = project "MyProject4"
119-
uses { "Custom2" }
118+
prj3 = project "MyProject3"
119+
usage "Custom2"
120+
uses { "Custom" }
120121

121-
p.oven.bake()
122+
prj4 = project "MyProject4"
123+
uses { "Custom2" }
122124

123-
local cfg = test.getconfig(prj4, "Debug", "x86")
125+
p.oven.bake()
124126

125-
-- Order is important here, as the test treats different order as a failure
126-
-- However, the order of the defines is not important in the actual implementation
127-
test.isequal({ "MY_CUSTOM_USAGE" }, cfg.defines) -- Interface defines should not be included
128-
end
127+
local cfg = test.getconfig(prj4, "Debug", "x86")
129128

129+
test.contains({ "MY_CUSTOM_USAGE" }, cfg.defines)
130+
end
130131

131-
function suite.twoprojects_noprojectinheritance()
132-
-- Ensure that no variables come in from the default project scope
133132

134-
prj2 = project "MyProject2"
135-
defines { "IMPLICIT_PRIVATE_DEFINE" }
136-
usage "PUBLIC"
137-
defines { "PROJECT_2_PUBLIC" }
133+
---
134+
-- Test to ensure that usages do not inherit from the default project scope
135+
---
136+
function suite.twoprojects_noprojectinheritance()
137+
prj2 = project "MyProject2"
138+
defines { "IMPLICIT_PRIVATE_DEFINE" }
139+
usage "PUBLIC"
140+
defines { "PROJECT_2_PUBLIC" }
138141

139-
prj3 = project "MyProject3"
140-
uses { "MyProject2" }
142+
prj3 = project "MyProject3"
143+
uses { "MyProject2" }
141144

142-
p.oven.bake()
145+
p.oven.bake()
143146

144-
local cfg = test.getconfig(prj3, "Debug", "x86")
147+
local cfg = test.getconfig(prj3, "Debug", "x86")
145148

146-
-- Ensure that the implicit scope's define is not included
147-
test.isequal({ "PROJECT_2_PUBLIC" }, cfg.defines)
148-
end
149+
test.contains({ "PROJECT_2_PUBLIC" }, cfg.defines)
150+
test.excludes({ "IMPLICIT_PRIVATE_DEFINE" }, cfg.defines)
151+
end

website/docs/usage.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Specifies a reusable block of configuration to be consumed at a later point.
22

33
```lua
44
usage 'MyUsage'
5-
defines { 'MY_DEFINE' }
65
```
76

87
The `usage` API is used to define configuration to be consumed by the `uses` API. Usages must have unique names, except for magic usage block names (as described below).

website/docs/uses.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,36 @@ uses { "ProjectA" }
66

77
The `uses` API is used to consume `usage` blocks from within a project. The `usage` blocks are case sensitive.
88

9-
### Usage resolve priority ###
9+
### Usage Resolution Priority ###
1010

1111
1. `PUBLIC` and `INTERFACE` usage scopes within a project of the corresponding name.
1212
2. `usage` blocks with the corresponding name in any scopes.
1313

14-
Note: If there are duplicate usage blocks with the same resolved name, the selected usage block is unspecified. `usage` blocks should have unique names if they are not specified as `PUBLIC`, `PRIVATE`, or `INTERFACE`. If `links` or `linkoptions` are defined within a usage block, it is recommended that `linkgroups` is also turned on.
14+
Note: If there are duplicate usage blocks with the same resolved name, the selected usage block is unspecified. `usage` blocks should have unique names if they are not specified as `PUBLIC`, `PRIVATE`, or `INTERFACE`.
1515

1616
### Applies To ###
1717

1818
Projects and usage configurations.
1919

20+
### Examples ###
21+
22+
Demonstration of using `uses`. When specifying a `uses` matching a project name containing a `PUBLIC` or `INTERFACE` usage block, the `uses` statement will match against that. If a `project` with a `PUBLIC` or `INTERFACE` usage block
23+
cannot be found, then it will fall back to searching all `usage` blocks to match the provided name, as described above.
24+
25+
```lua
26+
project "MyProject"
27+
usage "PUBLIC"
28+
defines { "PUBLIC_DEF" }
29+
usage "Custom"
30+
defines { "CUSTOM_DEF" }
31+
32+
project "MyExe"
33+
uses { "MyProject" }
34+
35+
project "MyDLL"
36+
uses { "Custom" }
37+
```
38+
2039
### See Also ###
2140

22-
* [linkgroups](linkgroups.md)
2341
* [usage](usage.md)

0 commit comments

Comments
 (0)