|
30 | 30 | import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
|
31 | 31 | import com.google.devtools.build.lib.collect.nestedset.NestedSet;
|
32 | 32 | import com.google.devtools.build.lib.util.Fingerprint;
|
| 33 | +import com.google.devtools.build.lib.util.OS; |
33 | 34 | import com.google.devtools.build.lib.vfs.Path;
|
34 | 35 | import com.google.devtools.build.lib.vfs.PathFragment;
|
35 | 36 | import com.google.devtools.build.lib.vfs.Root;
|
@@ -388,6 +389,78 @@ public void testUnresolvedSymlink() throws Exception {
|
388 | 389 | """);
|
389 | 390 | }
|
390 | 391 |
|
| 392 | + @Test |
| 393 | + public void testEscaping() throws Exception { |
| 394 | + Artifact manifest = getBinArtifactWithNoOwner("manifest1"); |
| 395 | + |
| 396 | + ArtifactRoot trivialRoot = |
| 397 | + ArtifactRoot.asSourceRoot(Root.fromPath(rootDirectory.getRelative("trivial"))); |
| 398 | + Path fileWithSpaceAndBackslashPath = scratch.file("trivial/file with sp\\ace", "foo"); |
| 399 | + Artifact fileWithSpaceAndBackslash = |
| 400 | + ActionsTestUtil.createArtifact(trivialRoot, fileWithSpaceAndBackslashPath); |
| 401 | + Path fileWithNewlineAndBackslashPath = scratch.file("trivial/file\nwith\\newline", "foo"); |
| 402 | + Artifact fileWithNewlineAndBackslash = |
| 403 | + ActionsTestUtil.createArtifact(trivialRoot, fileWithNewlineAndBackslashPath); |
| 404 | + |
| 405 | + SourceManifestAction action = |
| 406 | + new SourceManifestAction( |
| 407 | + ManifestType.SOURCE_SYMLINKS, |
| 408 | + NULL_ACTION_OWNER, |
| 409 | + manifest, |
| 410 | + new Runfiles.Builder("TESTING", false) |
| 411 | + .addSymlink(PathFragment.create("no/sp\\ace"), buildFile) |
| 412 | + .addSymlink(PathFragment.create("also/no/sp\\ace"), fileWithSpaceAndBackslash) |
| 413 | + .addSymlink(PathFragment.create("still/no/sp\\ace"), fileWithNewlineAndBackslash) |
| 414 | + .addSymlink(PathFragment.create("with sp\\ace"), buildFile) |
| 415 | + .addSymlink(PathFragment.create("also/with sp\\ace"), fileWithSpaceAndBackslash) |
| 416 | + .addSymlink(PathFragment.create("more/with sp\\ace"), fileWithNewlineAndBackslash) |
| 417 | + .addSymlink(PathFragment.create("with\nnew\\line"), buildFile) |
| 418 | + .addSymlink(PathFragment.create("also/with\nnewline"), fileWithSpaceAndBackslash) |
| 419 | + .addSymlink(PathFragment.create("more/with\nnewline"), fileWithNewlineAndBackslash) |
| 420 | + .addSymlink(PathFragment.create("with\nnew\\line and space"), buildFile) |
| 421 | + .addSymlink( |
| 422 | + PathFragment.create("also/with\nnewline and space"), fileWithSpaceAndBackslash) |
| 423 | + .addSymlink( |
| 424 | + PathFragment.create("more/with\nnewline and space"), |
| 425 | + fileWithNewlineAndBackslash) |
| 426 | + .build()); |
| 427 | + if (OS.getCurrent().equals(OS.WINDOWS)) { |
| 428 | + assertThat(action.getFileContents(reporter)) |
| 429 | + .isEqualTo( |
| 430 | + """ |
| 431 | + TESTING/also/no/sp/ace /workspace/trivial/file with sp/ace |
| 432 | + TESTING/also/with\\nnewline /workspace/trivial/file with sp/ace |
| 433 | + TESTING/also/with\\nnewline\\sand\\sspace /workspace/trivial/file with sp/ace |
| 434 | + TESTING/also/with\\ssp/ace /workspace/trivial/file with sp/ace |
| 435 | + TESTING/more/with\\nnewline /workspace/trivial/file\\nwith/newline |
| 436 | + TESTING/more/with\\nnewline\\sand\\sspace /workspace/trivial/file\\nwith/newline |
| 437 | + TESTING/more/with\\ssp/ace /workspace/trivial/file\\nwith/newline |
| 438 | + TESTING/no/sp/ace /workspace/trivial/BUILD |
| 439 | + TESTING/still/no/sp/ace /workspace/trivial/file\\nwith/newline |
| 440 | + TESTING/with\\nnew/line /workspace/trivial/BUILD |
| 441 | + TESTING/with\\nnew/line\\sand\\sspace /workspace/trivial/BUILD |
| 442 | + TESTING/with\\ssp/ace /workspace/trivial/BUILD |
| 443 | + """); |
| 444 | + } else { |
| 445 | + assertThat(action.getFileContents(reporter)) |
| 446 | + .isEqualTo( |
| 447 | + """ |
| 448 | + TESTING/also/no/sp\\ace /workspace/trivial/file with sp\\ace |
| 449 | + TESTING/also/with\\nnewline /workspace/trivial/file with sp\\bace |
| 450 | + TESTING/also/with\\nnewline\\sand\\sspace /workspace/trivial/file with sp\\bace |
| 451 | + TESTING/also/with\\ssp\\bace /workspace/trivial/file with sp\\bace |
| 452 | + TESTING/more/with\\nnewline /workspace/trivial/file\\nwith\\bnewline |
| 453 | + TESTING/more/with\\nnewline\\sand\\sspace /workspace/trivial/file\\nwith\\bnewline |
| 454 | + TESTING/more/with\\ssp\\bace /workspace/trivial/file\\nwith\\bnewline |
| 455 | + TESTING/no/sp\\ace /workspace/trivial/BUILD |
| 456 | + TESTING/still/no/sp\\bace /workspace/trivial/file\\nwith\\bnewline |
| 457 | + TESTING/with\\nnew\\bline /workspace/trivial/BUILD |
| 458 | + TESTING/with\\nnew\\bline\\sand\\sspace /workspace/trivial/BUILD |
| 459 | + TESTING/with\\ssp\\bace /workspace/trivial/BUILD |
| 460 | + """); |
| 461 | + } |
| 462 | + } |
| 463 | + |
391 | 464 | private String computeKey(SourceManifestAction action) {
|
392 | 465 | Fingerprint fp = new Fingerprint();
|
393 | 466 | action.computeKey(actionKeyContext, /* artifactExpander= */ null, fp);
|
|
0 commit comments