1// Copyright 2017 Google Inc. All rights reserved. 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 python 16 17import ( 18 "android/soong/android" 19 "fmt" 20 "io" 21 "path/filepath" 22 "strings" 23) 24 25type subAndroidMkProvider interface { 26 AndroidMk(*Module, *android.AndroidMkData) 27} 28 29func (p *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) { 30 if p.subAndroidMkOnce == nil { 31 p.subAndroidMkOnce = make(map[subAndroidMkProvider]bool) 32 } 33 if androidmk, ok := obj.(subAndroidMkProvider); ok { 34 if !p.subAndroidMkOnce[androidmk] { 35 p.subAndroidMkOnce[androidmk] = true 36 androidmk.AndroidMk(p, data) 37 } 38 } 39} 40 41func (p *Module) AndroidMk() android.AndroidMkData { 42 ret := android.AndroidMkData{OutputFile: p.installSource} 43 44 p.subAndroidMk(&ret, p.installer) 45 46 return ret 47} 48 49func (p *binaryDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { 50 ret.Class = "EXECUTABLES" 51 52 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { 53 if len(p.binaryProperties.Test_suites) > 0 { 54 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", 55 strings.Join(p.binaryProperties.Test_suites, " ")) 56 } 57 }) 58 base.subAndroidMk(ret, p.pythonInstaller) 59} 60 61func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { 62 ret.Class = "NATIVE_TESTS" 63 64 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { 65 if len(p.binaryDecorator.binaryProperties.Test_suites) > 0 { 66 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", 67 strings.Join(p.binaryDecorator.binaryProperties.Test_suites, " ")) 68 } 69 // If the test config has an explicit config specified use it. 70 if p.testProperties.Test_config != nil { 71 fmt.Fprintln(w, "LOCAL_TEST_CONFIG :=", 72 *p.testProperties.Test_config) 73 } else { 74 if p.testConfig != nil { 75 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", 76 p.testConfig.String()) 77 } 78 } 79 }) 80 base.subAndroidMk(ret, p.binaryDecorator.pythonInstaller) 81} 82 83func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMkData) { 84 // Soong installation is only supported for host modules. Have Make 85 // installation trigger Soong installation. 86 if base.Target().Os.Class == android.Host { 87 ret.OutputFile = android.OptionalPathForPath(installer.path) 88 } 89 90 ret.Required = append(ret.Required, "libc++") 91 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { 92 path := installer.path.RelPathString() 93 dir, file := filepath.Split(path) 94 stem := strings.TrimSuffix(file, filepath.Ext(file)) 95 96 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) 97 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) 98 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) 99 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " ")) 100 }) 101} 102