Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6bbe5774 authored by Thiébaud Weksteen's avatar Thiébaud Weksteen Committed by Gerrit Code Review
Browse files

Merge "Explicitly define Rust default lints"

parents 7d9deed9 8e46efac
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ var (
				// Because clippy-driver uses rustc as backend, we need to have some output even during the linting.
				// Use the metadata output as it has the smallest footprint.
				"--emit metadata -o $out $in ${libFlags} " +
				"$clippyFlags $rustcFlags",
				"$rustcFlags $clippyFlags",
			CommandDeps: []string{"$clippyCmd"},
		},
		"rustcFlags", "libFlags", "clippyFlags")
+4 −8
Original line number Diff line number Diff line
@@ -28,10 +28,6 @@ func getEdition(compiler *baseCompiler) string {
	return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
}

func getDenyWarnings(compiler *baseCompiler) bool {
	return BoolDefault(compiler.Properties.Deny_warnings, config.DefaultDenyWarnings)
}

func (compiler *baseCompiler) setNoStdlibs() {
	compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
}
@@ -56,8 +52,8 @@ type BaseCompilerProperties struct {
	// path to the source file that is the main entry point of the program (e.g. main.rs or lib.rs)
	Srcs []string `android:"path,arch_variant"`

	// whether to pass "-D warnings" to rustc. Defaults to true.
	Deny_warnings *bool
	// whether to suppress the standard lint flags - default to false
	No_lint *bool

	// flags to pass to rustc
	Flags []string `android:"path,arch_variant"`
@@ -145,8 +141,8 @@ func (compiler *baseCompiler) featuresToFlags(features []string) []string {

func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {

	if getDenyWarnings(compiler) {
		flags.RustFlags = append(flags.RustFlags, "-D warnings")
	if !Bool(compiler.Properties.No_lint) {
		flags.RustFlags = append(flags.RustFlags, config.RustcLintsForDir(ctx.ModuleDir()))
	}
	flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
	flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...)
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ bootstrap_go_package {
        "arm_device.go",
        "arm64_device.go",
        "global.go",
        "clippy.go",
        "lints.go",
        "toolchain.go",
        "allowed_list.go",
        "x86_darwin_host.go",

rust/config/clippy.go

deleted100644 → 0
+0 −80
Original line number Diff line number Diff line
// Copyright 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package config

import (
	"strings"

	"android/soong/android"
)

var (
	defaultLints = []string{
		"-D missing-docs",
		"-D clippy::missing-safety-doc",
	}
	defaultVendorLints = []string{
		"",
	}
)

func init() {
	// Default Rust lints. These apply to all Google-authored modules.
	pctx.VariableFunc("ClippyDefaultLints", func(ctx android.PackageVarContext) string {
		if override := ctx.Config().Getenv("CLIPPY_DEFAULT_LINTS"); override != "" {
			return override
		}
		return strings.Join(defaultLints, " ")
	})

	// Rust lints that only applies to external code.
	pctx.VariableFunc("ClippyVendorLints", func(ctx android.PackageVarContext) string {
		if override := ctx.Config().Getenv("CLIPPY_VENDOR_LINTS"); override != "" {
			return override
		}
		return strings.Join(defaultVendorLints, " ")
	})
}

type PathBasedClippyConfig struct {
	PathPrefix   string
	Enabled      bool
	ClippyConfig string
}

const clippyNone = ""
const clippyDefault = "${config.ClippyDefaultLints}"
const clippyVendor = "${config.ClippyVendorLints}"

// This is a map of local path prefixes to a boolean indicating if the lint
// rule should be generated and if so, the set of lints to use. The first entry
// matching will be used. If no entry is matching, clippyDefault will be used.
var DefaultLocalTidyChecks = []PathBasedClippyConfig{
	{"external/", false, clippyNone},
	{"hardware/", true, clippyVendor},
	{"prebuilts/", false, clippyNone},
	{"vendor/google", true, clippyDefault},
	{"vendor/", true, clippyVendor},
}

// ClippyLintsForDir returns the Clippy lints to be used for a repository.
func ClippyLintsForDir(dir string) (bool, string) {
	for _, pathCheck := range DefaultLocalTidyChecks {
		if strings.HasPrefix(dir, pathCheck.PathPrefix) {
			return pathCheck.Enabled, pathCheck.ClippyConfig
		}
	}
	return true, clippyDefault
}
+0 −2
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ var (
		"libtest",
	}

	DefaultDenyWarnings = true

	GlobalRustFlags = []string{
		"--remap-path-prefix $$(pwd)=",
		"-C codegen-units=1",
Loading