diff options
| author | 2020-11-11 10:59:52 -0500 | |
|---|---|---|
| committer | 2020-11-11 11:25:48 -0500 | |
| commit | 1776a2ac6f32445b8563f8597b62918b6b1bd3d6 (patch) | |
| tree | 85ca1ed398aa06f06b877f94dfffcb5ae70871ad /rust/builder.go | |
| parent | 68ecbaf614f7a4518357a0ab2b63f98e83778652 (diff) | |
rust: Fix absolute path OUT_DIR bug
The OUT_DIR for rustc is incorrectly calculated when Soong's OUT_DIR
is set to an absolute path through OUT_DIR_COMMON_BASE. This breaks
compilation when rustc is unable to find files that have beein included
through the include! macro.
Bug: 172952634
Test: OUT_DIR_COMMON_BASE=/some/abs/path m
Change-Id: Id447630a7774c1dec655f65dd227c144a159e1b1
Diffstat (limited to 'rust/builder.go')
| -rw-r--r-- | rust/builder.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/rust/builder.go b/rust/builder.go index 3e082dc2f..a09b1d1ec 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -15,6 +15,7 @@ package rust import ( + "path/filepath" "strings" "github.com/google/blueprint" @@ -235,7 +236,18 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl }, }) implicits = append(implicits, outputs.Paths()...) - envVars = append(envVars, "OUT_DIR=$$PWD/"+moduleGenDir.String()) + + // We must calculate an absolute path for OUT_DIR since Rust's include! macro (which normally consumes this) + // assumes that paths are relative to the source file. + var outDirPrefix string + if !filepath.IsAbs(moduleGenDir.String()) { + // If OUT_DIR is not absolute, we use $$PWD to generate an absolute path (os.Getwd() returns '/') + outDirPrefix = "$$PWD/" + } else { + // If OUT_DIR is absolute, then moduleGenDir will be an absolute path, so we don't need to set this to anything. + outDirPrefix = "" + } + envVars = append(envVars, "OUT_DIR="+filepath.Join(outDirPrefix, moduleGenDir.String())) } if flags.Clippy { |