aboutsummaryrefslogtreecommitdiff
path: root/bazel
diff options
context:
space:
mode:
authorSpandan Das <spandandas@google.com>2023-06-29 01:15:51 +0000
committerSpandan Das <spandandas@google.com>2023-07-14 00:43:52 +0000
commitaf4ccaaf41604233915cc15f5e6de8187dd28811 (patch)
treeaf43b174fb0c227de9116d93440640062972e17b /bazel
parent33e309746e3e839e363f0ca679092974b83a7511 (diff)
Add functionality to sandbox mixed build actions
The use case for this is for building rules_go's root builder which runs into issues when built in a directory that contains a symlink to prebuilts/go The implementation will involve two changes of working dir - `sbox` to change the working directory to __SBOX_SANDBOX_DIR__ - the generated manifest will change the working directory to mixed build execution root relative to that Implemenation details 1. Create a unique intermediate path by hashing the outputs of a buildAction. "out/bazel/output/execroot/__main__/" was deliberately not chosen as the outpuDir for the sandbox because ruleBuilder would wipe it. `sbox` will generate the files in __SBOX_SANDBOX_DIR__ and then place the files in this intermediate directory. 2. After the files have been generated in (1), copy them to out/bazel/output/execroot/__main__/... 3. For bazel depsets that are inputs of an action, copy the direct artifacts into the sandbox instead of the phony target 4. Make sandboxing an opt-in. Currently we will only use it for `GoToolchainBinaryBuild` In the current implementation, (3) will increase the size of the ninja file. With sboxing turned on for only GoToolchainBinaryBuild, this will increase the size of the ninja file by around 1.3% on aosp's cf Test: m com.android.neuralnetworks (will build soong_zip from source using rules_go) Test: OUT_DIR=out.other m com.android.neuralnetworks Bug: 289102849 Change-Id: I7addda9af583ba0ff306e50c1dfa16ed16c29799
Diffstat (limited to 'bazel')
-rw-r--r--bazel/aquery.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/bazel/aquery.go b/bazel/aquery.go
index 480158c11..3428328bd 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -116,6 +116,9 @@ type BuildStatement struct {
InputDepsetHashes []string
InputPaths []string
FileContents string
+ // If ShouldRunInSbox is true, Soong will use sbox to created an isolated environment
+ // and run the mixed build action there
+ ShouldRunInSbox bool
}
// A helper type for aquery processing which facilitates retrieval of path IDs from their
@@ -496,6 +499,12 @@ func (a *aqueryArtifactHandler) normalActionBuildStatement(actionEntry *analysis
Env: actionEntry.EnvironmentVariables,
Mnemonic: actionEntry.Mnemonic,
}
+ if buildStatement.Mnemonic == "GoToolchainBinaryBuild" {
+ // Unlike b's execution root, mixed build execution root contains a symlink to prebuilts/go
+ // This causes issues for `GOCACHE=$(mktemp -d) go build ...`
+ // To prevent this, sandbox this action in mixed builds as well
+ buildStatement.ShouldRunInSbox = true
+ }
return buildStatement, nil
}