Conditionally apply rustdoc flags to third party crates
This CL changes the logic in rust/builder.go so that some rustdoc flags
are only applied to external crates. This will allow us to since
warnings and deal with soft-failures in external crates while allowing
us to be more strict with our internal Rust code.
Bug: 195136952
Test: m rustdoc
Change-Id: Icdde304bbbb323cae9657e8f842f58ae79e811ce
diff --git a/android/paths.go b/android/paths.go
index 99db22f..9c9914e 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -20,6 +20,7 @@
"os"
"path/filepath"
"reflect"
+ "regexp"
"sort"
"strings"
@@ -2094,3 +2095,25 @@
}
return ret
}
+
+var thirdPartyDirPrefixExceptions = []*regexp.Regexp{
+ regexp.MustCompile("^vendor/[^/]*google[^/]*/"),
+ regexp.MustCompile("^hardware/google/"),
+ regexp.MustCompile("^hardware/interfaces/"),
+ regexp.MustCompile("^hardware/libhardware[^/]*/"),
+ regexp.MustCompile("^hardware/ril/"),
+}
+
+func IsThirdPartyPath(path string) bool {
+ thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
+
+ if HasAnyPrefix(path, thirdPartyDirPrefixes) {
+ for _, prefix := range thirdPartyDirPrefixExceptions {
+ if prefix.MatchString(path) {
+ return false
+ }
+ }
+ return true
+ }
+ return false
+}
diff --git a/cc/compiler.go b/cc/compiler.go
index e19efd5..03214c8 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -450,7 +450,7 @@
"${config.CommonGlobalCflags}",
fmt.Sprintf("${config.%sGlobalCflags}", hod))
- if isThirdParty(modulePath) {
+ if android.IsThirdPartyPath(modulePath) {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "${config.ExternalCflags}")
}
@@ -675,28 +675,6 @@
return transformSourceToObj(ctx, subdir, srcFiles, flags, pathDeps, cFlagsDeps)
}
-var thirdPartyDirPrefixExceptions = []*regexp.Regexp{
- regexp.MustCompile("^vendor/[^/]*google[^/]*/"),
- regexp.MustCompile("^hardware/google/"),
- regexp.MustCompile("^hardware/interfaces/"),
- regexp.MustCompile("^hardware/libhardware[^/]*/"),
- regexp.MustCompile("^hardware/ril/"),
-}
-
-func isThirdParty(path string) bool {
- thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
-
- if android.HasAnyPrefix(path, thirdPartyDirPrefixes) {
- for _, prefix := range thirdPartyDirPrefixExceptions {
- if prefix.MatchString(path) {
- return false
- }
- }
- return true
- }
- return false
-}
-
// Properties for rust_bindgen related to generating rust bindings.
// This exists here so these properties can be included in a cc_default
// which can be used in both cc and rust modules.
diff --git a/cc/compiler_test.go b/cc/compiler_test.go
index a3ee4a6..9ae4d18 100644
--- a/cc/compiler_test.go
+++ b/cc/compiler_test.go
@@ -16,6 +16,8 @@
import (
"testing"
+
+ "android/soong/android"
)
func TestIsThirdParty(t *testing.T) {
@@ -32,12 +34,12 @@
"bionic/libc",
}
for _, path := range thirdPartyPaths {
- if !isThirdParty(path) {
+ if !android.IsThirdPartyPath(path) {
t.Errorf("Expected %s to be considered third party", path)
}
}
for _, path := range nonThirdPartyPaths {
- if isThirdParty(path) {
+ if android.IsThirdPartyPath(path) {
t.Errorf("Expected %s to *not* be considered third party", path)
}
}
diff --git a/rust/builder.go b/rust/builder.go
index 6c44166..a5b3ab9 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -332,8 +332,11 @@
rustdocFlags = append(rustdocFlags, makeLibFlags(deps)...)
docTimestampFile := android.PathForModuleOut(ctx, "rustdoc.timestamp")
- // Silence warnings about renamed lints
- rustdocFlags = append(rustdocFlags, " -A renamed_and_removed_lints")
+ // Silence warnings about renamed lints for third-party crates
+ modulePath := android.PathForModuleSrc(ctx).String()
+ if android.IsThirdPartyPath(modulePath) {
+ rustdocFlags = append(rustdocFlags, " -A renamed_and_removed_lints")
+ }
// Yes, the same out directory is used simultaneously by all rustdoc builds.
// This is what cargo does. The docs for individual crates get generated to