blob: 13b41723e3e8a449bc8a2653684b580831043ec3 [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
Colin Crossf79fee82020-07-03 13:18:24 -070051 entries.ExtraEntries = append(entries.ExtraEntries,
52 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
53 entries.AddCompatibilityTestSuites(p.binaryProperties.Test_suites...)
54 })
Liz Kammerd8dceb02020-11-24 08:36:14 -080055 base.subAndroidMk(entries, p.pythonInstaller)
Nan Zhang5323f8e2017-05-10 13:37:54 -070056}
57
Liz Kammerd8dceb02020-11-24 08:36:14 -080058func (p *testDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
59 entries.Class = "NATIVE_TESTS"
Nan Zhangc9c6cb72017-11-03 16:54:05 -070060
Colin Crossf79fee82020-07-03 13:18:24 -070061 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 Shi2468d012020-01-06 15:47:57 -080067
Colin Crossf79fee82020-07-03 13:18:24 -070068 entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(p.binaryProperties.Auto_gen_config, true))
Dan Shi31949122020-09-21 12:11:02 -070069
Colin Crossf79fee82020-07-03 13:18:24 -070070 entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...)
Dan Shid79572f2020-11-13 14:33:46 -080071
Colin Crossf79fee82020-07-03 13:18:24 -070072 entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(p.testProperties.Test_options.Unit_test))
73 })
Liz Kammerd8dceb02020-11-24 08:36:14 -080074 base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller)
Nan Zhang5323f8e2017-05-10 13:37:54 -070075}
76
Liz Kammerd8dceb02020-11-24 08:36:14 -080077func (installer *pythonInstaller) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
Nan Zhang5323f8e2017-05-10 13:37:54 -070078 // Soong installation is only supported for host modules. Have Make
79 // installation trigger Soong installation.
80 if base.Target().Os.Class == android.Host {
Liz Kammerd8dceb02020-11-24 08:36:14 -080081 entries.OutputFile = android.OptionalPathForPath(installer.path)
Nan Zhang5323f8e2017-05-10 13:37:54 -070082 }
83
Liz Kammerd8dceb02020-11-24 08:36:14 -080084 entries.Required = append(entries.Required, "libc++")
Colin Crossf79fee82020-07-03 13:18:24 -070085 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 Zhang5323f8e2017-05-10 13:37:54 -070089
Colin Crossf79fee82020-07-03 13:18:24 -070090 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 Zhang5323f8e2017-05-10 13:37:54 -070096}