Merge "Conditionally apply rustdoc flags to third party crates"

This commit is contained in:
Christian Wailes
2021-08-03 19:39:17 +00:00
committed by Gerrit Code Review
4 changed files with 33 additions and 27 deletions

View File

@@ -20,6 +20,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"regexp"
"sort" "sort"
"strings" "strings"
@@ -2094,3 +2095,25 @@ func PathsIfNonNil(paths ...Path) Paths {
} }
return ret 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
}

View File

@@ -450,7 +450,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
"${config.CommonGlobalCflags}", "${config.CommonGlobalCflags}",
fmt.Sprintf("${config.%sGlobalCflags}", hod)) fmt.Sprintf("${config.%sGlobalCflags}", hod))
if isThirdParty(modulePath) { if android.IsThirdPartyPath(modulePath) {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "${config.ExternalCflags}") flags.Global.CommonFlags = append(flags.Global.CommonFlags, "${config.ExternalCflags}")
} }
@@ -675,28 +675,6 @@ func compileObjs(ctx android.ModuleContext, flags builderFlags,
return transformSourceToObj(ctx, subdir, srcFiles, flags, pathDeps, cFlagsDeps) 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. // Properties for rust_bindgen related to generating rust bindings.
// This exists here so these properties can be included in a cc_default // This exists here so these properties can be included in a cc_default
// which can be used in both cc and rust modules. // which can be used in both cc and rust modules.

View File

@@ -16,6 +16,8 @@ package cc
import ( import (
"testing" "testing"
"android/soong/android"
) )
func TestIsThirdParty(t *testing.T) { func TestIsThirdParty(t *testing.T) {
@@ -32,12 +34,12 @@ func TestIsThirdParty(t *testing.T) {
"bionic/libc", "bionic/libc",
} }
for _, path := range thirdPartyPaths { for _, path := range thirdPartyPaths {
if !isThirdParty(path) { if !android.IsThirdPartyPath(path) {
t.Errorf("Expected %s to be considered third party", path) t.Errorf("Expected %s to be considered third party", path)
} }
} }
for _, path := range nonThirdPartyPaths { for _, path := range nonThirdPartyPaths {
if isThirdParty(path) { if android.IsThirdPartyPath(path) {
t.Errorf("Expected %s to *not* be considered third party", path) t.Errorf("Expected %s to *not* be considered third party", path)
} }
} }

View File

@@ -332,8 +332,11 @@ func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps,
rustdocFlags = append(rustdocFlags, makeLibFlags(deps)...) rustdocFlags = append(rustdocFlags, makeLibFlags(deps)...)
docTimestampFile := android.PathForModuleOut(ctx, "rustdoc.timestamp") docTimestampFile := android.PathForModuleOut(ctx, "rustdoc.timestamp")
// Silence warnings about renamed 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") rustdocFlags = append(rustdocFlags, " -A renamed_and_removed_lints")
}
// Yes, the same out directory is used simultaneously by all rustdoc builds. // 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 // This is what cargo does. The docs for individual crates get generated to