From c773778bfe57d979f6b146c41ac8a6e4ac3b1be2 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Thu, 4 Nov 2021 10:56:13 -0400 Subject: [PATCH] Make bazel action symlinks absolute paths hardlinks are incompatible with sandboxing relative links are incopatible with Soong's use of `cp -d` Test: build/bazel/ci/mixed_libc.sh Change-Id: I8c776cda6a27c680c51466d9a7af1b499f2f566d --- bazel/aquery.go | 6 +++--- bazel/aquery_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bazel/aquery.go b/bazel/aquery.go index 0dedcf492..6d96b1ca1 100644 --- a/bazel/aquery.go +++ b/bazel/aquery.go @@ -245,9 +245,9 @@ func AqueryBuildStatements(aqueryJsonProto []byte) ([]BuildStatement, error) { out := outputPaths[0] outDir := proptools.ShellEscapeIncludingSpaces(filepath.Dir(out)) out = proptools.ShellEscapeIncludingSpaces(out) - in := proptools.ShellEscapeIncludingSpaces(inputPaths[0]) - // Use hard links, because some soong actions expect real files (for example, `cp -d`). - buildStatement.Command = fmt.Sprintf("mkdir -p %[1]s && rm -f %[2]s && ln -f %[3]s %[2]s", outDir, out, in) + in := filepath.Join("$PWD", proptools.ShellEscapeIncludingSpaces(inputPaths[0])) + // Use absolute paths, because some soong actions don't play well with relative paths (for example, `cp -d`). + buildStatement.Command = fmt.Sprintf("mkdir -p %[1]s && rm -f %[2]s && ln -sf %[3]s %[2]s", outDir, out, in) buildStatement.SymlinkPaths = outputPaths[:] } else if len(actionEntry.Arguments) < 1 { return nil, fmt.Errorf("received action with no command: [%v]", buildStatement) diff --git a/bazel/aquery_test.go b/bazel/aquery_test.go index 88066c8fe..69f11152e 100644 --- a/bazel/aquery_test.go +++ b/bazel/aquery_test.go @@ -859,7 +859,7 @@ func TestSimpleSymlink(t *testing.T) { BuildStatement{ Command: "mkdir -p one/symlink_subdir && " + "rm -f one/symlink_subdir/symlink && " + - "ln -f one/file_subdir/file one/symlink_subdir/symlink", + "ln -sf $PWD/one/file_subdir/file one/symlink_subdir/symlink", InputPaths: []string{"one/file_subdir/file"}, OutputPaths: []string{"one/symlink_subdir/symlink"}, SymlinkPaths: []string{"one/symlink_subdir/symlink"}, @@ -923,14 +923,14 @@ func TestSymlinkQuotesPaths(t *testing.T) { BuildStatement{ Command: "mkdir -p 'one/symlink subdir' && " + "rm -f 'one/symlink subdir/symlink' && " + - "ln -f 'one/file subdir/file' 'one/symlink subdir/symlink'", + "ln -sf $PWD/'one/file subdir/file' 'one/symlink subdir/symlink'", InputPaths: []string{"one/file subdir/file"}, OutputPaths: []string{"one/symlink subdir/symlink"}, SymlinkPaths: []string{"one/symlink subdir/symlink"}, Mnemonic: "SolibSymlink", }, } - assertBuildStatements(t, actual, expectedBuildStatements) + assertBuildStatements(t, expectedBuildStatements, actual) } func TestSymlinkMultipleInputs(t *testing.T) {