1111from buildbot .steps .worker import CompositeStepMixin
1212from twisted .internet import defer
1313
14- __all__ = [' CleanOldFiles' , ' CTest' , ' FileUploadIfNotExist' , ' SetPropertiesFromCMakeCache' ]
14+ __all__ = [" CleanOldFiles" , " CTest" , " FileUploadIfNotExist" , " SetPropertiesFromCMakeCache" ]
1515
1616
1717class SetPropertiesFromCMakeCache (CompositeStepMixin , BuildStep ):
18- name = ' set-properties-from-cmake-cache'
18+ name = " set-properties-from-cmake-cache"
1919
20- renderables = [' props' ]
20+ renderables = [" props" ]
2121
2222 # Parsing with regex is safe because the CMakeCache.txt format
2323 # hasn't changed since 2006, according to `git blame`. Caveat:
2424 # they have backwards compatibility code for parsing entries with
2525 # quoted names and missing types. We don't bother with that here.
2626 _cache_re = re .compile (
27- r'''
27+ r"""
2828 ^(?!//|\#) # Ignore comment lines.
2929 ([^:=]+?) # Get the variable name,
3030 (-ADVANCED)? # which might be marked as advanced,
3131 :([^=]*) # and will have a type.
3232 =(.*)$ # The value extends through the end of the line.
33- ''' ,
33+ """ ,
3434 re .VERBOSE ,
3535 )
3636
@@ -45,22 +45,22 @@ def run(self):
4545 if not self .props :
4646 return SUCCESS
4747
48- log = yield self .addLog (' props' )
48+ log = yield self .addLog (" props" )
4949
50- cache = yield self .getFileContentFromWorker (f' { self .workdir } /CMakeCache.txt' , abandonOnFailure = True )
50+ cache = yield self .getFileContentFromWorker (f" { self .workdir } /CMakeCache.txt" , abandonOnFailure = True )
5151 cache = self ._parse_cache (cache )
5252
5353 to_find = set (self .props )
5454 found = to_find & cache .keys ()
5555 not_found = to_find - cache .keys ()
5656
5757 for key in found :
58- log .addStdout (f' { key } ={ cache [key ]} \n ' )
59- self .setProperty (key , cache [key ], ' CMakeCache' )
58+ log .addStdout (f" { key } ={ cache [key ]} \n " )
59+ self .setProperty (key , cache [key ], " CMakeCache" )
6060
6161 for key in not_found :
62- log .addStderr (f' Cache entry not found: { key } \n ' )
63- self .setProperty (key , '' , ' CMakeCache' )
62+ log .addStderr (f" Cache entry not found: { key } \n " )
63+ self .setProperty (key , "" , " CMakeCache" )
6464
6565 yield log .finish ()
6666 return WARNINGS if not_found else SUCCESS
@@ -71,7 +71,7 @@ def _parse_cache(self, cache: str):
7171 match = self ._cache_re .match (entry )
7272 if match :
7373 key , is_advanced , ty , value = match .groups ()
74- if ty == ' BOOL' and self .normalize_bools :
74+ if ty == " BOOL" and self .normalize_bools :
7575 value = self ._normalize_bools (value )
7676 if self .expand_lists :
7777 value = self ._expand_lists (value )
@@ -80,24 +80,24 @@ def _parse_cache(self, cache: str):
8080
8181 @staticmethod
8282 def _expand_lists (value : str ):
83- if ';' in value :
84- return value .split (';' )
83+ if ";" in value :
84+ return value .split (";" )
8585 return value
8686
8787 @staticmethod
8888 def _normalize_bools (value : str ):
8989 value = value .upper ().strip ()
90- if value .endswith (' -NOTFOUND' ):
91- return '0'
92- if value in {'1' , 'ON' , ' YES' , ' TRUE' , 'Y' }:
93- return '1'
94- if value in {'0' , ' OFF' , 'NO' , ' FALSE' , 'N' , ' IGNORE' , ' NOTFOUND' }:
95- return '0'
90+ if value .endswith (" -NOTFOUND" ):
91+ return "0"
92+ if value in {"1" , "ON" , " YES" , " TRUE" , "Y" }:
93+ return "1"
94+ if value in {"0" , " OFF" , "NO" , " FALSE" , "N" , " IGNORE" , " NOTFOUND" }:
95+ return "0"
9696 raise ValueError (f'Invalid CMake bool "{ value } "' )
9797
9898
9999class CleanOldFiles (BuildStep ):
100- name = ' clean-old'
100+ name = " clean-old"
101101
102102 def __init__ (self , * , groupfn , workdir , keep = 1 , ** kwargs ):
103103 super ().__init__ (** kwargs )
@@ -107,7 +107,7 @@ def __init__(self, *, groupfn, workdir, keep=1, **kwargs):
107107
108108 @defer .inlineCallbacks
109109 def run (self ):
110- stdio = yield self .addLog (' stdio' )
110+ stdio = yield self .addLog (" stdio" )
111111 status = SUCCESS
112112
113113 # Group files in workdir together using the supplied function.
@@ -123,9 +123,9 @@ def run(self):
123123 for file in group [self .keep :]:
124124 try :
125125 file .unlink ()
126- stdio .addStdout (f' Removed: { file .resolve ()} \n ' )
126+ stdio .addStdout (f" Removed: { file .resolve ()} \n " )
127127 except (FileNotFoundError , OSError ) as e :
128- stdio .addStderr (f' Could not delete { file .resolve ()} : { e } \n ' )
128+ stdio .addStderr (f" Could not delete { file .resolve ()} : { e } \n " )
129129 status = FAILURE
130130
131131 yield stdio .finish ()
@@ -137,13 +137,13 @@ def run(self):
137137# filename contains (eg) a git commit or SHA that uniquely
138138# identifies the file version.
139139class FileUploadIfNotExist (FileUpload ):
140- name = ' file-upload-if-not-exist'
140+ name = " file-upload-if-not-exist"
141141
142142 @defer .inlineCallbacks
143143 def run (self ):
144144 masterdest = os .path .expanduser (self .masterdest )
145145 if os .path .isfile (masterdest ) and os .path .getsize (masterdest ) > 0 :
146- stdio = yield self .addLog (' stdio' )
146+ stdio = yield self .addLog (" stdio" )
147147 stdio .addStdout (f"File { repr (masterdest )} already exists on dest, skipping upload!" )
148148 yield stdio .finish ()
149149 return SUCCESS
@@ -153,7 +153,7 @@ def run(self):
153153
154154
155155class CTest (ShellMixin , CompositeStepMixin , BuildStep ):
156- name = ' ctest'
156+ name = " ctest"
157157
158158 def __init__ (
159159 self ,
@@ -168,52 +168,52 @@ def __init__(
168168 test_dir = None ,
169169 ** kwargs ,
170170 ):
171- kwargs [' command' ] = [
172- ' ctest' ,
171+ kwargs [" command" ] = [
172+ " ctest" ,
173173 # Note, jobs may be a renderable, don't explicitly convert to str
174- * ([' --parallel' , jobs ] if jobs else []),
175- * ([' --tests-regex' , '|' .join (tests )] if tests else []),
176- * ([' --exclude-regex' , '|' .join (exclude_tests )] if exclude_tests else []),
177- * ([' --label-regex' , '|' .join (labels )] if labels else []),
178- * ([' --label-exclude' , '|' .join (exclude_labels )] if exclude_labels else []),
179- * ([' --test-dir' , test_dir ] if test_dir else []),
174+ * ([" --parallel" , jobs ] if jobs else []),
175+ * ([" --tests-regex" , "|" .join (tests )] if tests else []),
176+ * ([" --exclude-regex" , "|" .join (exclude_tests )] if exclude_tests else []),
177+ * ([" --label-regex" , "|" .join (labels )] if labels else []),
178+ * ([" --label-exclude" , "|" .join (exclude_labels )] if exclude_labels else []),
179+ * ([" --test-dir" , test_dir ] if test_dir else []),
180180 # We always want output from performance tests
181- * ([' --verbose' ] if labels and ' performance' in labels else []),
182- ' --output-on-failure' ,
183- ' --test-action' ,
184- ' Test' ,
185- ' --no-compress-output' ,
181+ * ([" --verbose" ] if labels and " performance" in labels else []),
182+ " --output-on-failure" ,
183+ " --test-action" ,
184+ " Test" ,
185+ " --no-compress-output" ,
186186 ]
187187 assert (build_config is None ) ^ (preset is None ), "You must pass either build_config or preset, but not both"
188188 if build_config :
189- kwargs [' command' ] += [' --build-config' , build_config ]
189+ kwargs [" command" ] += [" --build-config" , build_config ]
190190 if preset :
191- kwargs [' command' ] += [' --preset' , preset ]
191+ kwargs [" command" ] += [" --preset" , preset ]
192192
193193 kwargs = self .setupShellMixin (kwargs )
194194 super ().__init__ (** kwargs )
195195
196196 @defer .inlineCallbacks
197197 def run (self ):
198198 # Remove any leftover log files (if they exist)
199- yield self .runRmdir (f' { self .workdir } /Testing' , abandonOnFailure = False )
199+ yield self .runRmdir (f" { self .workdir } /Testing" , abandonOnFailure = False )
200200
201201 # Run CTest
202202 cmd = yield self .makeRemoteShellCommand ()
203203 yield self .runCommand (cmd )
204204
205205 # Upload the XML log from the CTest run
206- xml_results = yield self .runGlob (f' { self .workdir } /Testing/*/*.xml' )
206+ xml_results = yield self .runGlob (f" { self .workdir } /Testing/*/*.xml" )
207207 if len (xml_results ) != 1 :
208- raise BuildStepFailed (f' Expected to find a single XML file. Got: { xml_results } ' )
208+ raise BuildStepFailed (f" Expected to find a single XML file. Got: { xml_results } " )
209209
210210 ctest_log = yield self .getFileContentFromWorker (xml_results [0 ], abandonOnFailure = True )
211211
212212 # Parse the result, collecting test failures into more convenient logs.
213213 root = Xml .fromstring (ctest_log )
214214
215215 for test in root .findall (".//Test[@Status='failed']" ):
216- log = yield self .addLog (test .findtext (' Name' ))
216+ log = yield self .addLog (test .findtext (" Name" ))
217217 self .write_xml (
218218 test ,
219219 ("./Results/NamedMeasurement[@name='Environment']/Value" , log .addHeader ),
@@ -225,7 +225,7 @@ def run(self):
225225
226226 skipped = root .findall (".//Test[@Status='notrun']" )
227227 if skipped :
228- log = yield self .addLog (' skipped' )
228+ log = yield self .addLog (" skipped" )
229229 for test in skipped :
230230 log .addStdout (f'{ test .findtext ("Name" )} \n ' )
231231 self .write_xml (
@@ -235,7 +235,7 @@ def run(self):
235235 ("./Results/Measurement/Value" , log .addStdout ),
236236 indent = 2 ,
237237 )
238- log .addStdout (' \n ' )
238+ log .addStdout (" \n " )
239239 yield log .finish ()
240240
241241 return cmd .results ()
@@ -249,10 +249,10 @@ def write_xml(self, test, *sections, indent=0):
249249 @staticmethod
250250 def clean_text (text , * , indent = 0 ):
251251 indent = " " * indent
252- text = text or ''
253- if ' Regex=[' in text : # clean up annoying CTest output
254- text = text .replace (' \n ]' , ' ]\n ' )
252+ text = text or ""
253+ if " Regex=[" in text : # clean up annoying CTest output
254+ text = text .replace (" \n ]" , " ]\n " )
255255 text = text .strip ()
256- text = text .replace (' \n ' , f' \n { indent } ' )
257- text = f' { indent } { text } \n '
256+ text = text .replace (" \n " , f" \n { indent } " )
257+ text = f" { indent } { text } \n "
258258 return text
0 commit comments