@@ -50,6 +50,8 @@ def parseMATCH(self):
5050 self .unknown = True
5151 else :
5252 self .unknown = False
53+ if self .value and self .unknown :
54+ raise ValueError ("Runtime feature \" " + token + "\" evaluated to True in build-only" )
5355
5456 def parseAND (self ):
5557 self .parseNOT ()
@@ -95,124 +97,43 @@ def parseAll(self):
9597
9698class TestE2EExpr (unittest .TestCase ):
9799 def test_basic (self ):
100+ BuildOnly = True
101+ BuildAndRun = False
102+ RequiresDirective = True
103+ UnsupportedDirective = False
104+ RegularEval = lambda expr , features : E2EExpr .evaluate (expr , features , BuildAndRun )
105+ RequiresBuildEval = lambda expr , features : E2EExpr .evaluate (expr , features , BuildOnly , RequiresDirective )
106+ UnsupportedBuildEval = lambda expr , features : E2EExpr .evaluate (expr , features , BuildOnly , UnsupportedDirective )
98107 # Non build-only expressions should work the same
99- self .assertTrue (E2EExpr .evaluate ("linux" , {"linux" , "rt_feature" }, False ))
100- self .assertTrue (E2EExpr .evaluate ("rt_feature" , {"linux" , "rt_feature" }, False ))
101- self .assertFalse (
102- E2EExpr .evaluate (
103- "another_aspect && rt_feature" , {"linux" , "rt_feature" }, False
104- )
105- )
108+ self .assertTrue (RegularEval ("linux" , {"linux" , "rt_feature" }))
109+ self .assertTrue (RegularEval ("rt_feature" , {"linux" , "rt_feature" }))
110+ self .assertFalse (RegularEval ("rt_feature1 && rt_feature2" , {"linux" , "rt_feature1" }))
106111 # build-only expressions with no unknowns should work the same
107- self .assertTrue (
108- E2EExpr .evaluate ("linux" , {"linux" }, True , final_unknown_value = False )
109- )
110- self .assertFalse (
111- E2EExpr .evaluate (
112- "linux && windows" , {"linux" }, True , final_unknown_value = True
113- )
114- )
115- self .assertTrue (
116- E2EExpr .evaluate (
117- "!(windows || zstd)" , {"linux" }, True , final_unknown_value = False
118- )
119- )
112+ self .assertTrue (UnsupportedBuildEval ("linux" , {"linux" }))
113+ self .assertFalse (RequiresBuildEval ("linux && windows" , {"linux" }))
114+ self .assertTrue (UnsupportedBuildEval ("!(windows || zstd)" , {"linux" }))
120115 # build-only expressions where unknown affects the resulting value
121- self .assertTrue (
122- E2EExpr .evaluate ("rt_feature" , {}, True , final_unknown_value = True )
123- )
124- self .assertFalse (
125- E2EExpr .evaluate ("rt_feature" , {}, True , final_unknown_value = False )
126- )
127- self .assertTrue (
128- E2EExpr .evaluate (
129- "rt_feature" , {"rt_feature" }, True , final_unknown_value = True
130- )
131- )
132- self .assertFalse (
133- E2EExpr .evaluate (
134- "rt_feature" , {"rt_feature" }, True , final_unknown_value = False
135- )
136- )
137- self .assertFalse (
138- E2EExpr .evaluate ("!rt_feature" , {}, True , final_unknown_value = False )
139- )
140- self .assertFalse (
141- E2EExpr .evaluate ("!!rt_feature" , {}, True , final_unknown_value = False )
142- )
143- self .assertTrue (
144- E2EExpr .evaluate (
145- "windows || rt_feature" , {"linux" }, True , final_unknown_value = True
146- )
147- )
148- self .assertFalse (
149- E2EExpr .evaluate (
150- "windows || rt_feature" , {"linux" }, True , final_unknown_value = False
151- )
152- )
153- self .assertTrue (
154- E2EExpr .evaluate (
155- "linux && rt_feature" , {"linux" }, True , final_unknown_value = True
156- )
157- )
158- self .assertFalse (
159- E2EExpr .evaluate (
160- "linux && rt_feature" , {"linux" }, True , final_unknown_value = False
161- )
162- )
163- self .assertTrue (
164- E2EExpr .evaluate (
165- "linux && !(windows || rt_feature)" ,
166- {"linux" },
167- True ,
168- final_unknown_value = True ,
169- )
170- )
171- self .assertFalse (
172- E2EExpr .evaluate (
173- "linux && !(windows || rt_feature)" ,
174- {"linux" },
175- True ,
176- final_unknown_value = False ,
177- )
178- )
116+ self .assertTrue (RequiresBuildEval ("rt_feature" , {}))
117+ self .assertFalse (UnsupportedBuildEval ("rt_feature" , {}))
118+ self .assertFalse (UnsupportedBuildEval ("!rt_feature" , {}))
119+ self .assertTrue (RequiresBuildEval ("windows || rt_feature" , {"linux" }))
120+ self .assertFalse (UnsupportedBuildEval ("windows || rt_feature" , {"linux" }))
121+ self .assertTrue (RequiresBuildEval ("linux && rt_feature" , {"linux" }))
122+ self .assertFalse (UnsupportedBuildEval ("linux && rt_feature" , {"linux" }))
123+ self .assertTrue (RequiresBuildEval ("linux && !(zstd || rt_feature)" , {"linux" }))
124+ self .assertFalse (UnsupportedBuildEval ("linux && !(zstd || rt_feature)" , {"linux" }))
179125 # build-only expressions where unknown does not affect the resulting value
180- self .assertTrue (
181- E2EExpr .evaluate (
182- "linux || rt_feature" , {"linux" }, True , final_unknown_value = True
183- )
184- )
185- self .assertTrue (
186- E2EExpr .evaluate (
187- "linux || rt_feature" , {"linux" }, True , final_unknown_value = False
188- )
189- )
190- self .assertFalse (
191- E2EExpr .evaluate (
192- "windows && rt_feature" , {"linux" }, True , final_unknown_value = True
193- )
194- )
195- self .assertFalse (
196- E2EExpr .evaluate (
197- "windows && rt_feature" , {"linux" }, True , final_unknown_value = False
198- )
199- )
200- self .assertFalse (
201- E2EExpr .evaluate (
202- "linux && (windows && rt_feature)" ,
203- {"linux" },
204- True ,
205- final_unknown_value = True ,
206- )
207- )
208- self .assertFalse (
209- E2EExpr .evaluate (
210- "linux && (windows && rt_feature)" ,
211- {"linux" },
212- True ,
213- final_unknown_value = False ,
214- )
215- )
126+ self .assertTrue (RequiresBuildEval ("linux || rt_feature" , {"linux" }))
127+ self .assertTrue (UnsupportedBuildEval ("linux || rt_feature" , {"linux" }))
128+ self .assertFalse (RequiresBuildEval ("windows && rt_feature" , {"linux" }))
129+ self .assertFalse (UnsupportedBuildEval ("windows && rt_feature" , {"linux" }))
130+ self .assertFalse (RequiresBuildEval ("linux && (vulkan && rt_feature)" , {"linux" }))
131+ self .assertFalse (UnsupportedBuildEval ("linux && (vulkan && rt_feature)" , {"linux" }))
132+ # runtime feature is present in build-only
133+ with self .assertRaises (ValueError ):
134+ RequiresBuildEval ("rt_feature" , {"rt_feature" })
135+ with self .assertRaises (ValueError ):
136+ UnsupportedBuildEval ("rt_feature" , {"rt_feature" })
216137
217138
218139if __name__ == "__main__" :
0 commit comments