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