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 ( |
| 18 | "android/soong/android" |
| 19 | "fmt" |
| 20 | "io" |
| 21 | "path/filepath" |
| 22 | "strings" |
| 23 | ) |
| 24 | |
| 25 | type subAndroidMkProvider interface { |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 26 | AndroidMk(*Module, *android.AndroidMkData) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 29 | func (p *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 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 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 41 | func (p *Module) AndroidMk() android.AndroidMkData { |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 42 | ret := android.AndroidMkData{OutputFile: p.installSource} |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 43 | |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 44 | p.subAndroidMk(&ret, p.installer) |
| 45 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 46 | return ret |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 49 | func (p *binaryDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 50 | ret.Class = "EXECUTABLES" |
Nan Zhang | c9c6cb7 | 2017-11-03 16:54:05 -0700 | [diff] [blame] | 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 | }) |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 58 | base.subAndroidMk(ret, p.pythonInstaller) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 61 | func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 62 | ret.Class = "NATIVE_TESTS" |
Nan Zhang | c9c6cb7 | 2017-11-03 16:54:05 -0700 | [diff] [blame] | 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 | } |
Colin Cross | a638482 | 2020-06-09 15:09:22 -0700 | [diff] [blame] | 69 | if p.testConfig != nil { |
| 70 | fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", |
| 71 | p.testConfig.String()) |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 72 | } |
Dan Shi | 2468d01 | 2020-01-06 15:47:57 -0800 | [diff] [blame] | 73 | |
| 74 | if !BoolDefault(p.binaryProperties.Auto_gen_config, true) { |
| 75 | fmt.Fprintln(w, "LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG := true") |
| 76 | } |
Nan Zhang | c9c6cb7 | 2017-11-03 16:54:05 -0700 | [diff] [blame] | 77 | }) |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 78 | base.subAndroidMk(ret, p.binaryDecorator.pythonInstaller) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 81 | func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMkData) { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 82 | // Soong installation is only supported for host modules. Have Make |
| 83 | // installation trigger Soong installation. |
| 84 | if base.Target().Os.Class == android.Host { |
| 85 | ret.OutputFile = android.OptionalPathForPath(installer.path) |
| 86 | } |
| 87 | |
Nan Zhang | ccf636e | 2018-05-23 14:42:44 -0700 | [diff] [blame] | 88 | ret.Required = append(ret.Required, "libc++") |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 89 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 90 | path, file := filepath.Split(installer.path.ToMakePath().String()) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 91 | stem := strings.TrimSuffix(file, filepath.Ext(file)) |
| 92 | |
| 93 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 94 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 95 | fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) |
Logan Chien | 02880e4 | 2018-11-06 17:30:35 +0800 | [diff] [blame] | 96 | fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " ")) |
Dan Willemsen | bc32a50 | 2020-03-11 20:54:00 +0000 | [diff] [blame] | 97 | fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES := false") |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 98 | }) |
| 99 | } |