blob: 8ad5889b57cca5e84c90125ecab05d220b1e033c [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 "fmt"
19 "io"
20 "path/filepath"
21 "strings"
Dan Shi31949122020-09-21 12:11:02 -070022
23 "android/soong/android"
Nan Zhang5323f8e2017-05-10 13:37:54 -070024)
25
26type subAndroidMkProvider interface {
Nan Zhangd4e641b2017-07-12 12:55:28 -070027 AndroidMk(*Module, *android.AndroidMkData)
Nan Zhang5323f8e2017-05-10 13:37:54 -070028}
29
Nan Zhangd4e641b2017-07-12 12:55:28 -070030func (p *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) {
Nan Zhang5323f8e2017-05-10 13:37:54 -070031 if p.subAndroidMkOnce == nil {
32 p.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
33 }
34 if androidmk, ok := obj.(subAndroidMkProvider); ok {
35 if !p.subAndroidMkOnce[androidmk] {
36 p.subAndroidMkOnce[androidmk] = true
37 androidmk.AndroidMk(p, data)
38 }
39 }
40}
41
Nan Zhangd4e641b2017-07-12 12:55:28 -070042func (p *Module) AndroidMk() android.AndroidMkData {
Nan Zhangd9ec5e72017-12-01 20:00:31 +000043 ret := android.AndroidMkData{OutputFile: p.installSource}
Colin Crossa18e9cf2017-08-10 17:00:19 -070044
Nan Zhang5323f8e2017-05-10 13:37:54 -070045 p.subAndroidMk(&ret, p.installer)
46
Colin Crossa18e9cf2017-08-10 17:00:19 -070047 return ret
Nan Zhang5323f8e2017-05-10 13:37:54 -070048}
49
Nan Zhangd4e641b2017-07-12 12:55:28 -070050func (p *binaryDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) {
Nan Zhang5323f8e2017-05-10 13:37:54 -070051 ret.Class = "EXECUTABLES"
Nan Zhangc9c6cb72017-11-03 16:54:05 -070052
53 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
54 if len(p.binaryProperties.Test_suites) > 0 {
55 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
56 strings.Join(p.binaryProperties.Test_suites, " "))
57 }
58 })
Nan Zhangd9ec5e72017-12-01 20:00:31 +000059 base.subAndroidMk(ret, p.pythonInstaller)
Nan Zhang5323f8e2017-05-10 13:37:54 -070060}
61
Nan Zhangd4e641b2017-07-12 12:55:28 -070062func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) {
Nan Zhang5323f8e2017-05-10 13:37:54 -070063 ret.Class = "NATIVE_TESTS"
Nan Zhangc9c6cb72017-11-03 16:54:05 -070064
65 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
66 if len(p.binaryDecorator.binaryProperties.Test_suites) > 0 {
67 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
68 strings.Join(p.binaryDecorator.binaryProperties.Test_suites, " "))
69 }
Colin Crossa6384822020-06-09 15:09:22 -070070 if p.testConfig != nil {
71 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=",
72 p.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -070073 }
Dan Shi2468d012020-01-06 15:47:57 -080074
75 if !BoolDefault(p.binaryProperties.Auto_gen_config, true) {
76 fmt.Fprintln(w, "LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG := true")
77 }
Dan Shi31949122020-09-21 12:11:02 -070078
79 if len(p.data) > 0 {
80 fmt.Fprintln(w, "LOCAL_TEST_DATA :=",
81 strings.Join(android.AndroidMkDataPaths(p.data), " "))
82 }
Nan Zhangc9c6cb72017-11-03 16:54:05 -070083 })
Nan Zhangd9ec5e72017-12-01 20:00:31 +000084 base.subAndroidMk(ret, p.binaryDecorator.pythonInstaller)
Nan Zhang5323f8e2017-05-10 13:37:54 -070085}
86
Nan Zhangd4e641b2017-07-12 12:55:28 -070087func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMkData) {
Nan Zhang5323f8e2017-05-10 13:37:54 -070088 // Soong installation is only supported for host modules. Have Make
89 // installation trigger Soong installation.
90 if base.Target().Os.Class == android.Host {
91 ret.OutputFile = android.OptionalPathForPath(installer.path)
92 }
93
Nan Zhangccf636e2018-05-23 14:42:44 -070094 ret.Required = append(ret.Required, "libc++")
Colin Cross27a4b052017-08-10 16:32:23 -070095 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossff6c33d2019-10-02 16:01:35 -070096 path, file := filepath.Split(installer.path.ToMakePath().String())
Nan Zhang5323f8e2017-05-10 13:37:54 -070097 stem := strings.TrimSuffix(file, filepath.Ext(file))
98
99 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file))
Colin Crossff6c33d2019-10-02 16:01:35 -0700100 fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
Nan Zhang5323f8e2017-05-10 13:37:54 -0700101 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Logan Chien02880e42018-11-06 17:30:35 +0800102 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " "))
Dan Willemsenbc32a502020-03-11 20:54:00 +0000103 fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES := false")
Nan Zhang5323f8e2017-05-10 13:37:54 -0700104 })
105}