12
12
13
13
import platform
14
14
15
+ from typing import Optional
16
+ from products .product import Product
15
17
from swift_build_support .swift_build_support import build_graph
16
18
17
19
@@ -23,14 +25,14 @@ class ProductPipeline(object):
23
25
24
26
This class is meant to just be state.
25
27
"""
26
- def __init__ (self , should_run_epilogue_operations , identity , is_impl ):
28
+ def __init__ (self , should_run_epilogue_operations : bool , identity : int , is_impl : bool ):
27
29
assert isinstance (identity , int )
28
30
self .identity = identity
29
- self .products = []
31
+ self .products : list [ tuple [ type [ Product ], bool ]] = []
30
32
self .is_impl = is_impl
31
33
self .should_run_epilogue_operations = should_run_epilogue_operations
32
34
33
- def append (self , product , is_enabled ):
35
+ def append (self , product : type [ Product ] , is_enabled : bool ):
34
36
self .products .append ((product , is_enabled ))
35
37
36
38
def finalize (self ):
@@ -41,7 +43,7 @@ def finalize(self):
41
43
def __iter__ (self ):
42
44
return iter (self .products )
43
45
44
- def __getitem__ (self , i ):
46
+ def __getitem__ (self , i ) -> tuple [ type [ Product ], bool ] :
45
47
return self .products [i ]
46
48
47
49
def __len__ (self ):
@@ -65,9 +67,9 @@ class ProductPipelineListBuilder(object):
65
67
def __init__ (self , args ):
66
68
self .args = args
67
69
self .current_count = 0
68
- self .current_pipeline = None
70
+ self .current_pipeline : Optional [ ProductPipeline ] = None
69
71
self .is_current_pipeline_impl = False
70
- self .pipeline_list = []
72
+ self .pipeline_list : list [ ProductPipeline ] = []
71
73
72
74
def begin_pipeline (self ):
73
75
if self .current_pipeline is not None :
@@ -93,14 +95,14 @@ def reset(self):
93
95
self .is_current_pipeline_impl = False
94
96
self .pipelinst_list = []
95
97
96
- def add_product (self , product_cls , is_enabled ):
98
+ def add_product (self , product_cls : type [ Product ] , is_enabled : bool ):
97
99
"""Add a non-impl product to the current pipeline begin constructed"""
98
100
assert self .current_pipeline is not None
99
101
assert not self .is_current_pipeline_impl
100
102
assert not product_cls .is_build_script_impl_product ()
101
103
self .current_pipeline .append (product_cls , is_enabled )
102
104
103
- def add_impl_product (self , product_cls , is_enabled ):
105
+ def add_impl_product (self , product_cls : type [ Product ] , is_enabled : bool ):
104
106
"""Add an impl product to the current pipeline begin constructed"""
105
107
assert self .current_pipeline is not None
106
108
assert self .is_current_pipeline_impl
@@ -109,14 +111,16 @@ def add_impl_product(self, product_cls, is_enabled):
109
111
110
112
def infer (self ):
111
113
products_to_generation_index = {}
112
- enabled_products = set ()
113
- inferred_pipeline_list = []
114
+ enabled_products : set [ type [ Product ]] = set ()
115
+ inferred_pipeline_list : list [ list [ Optional [ type [ Product ]]]] = []
114
116
last_impl_pipeline_index = None
117
+
115
118
for i in range (len (self .pipeline_list )):
116
- pipeline = self .pipeline_list [i ]
119
+ pipeline : ProductPipeline = self .pipeline_list [i ]
117
120
if pipeline .is_impl :
118
121
last_impl_pipeline_index = i
119
- final_pipeline = []
122
+
123
+ final_pipeline : list [Optional [type [Product ]]] = []
120
124
for pipeline_i in range (len (pipeline )):
121
125
(p , is_enabled ) = pipeline [pipeline_i ]
122
126
# Make sure p has not been added multiple times to the builder.
@@ -137,11 +141,11 @@ def infer(self):
137
141
p .get_dependencies ()))
138
142
139
143
for i in range (len (inferred_pipeline_list )):
140
- pipeline = inferred_pipeline_list [i ]
144
+ inferred_pipeline = inferred_pipeline_list [i ]
141
145
142
146
# Filter out any of the pipelines that before inference were not
143
147
# selected.
144
- enabled_pipeline = [p for p in pipeline if p is not None ]
148
+ enabled_pipeline : list = [p for p in inferred_pipeline if p is not None ]
145
149
146
150
if self .args .verbose_build :
147
151
print ("-- Build Graph Inference --" )
@@ -170,18 +174,18 @@ def infer(self):
170
174
inferred_pipeline_list [gen_offset ][index ] = p
171
175
172
176
filtered_results = []
173
- for pipeline in inferred_pipeline_list :
174
- filtered_results .append ([p for p in pipeline if p is not None ])
177
+ for inferred_pipeline in inferred_pipeline_list :
178
+ filtered_results .append ([p for p in inferred_pipeline if p is not None ])
175
179
176
180
if self .args .verbose_build :
177
181
print ("Final Build Order:" )
178
- for pipeline in filtered_results :
179
- for p in pipeline :
182
+ for filtered_pipeline in filtered_results :
183
+ for p in filtered_pipeline :
180
184
print (" {}" .format (p .product_name ()))
181
185
182
186
return (filtered_results , last_impl_pipeline_index )
183
187
184
- def finalize (self , shouldInfer ):
188
+ def finalize (self , shouldInfer : bool ):
185
189
"""Product a final schedule and return a list of our product pipelines. Resets
186
190
the builder when done so is a consuming operation.
187
191
"""
0 commit comments