@@ -189,6 +189,8 @@ func Test(t *testing.T) {
189
189
defer wg .Done ()
190
190
cmd := bazel_testing .BazelCmd ("build" ,
191
191
"//:all" ,
192
+ "--copt=-Irelative/path/does/not/exist" ,
193
+ "--linkopt=-Lrelative/path/does/not/exist" ,
192
194
"@io_bazel_rules_go//go/tools/builders:go_path" ,
193
195
"@go_sdk//:builder" ,
194
196
)
@@ -200,49 +202,92 @@ func Test(t *testing.T) {
200
202
}
201
203
wg .Wait ()
202
204
203
- // Hash files in each bazel-bin directory.
204
- dirHashes := make ([][]fileHash , len (dirs ))
205
- errs := make ([]error , len (dirs ))
206
- wg .Add (len (dirs ))
207
- for i := range dirs {
208
- go func (i int ) {
209
- defer wg .Done ()
210
- dirHashes [i ], errs [i ] = hashFiles (filepath .Join (dirs [i ], "bazel-bin" ))
211
- }(i )
212
- }
213
- wg .Wait ()
214
- for _ , err := range errs {
215
- if err != nil {
205
+ t .Run ("Check Hashes" , func (t * testing.T ) {
206
+ // Hash files in each bazel-bin directory.
207
+ dirHashes := make ([][]fileHash , len (dirs ))
208
+ errs := make ([]error , len (dirs ))
209
+ wg .Add (len (dirs ))
210
+ for i := range dirs {
211
+ go func (i int ) {
212
+ defer wg .Done ()
213
+ dirHashes [i ], errs [i ] = hashFiles (filepath .Join (dirs [i ], "bazel-out/" ), func (root , path string ) bool {
214
+ // Hash everything but actions stdout/stderr and the volatile-status.txt file
215
+ // as they are expected to change
216
+ return strings .HasPrefix (path , filepath .Join (root , "_tmp" )) ||
217
+ path == filepath .Join (root , "volatile-status.txt" )
218
+ })
219
+ }(i )
220
+ }
221
+ wg .Wait ()
222
+ for _ , err := range errs {
223
+ if err != nil {
224
+ t .Fatal (err )
225
+ }
226
+ }
227
+
228
+ // Compare dir0 and dir1. They should be identical.
229
+ if err := compareHashes (dirHashes [0 ], dirHashes [1 ]); err != nil {
216
230
t .Fatal (err )
217
231
}
218
- }
219
232
220
- // Compare dir0 and dir1. They should be identical.
221
- if err := compareHashes (dirHashes [0 ], dirHashes [1 ]); err != nil {
222
- t .Fatal (err )
223
- }
233
+ // Compare dir0 and dir2. They should be different.
234
+ if err := compareHashes (dirHashes [0 ], dirHashes [2 ]); err == nil {
235
+ t .Fatalf ("dir0 and dir2 are the same)" , len (dirHashes [0 ]))
236
+ }
237
+ })
224
238
225
- // Compare dir0 and dir2. They should be different.
226
- if err := compareHashes (dirHashes [0 ], dirHashes [2 ]); err == nil {
227
- t .Fatalf ("dir0 and dir2 are the same)" , len (dirHashes [0 ]))
228
- }
239
+ t .Run ("Check builder" , func (t * testing.T ) {
240
+ // Check that the go_sdk path doesn't appear in the builder binary. This path is different
241
+ // nominally different per workspace (but in these tests, the go_sdk paths are all set to the same
242
+ // path in WORKSPACE) -- so if this path is in the builder binary, then builds between workspaces
243
+ // would be partially non cacheable.
244
+ builder_file , err := os .Open (filepath .Join (dirs [0 ], "bazel-bin" , "external" , "go_sdk" , "builder" ))
245
+ if err != nil {
246
+ t .Fatal (err )
247
+ }
248
+ defer builder_file .Close ()
249
+ builder_data , err := ioutil .ReadAll (builder_file )
250
+ if err != nil {
251
+ t .Fatal (err )
252
+ }
253
+ if bytes .Index (builder_data , []byte ("go_sdk" )) != - 1 {
254
+ t .Fatalf ("Found go_sdk path in builder binary, builder tool won't be reproducible" )
255
+ }
256
+ })
229
257
230
- // Check that the go_sdk path doesn't appear in the builder binary. This path is different
231
- // nominally different per workspace (but in these tests, the go_sdk paths are all set to the same
232
- // path in WORKSPACE) -- so if this path is in the builder binary, then builds between workspaces
233
- // would be partially non cacheable.
234
- builder_file , err := os .Open (filepath .Join (dirs [0 ], "bazel-bin" , "external" , "go_sdk" , "builder" ))
235
- if err != nil {
236
- t .Fatal (err )
237
- }
238
- defer builder_file .Close ()
239
- builder_data , err := ioutil .ReadAll (builder_file )
240
- if err != nil {
241
- t .Fatal (err )
242
- }
243
- if bytes .Index (builder_data , []byte ("go_sdk" )) != - 1 {
244
- t .Fatalf ("Found go_sdk path in builder binary, builder tool won't be reproducible" )
245
- }
258
+ t .Run ("Check stdlib" , func (t * testing.T ) {
259
+ for _ , dir := range dirs {
260
+ found := false
261
+ root , err := os .Readlink (filepath .Join (dir , "bazel-out/" ))
262
+ if err != nil {
263
+ t .Fatal (err )
264
+ }
265
+
266
+ filepath .Walk (root , func (path string , info os.FileInfo , err error ) error {
267
+ if err != nil {
268
+ return err
269
+ }
270
+ if ! strings .Contains (path , "stdlib_/pkg" ) {
271
+ return nil
272
+ }
273
+ if ! strings .HasSuffix (path , ".a" ) {
274
+ return nil
275
+ }
276
+ data , err := ioutil .ReadFile (path )
277
+ if err != nil {
278
+ t .Fatal (err )
279
+ }
280
+ if bytes .Index (data , []byte ("__GO_BAZEL_CC_PLACEHOLDER__" )) == - 1 {
281
+ found = true
282
+ return filepath .SkipAll
283
+ }
284
+ return nil
285
+ })
286
+ if ! found {
287
+ t .Fatal ("Placeholder not found in stdlib of " + dir )
288
+ }
289
+ }
290
+ })
246
291
}
247
292
248
293
func copyTree (dstRoot , srcRoot string ) error {
@@ -311,7 +356,7 @@ type fileHash struct {
311
356
rel , hash string
312
357
}
313
358
314
- func hashFiles (dir string ) ([]fileHash , error ) {
359
+ func hashFiles (dir string , exclude func ( root , path string ) bool ) ([]fileHash , error ) {
315
360
// Follow top-level symbolic link
316
361
root := dir
317
362
for {
@@ -348,7 +393,15 @@ func hashFiles(dir string) ([]fileHash, error) {
348
393
return err
349
394
}
350
395
}
396
+
351
397
if info .IsDir () {
398
+ if exclude (root , path ) {
399
+ return filepath .SkipDir
400
+ }
401
+ return nil
402
+ }
403
+
404
+ if exclude (root , path ) {
352
405
return nil
353
406
}
354
407
0 commit comments