1// Copyright 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package rust
16
17import (
18	"android/soong/rust/config"
19)
20
21type ClippyProperties struct {
22	// name of the lint set that should be used to validate this module.
23	//
24	// Possible values are "default" (for using a sensible set of lints
25	// depending on the module's location), "android" (for the strictest
26	// lint set that applies to all Android platform code), "vendor" (for a
27	// relaxed set) and "none" (to disable the execution of clippy).  The
28	// default value is "default". See also the `lints` property.
29	Clippy_lints *string
30}
31
32type clippy struct {
33	Properties ClippyProperties
34}
35
36func (c *clippy) props() []interface{} {
37	return []interface{}{&c.Properties}
38}
39
40func (c *clippy) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
41	enabled, lints, err := config.ClippyLintsForDir(ctx.ModuleDir(), c.Properties.Clippy_lints)
42	if err != nil {
43		ctx.PropertyErrorf("clippy_lints", err.Error())
44	}
45	flags.Clippy = enabled
46	flags.ClippyFlags = append(flags.ClippyFlags, lints)
47	return flags, deps
48}
49