@@ -99,54 +99,82 @@ def getBOLTCmakeBuildFactory(
9999 # Individual markers to skip either in-tree or out-of-tree tests.
100100 skipInTree = ".llvm-bolt.skip.in-tree"
101101 skipOutOfTree = ".llvm-bolt.skip.out-of-tree"
102+ boltNew = "bin/llvm-bolt.new"
103+ boltOld = "bin/llvm-bolt.old"
102104
103105 f .addSteps ([
106+ # Cleanup binaries and markers from previous NFC-mode runs.
107+ ShellCommand (
108+ name = 'clean-nfc-check' ,
109+ command = (
110+ f"rm -f { boltNew } { boltOld } { hasSrcChanges } { skipInTree } { skipOutOfTree } ; "
111+ ),
112+ description = ('Cleanup for NFC-Mode testing' ),
113+ descriptionDone = ["NFC-Mode cleanup" ],
114+ haltOnFailure = False ,
115+ flunkOnFailure = False ,
116+ env = env ),
117+ # Build the current and previous revision of llvm-bolt.
104118 ShellCommand (
105119 name = 'nfc-check-setup' ,
106120 command = [
107- f"../{ f .monorepo_dir } /bolt/utils/nfc-check-setup.py" ,
121+ f"../{ f .monorepo_dir } /bolt/utils/nfc-check-setup.py" ,
108122 "--switch-back" ,
109123 "--check-bolt-sources"
110124 ],
111125 description = ('Setup NFC testing' ),
112126 descriptionDone = ["NFC-Mode setup" ],
113127 warnOnFailure = True ,
128+ warnOnWarnings = True ,
129+ decodeRC = {0 : SUCCESS , 1 : WARNINGS },
114130 haltOnFailure = False ,
115131 flunkOnFailure = False ,
116132 env = env ),
133+ # Validate that NFC-mode comparison is meaningful by checking:
134+ # - the old and new binaries exist
135+ # - no unique IDs are embedded in the binaries
136+ # Warns but does not fail when validation fails.
117137 ShellCommand (
118138 name = 'nfc-check-validation' ,
119139 command = (
120- "info=$(bin/llvm-bolt.new --version | grep 'BOLT revision' "
140+ f"( ! [ -f { boltNew } ] || ! [ -f { boltOld } ] ) && "
141+ "{ printf 'NFC-Mode WARNING: old/new files not present. Tests will run.'; return 2; }; "
142+ f"uids=$({ boltNew } --version | grep 'BOLT revision' "
121143 "| grep -q '<unknown>' || echo 'bolt-revision'); "
122- "info=$info $(readelf --notes bin/llvm-bolt.new "
144+ f"uids=$uids $(readelf --notes { boltNew } "
123145 "| grep -q 'Build ID:' && echo ' GNU-build-id'); "
124- "info=$(echo \" $info\" | sed 's/^ //'); "
125- "[ ! -z \" $info\" ] || return 0 && "
126- "(printf \" NFC-Mode WARNING: unique IDs found in binaries ($info)"
127- ". This means tests will run at all times.\" ; return 2)"
146+ "uids=$(echo \" $uids\" | sed 's/^ //'); "
147+ f"[ $(readelf --note { boltNew } { boltOld } | grep 'Build ID' | uniq -c | wc -l) -eq 1 ] "
148+ "&& extra='Identical build-ids.' || extra='Tests will run.'; "
149+ "[ ! -z \" $uids\" ] || return 0 && "
150+ "{ printf \" NFC-Mode WARNING: unique IDs found in binaries ($uids). $extra\" ; return 2; }"
128151 ),
129152 description = ('Check that nfc-mode works as intended when '
130153 'comparing with the previous commit.' ),
131154 haltOnFailure = False ,
132155 warnOnFailure = True ,
133156 warnOnWarnings = True ,
134157 decodeRC = {0 : SUCCESS , 1 : FAILURE , 2 : WARNINGS },
135- descriptionDone = ["NFC-Mode unique IDs in binaries " ],
158+ descriptionDone = ["NFC-Mode Validation " ],
136159 env = env ),
160+ # Compare the current and previous llvm-bolt binaries. If they are
161+ # identical, skip the following tests. If relevant source code
162+ # changes are detected, still run the in-tree tests.
137163 ShellCommand (
138164 name = 'nfc-check-bolt-different' ,
139165 command = (
140- f'rm -f { skipInTree } { skipOutOfTree } ; '
141- f'cmp -s bin/llvm-bolt.old bin/llvm-bolt.new && ('
166+ f'cmp -s { boltNew } { boltOld } && ('
142167 f'touch { skipInTree } ; touch { skipOutOfTree } ); '
143- f'[ -f { hasSrcChanges } ] && rm -f { skipInTree } ;'
144- f'rm -f { hasSrcChanges } ; '
168+ f'[ -f { hasSrcChanges } ] && rm -f { skipInTree } ; '
169+ f'return 0 '
145170 ),
146171 description = ('Check if llvm-bolt binaries are different and '
147172 'skip the following nfc-check steps' ),
173+ decodeRC = {0 : SUCCESS , 1 : WARNINGS },
148174 haltOnFailure = False ,
149175 env = env ),
176+ # Run in-tree tests if the llvm-bolt binary has changed, or if
177+ # relevant source code changes are detected.
150178 LitTestCommand (
151179 name = 'nfc-check-bolt' ,
152180 command = ["ninja" , "check-bolt" ],
@@ -157,6 +185,7 @@ def getBOLTCmakeBuildFactory(
157185 flunkOnFailure = True ,
158186 doStepIf = FileDoesNotExist (f"build/{ skipInTree } " ),
159187 env = env ),
188+ # Run out-of-tree large tests if the llvm-bolt binary has changed.
160189 LitTestCommand (
161190 name = 'nfc-check-large-bolt' ,
162191 command = ['bin/llvm-lit' , '-sv' , '-j2' ,
@@ -171,6 +200,7 @@ def getBOLTCmakeBuildFactory(
171200 ])
172201
173202 return f
203+
174204class SkipAwareBuild (Build ):
175205 """
176206 Custom Build class that marks the overall build status as skipped when no
0 commit comments