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 "path/filepath" 19 "strings" 20 21 "android/soong/android" 22) 23 24type subAndroidMkProvider interface { 25 AndroidMk(*Module, *android.AndroidMkEntries) 26} 27 28func (p *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) { 29 if p.subAndroidMkOnce == nil { 30 p.subAndroidMkOnce = make(map[subAndroidMkProvider]bool) 31 } 32 if androidmk, ok := obj.(subAndroidMkProvider); ok { 33 if !p.subAndroidMkOnce[androidmk] { 34 p.subAndroidMkOnce[androidmk] = true 35 androidmk.AndroidMk(p, entries) 36 } 37 } 38} 39 40func (p *Module) AndroidMkEntries() []android.AndroidMkEntries { 41 entries := android.AndroidMkEntries{OutputFile: p.installSource} 42 43 p.subAndroidMk(&entries, p.installer) 44 45 return []android.AndroidMkEntries{entries} 46} 47 48func (p *binaryDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) { 49 entries.Class = "EXECUTABLES" 50 51 entries.ExtraEntries = append(entries.ExtraEntries, 52 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 53 entries.AddCompatibilityTestSuites(p.binaryProperties.Test_suites...) 54 }) 55 base.subAndroidMk(entries, p.pythonInstaller) 56} 57 58func (p *testDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) { 59 entries.Class = "NATIVE_TESTS" 60 61 entries.ExtraEntries = append(entries.ExtraEntries, 62 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 63 entries.AddCompatibilityTestSuites(p.binaryDecorator.binaryProperties.Test_suites...) 64 if p.testConfig != nil { 65 entries.SetString("LOCAL_FULL_TEST_CONFIG", p.testConfig.String()) 66 } 67 68 entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(p.binaryProperties.Auto_gen_config, true)) 69 70 entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...) 71 72 entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(p.testProperties.Test_options.Unit_test)) 73 }) 74 base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller) 75} 76 77func (installer *pythonInstaller) AndroidMk(base *Module, entries *android.AndroidMkEntries) { 78 entries.Required = append(entries.Required, "libc++") 79 entries.ExtraEntries = append(entries.ExtraEntries, 80 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 81 path, file := filepath.Split(installer.path.String()) 82 stem := strings.TrimSuffix(file, filepath.Ext(file)) 83 84 entries.SetString("LOCAL_MODULE_SUFFIX", filepath.Ext(file)) 85 entries.SetString("LOCAL_MODULE_PATH", path) 86 entries.SetString("LOCAL_MODULE_STEM", stem) 87 entries.AddStrings("LOCAL_SHARED_LIBRARIES", installer.androidMkSharedLibs...) 88 entries.SetBool("LOCAL_CHECK_ELF_FILES", false) 89 }) 90} 91