Move partner androidmk and bpfix files to match their package path
Using a gomod-aware editor with build/soong requires that files in build/soong can be mapped to the android/soong package path. Move the partner androidmk and bpfix files such that their path matches the package path when the android/soong package prefix is replaced with the build/soong path prefix. Test: go test ./... Test: m bpfix androidmk partner_bpfix partner_androidmk Change-Id: Ic7f7aad9e5eb9178eef0383f0b37e4fb93ce8314
This commit is contained in:
27
partner/bpfix/bpfix.go
Normal file
27
partner/bpfix/bpfix.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2017 Google Inc. All rights reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// This file provides a command-line interface to bpfix
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"android/soong/bpfix/cmd_lib"
|
||||
|
||||
_ "android/soong/partner/bpfix/extensions"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd_lib.Run()
|
||||
}
|
120
partner/bpfix/extensions/headers.go
Normal file
120
partner/bpfix/extensions/headers.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package extensions
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint/parser"
|
||||
|
||||
"android/soong/bpfix/bpfix"
|
||||
)
|
||||
|
||||
var fixSteps = bpfix.FixStepsExtension{
|
||||
Name: "partner-include-dirs",
|
||||
Steps: []bpfix.FixStep{
|
||||
{
|
||||
Name: "fixIncludeDirs",
|
||||
Fix: fixIncludeDirs,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
bpfix.RegisterFixStepExtension(&fixSteps)
|
||||
}
|
||||
|
||||
type includeDirFix struct {
|
||||
libName string
|
||||
libType string
|
||||
variable string
|
||||
subdir string
|
||||
}
|
||||
|
||||
var commonIncludeDirs = []includeDirFix{
|
||||
{
|
||||
libName: "my_header_lib",
|
||||
libType: "header_libs",
|
||||
variable: "TARGET_OUT_HEADERS",
|
||||
subdir: "/my_headers",
|
||||
},
|
||||
}
|
||||
|
||||
func findHeaderLib(e parser.Expression) (*includeDirFix, bool) {
|
||||
if op, ok := e.(*parser.Operator); ok {
|
||||
if op.Operator != '+' {
|
||||
return nil, false
|
||||
}
|
||||
arg0, ok := op.Args[0].(*parser.Variable)
|
||||
arg1, ok1 := op.Args[1].(*parser.String)
|
||||
if !ok || !ok1 {
|
||||
return nil, false
|
||||
}
|
||||
for _, lib := range commonIncludeDirs {
|
||||
if arg0.Name == lib.variable && arg1.Value == lib.subdir {
|
||||
return &lib, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
func searchThroughOperatorList(mod *parser.Module, e parser.Expression) {
|
||||
if list, ok := e.(*parser.List); ok {
|
||||
newList := make([]parser.Expression, 0, len(list.Values))
|
||||
for _, item := range list.Values {
|
||||
if lib, found := findHeaderLib(item); found {
|
||||
if lib.libName != "" {
|
||||
addLibrary(mod, lib.libType, lib.libName)
|
||||
}
|
||||
} else {
|
||||
newList = append(newList, item)
|
||||
}
|
||||
}
|
||||
list.Values = newList
|
||||
}
|
||||
if op, ok := e.(*parser.Operator); ok {
|
||||
searchThroughOperatorList(mod, op.Args[0])
|
||||
searchThroughOperatorList(mod, op.Args[1])
|
||||
}
|
||||
}
|
||||
func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List, found bool) {
|
||||
prop, ok := mod.GetProperty(name)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
list, ok = prop.Value.(*parser.List)
|
||||
return list, ok
|
||||
}
|
||||
func addLibrary(mod *parser.Module, libType string, libName string) {
|
||||
var list, ok = getLiteralListProperty(mod, libType)
|
||||
if !ok {
|
||||
list = new(parser.List)
|
||||
prop := new(parser.Property)
|
||||
prop.Name = libType
|
||||
prop.Value = list
|
||||
mod.Properties = append(mod.Properties, prop)
|
||||
} else {
|
||||
for _, v := range list.Values {
|
||||
if stringValue, ok := v.(*parser.String); ok && stringValue.Value == libName {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
lib := new(parser.String)
|
||||
lib.Value = libName
|
||||
list.Values = append(list.Values, lib)
|
||||
}
|
||||
func fixIncludeDirs(f *bpfix.Fixer) error {
|
||||
tree := f.Tree()
|
||||
for _, def := range tree.Defs {
|
||||
mod, ok := def.(*parser.Module)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(mod.Type, "cc_") {
|
||||
continue
|
||||
}
|
||||
if prop, ok := mod.GetProperty("include_dirs"); ok {
|
||||
searchThroughOperatorList(mod, prop.Value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user