Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 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 | |
| 15 | package python |
| 16 | |
| 17 | import ( |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 18 | "path/filepath" |
| 19 | "strings" |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | type subAndroidMkProvider interface { |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 25 | AndroidMk(*Module, *android.AndroidMkEntries) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 28 | func (p *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 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 |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 35 | androidmk.AndroidMk(p, entries) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 40 | func (p *Module) AndroidMkEntries() []android.AndroidMkEntries { |
| 41 | entries := android.AndroidMkEntries{OutputFile: p.installSource} |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 42 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 43 | p.subAndroidMk(&entries, p.installer) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 44 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 45 | return []android.AndroidMkEntries{entries} |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 48 | func (p *binaryDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) { |
| 49 | entries.Class = "EXECUTABLES" |
Nan Zhang | c9c6cb7 | 2017-11-03 16:54:05 -0700 | [diff] [blame] | 50 | |
Colin Cross | f79fee8 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 51 | entries.ExtraEntries = append(entries.ExtraEntries, |
| 52 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
| 53 | entries.AddCompatibilityTestSuites(p.binaryProperties.Test_suites...) |
| 54 | }) |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 55 | base.subAndroidMk(entries, p.pythonInstaller) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 58 | func (p *testDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) { |
| 59 | entries.Class = "NATIVE_TESTS" |
Nan Zhang | c9c6cb7 | 2017-11-03 16:54:05 -0700 | [diff] [blame] | 60 | |
Colin Cross | f79fee8 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 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 | } |
Dan Shi | 2468d01 | 2020-01-06 15:47:57 -0800 | [diff] [blame] | 67 | |
Colin Cross | f79fee8 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 68 | entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(p.binaryProperties.Auto_gen_config, true)) |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 69 | |
Colin Cross | f79fee8 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 70 | entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...) |
Dan Shi | d79572f | 2020-11-13 14:33:46 -0800 | [diff] [blame] | 71 | |
Colin Cross | f79fee8 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 72 | entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(p.testProperties.Test_options.Unit_test)) |
| 73 | }) |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 74 | base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 77 | func (installer *pythonInstaller) AndroidMk(base *Module, entries *android.AndroidMkEntries) { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 78 | // Soong installation is only supported for host modules. Have Make |
| 79 | // installation trigger Soong installation. |
| 80 | if base.Target().Os.Class == android.Host { |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 81 | entries.OutputFile = android.OptionalPathForPath(installer.path) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Liz Kammer | d8dceb0 | 2020-11-24 08:36:14 -0800 | [diff] [blame] | 84 | entries.Required = append(entries.Required, "libc++") |
Colin Cross | f79fee8 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 85 | entries.ExtraEntries = append(entries.ExtraEntries, |
| 86 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
| 87 | path, file := filepath.Split(installer.path.ToMakePath().String()) |
| 88 | stem := strings.TrimSuffix(file, filepath.Ext(file)) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 89 | |
Colin Cross | f79fee8 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 90 | entries.SetString("LOCAL_MODULE_SUFFIX", filepath.Ext(file)) |
| 91 | entries.SetString("LOCAL_MODULE_PATH", path) |
| 92 | entries.SetString("LOCAL_MODULE_STEM", stem) |
| 93 | entries.AddStrings("LOCAL_SHARED_LIBRARIES", installer.androidMkSharedLibs...) |
| 94 | entries.SetBool("LOCAL_CHECK_ELF_FILES", false) |
| 95 | }) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 96 | } |