blob: e60c5385b542a7f5ecdeb985a31c2d69e27efe25 [file] [log] [blame]
Nan Zhang5323f8e2017-05-10 13:37:54 -07001// 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 (
Nan Zhang5323f8e2017-05-10 13:37:54 -070018 "path/filepath"
19 "strings"
Dan Shi31949122020-09-21 12:11:02 -070020
21 "android/soong/android"
Nan Zhang5323f8e2017-05-10 13:37:54 -070022)
23
24type subAndroidMkProvider interface {
Liz Kammerd8dceb02020-11-24 08:36:14 -080025 AndroidMk(*Module, *android.AndroidMkEntries)
Nan Zhang5323f8e2017-05-10 13:37:54 -070026}
27
Liz Kammerd8dceb02020-11-24 08:36:14 -080028func (p *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) {
Nan Zhang5323f8e2017-05-10 13:37:54 -070029 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 Kammerd8dceb02020-11-24 08:36:14 -080035 androidmk.AndroidMk(p, entries)
Nan Zhang5323f8e2017-05-10 13:37:54 -070036 }
37 }
38}
39
Liz Kammerd8dceb02020-11-24 08:36:14 -080040func (p *Module) AndroidMkEntries() []android.AndroidMkEntries {
41 entries := android.AndroidMkEntries{OutputFile: p.installSource}
Colin Crossa18e9cf2017-08-10 17:00:19 -070042
Liz Kammerd8dceb02020-11-24 08:36:14 -080043 p.subAndroidMk(&entries, p.installer)
Nan Zhang5323f8e2017-05-10 13:37:54 -070044
Liz Kammerd8dceb02020-11-24 08:36:14 -080045 return []android.AndroidMkEntries{entries}
Nan Zhang5323f8e2017-05-10 13:37:54 -070046}
47
Liz Kammerd8dceb02020-11-24 08:36:14 -080048func (p *binaryDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
49 entries.Class = "EXECUTABLES"
Nan Zhangc9c6cb72017-11-03 16:54:05 -070050
Liz Kammerd8dceb02020-11-24 08:36:14 -080051 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
52 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", p.binaryProperties.Test_suites...)
Nan Zhangc9c6cb72017-11-03 16:54:05 -070053 })
Liz Kammerd8dceb02020-11-24 08:36:14 -080054 base.subAndroidMk(entries, p.pythonInstaller)
Nan Zhang5323f8e2017-05-10 13:37:54 -070055}
56
Liz Kammerd8dceb02020-11-24 08:36:14 -080057func (p *testDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
58 entries.Class = "NATIVE_TESTS"
Nan Zhangc9c6cb72017-11-03 16:54:05 -070059
Liz Kammerd8dceb02020-11-24 08:36:14 -080060 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
61 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", p.binaryDecorator.binaryProperties.Test_suites...)
Colin Crossa6384822020-06-09 15:09:22 -070062 if p.testConfig != nil {
Liz Kammerd8dceb02020-11-24 08:36:14 -080063 entries.SetString("LOCAL_FULL_TEST_CONFIG", p.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -070064 }
Dan Shi2468d012020-01-06 15:47:57 -080065
Liz Kammerd8dceb02020-11-24 08:36:14 -080066 entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(p.binaryProperties.Auto_gen_config, true))
Dan Shi31949122020-09-21 12:11:02 -070067
Liz Kammerd8dceb02020-11-24 08:36:14 -080068 entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...)
Dan Shid79572f2020-11-13 14:33:46 -080069
Liz Kammerd8dceb02020-11-24 08:36:14 -080070 entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(p.testProperties.Test_options.Unit_test))
Nan Zhangc9c6cb72017-11-03 16:54:05 -070071 })
Liz Kammerd8dceb02020-11-24 08:36:14 -080072 base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller)
Nan Zhang5323f8e2017-05-10 13:37:54 -070073}
74
Liz Kammerd8dceb02020-11-24 08:36:14 -080075func (installer *pythonInstaller) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
Nan Zhang5323f8e2017-05-10 13:37:54 -070076 // Soong installation is only supported for host modules. Have Make
77 // installation trigger Soong installation.
78 if base.Target().Os.Class == android.Host {
Liz Kammerd8dceb02020-11-24 08:36:14 -080079 entries.OutputFile = android.OptionalPathForPath(installer.path)
Nan Zhang5323f8e2017-05-10 13:37:54 -070080 }
81
Liz Kammerd8dceb02020-11-24 08:36:14 -080082 entries.Required = append(entries.Required, "libc++")
83 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -070084 path, file := filepath.Split(installer.path.ToMakePath().String())
Nan Zhang5323f8e2017-05-10 13:37:54 -070085 stem := strings.TrimSuffix(file, filepath.Ext(file))
86
Liz Kammerd8dceb02020-11-24 08:36:14 -080087 entries.SetString("LOCAL_MODULE_SUFFIX", filepath.Ext(file))
88 entries.SetString("LOCAL_MODULE_PATH", path)
89 entries.SetString("LOCAL_MODULE_STEM", stem)
90 entries.AddStrings("LOCAL_SHARED_LIBRARIES", installer.androidMkSharedLibs...)
91 entries.SetBool("LOCAL_CHECK_ELF_FILES", false)
Nan Zhang5323f8e2017-05-10 13:37:54 -070092 })
93}