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 { |
| 26 | AndroidMk(*pythonBaseModule, *android.AndroidMkData) |
| 27 | } |
| 28 | |
| 29 | func (p *pythonBaseModule) subAndroidMk(data *android.AndroidMkData, obj interface{}) { |
| 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 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame^] | 41 | func (p *pythonBaseModule) AndroidMk() android.AndroidMkData { |
| 42 | ret := android.AndroidMkData{} |
| 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 | |
| 49 | func (p *pythonBinaryHostDecorator) AndroidMk(base *pythonBaseModule, ret *android.AndroidMkData) { |
| 50 | ret.Class = "EXECUTABLES" |
| 51 | base.subAndroidMk(ret, p.pythonDecorator.baseInstaller) |
| 52 | } |
| 53 | |
| 54 | func (p *pythonTestHostDecorator) AndroidMk(base *pythonBaseModule, ret *android.AndroidMkData) { |
| 55 | ret.Class = "NATIVE_TESTS" |
| 56 | base.subAndroidMk(ret, p.pythonDecorator.baseInstaller) |
| 57 | } |
| 58 | |
| 59 | func (installer *pythonInstaller) AndroidMk(base *pythonBaseModule, ret *android.AndroidMkData) { |
| 60 | // Soong installation is only supported for host modules. Have Make |
| 61 | // installation trigger Soong installation. |
| 62 | if base.Target().Os.Class == android.Host { |
| 63 | ret.OutputFile = android.OptionalPathForPath(installer.path) |
| 64 | } |
| 65 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 66 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 67 | path := installer.path.RelPathString() |
| 68 | dir, file := filepath.Split(path) |
| 69 | stem := strings.TrimSuffix(file, filepath.Ext(file)) |
| 70 | |
| 71 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) |
| 72 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) |
| 73 | fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 74 | }) |
| 75 | } |