2019-08-28 03:03:00 +08:00
|
|
|
// Copyright 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AndroidMkContext interface {
|
|
|
|
Name() string
|
|
|
|
Target() android.Target
|
2020-08-05 21:36:19 +08:00
|
|
|
SubAndroidMk(*android.AndroidMkData, interface{})
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
2020-08-05 21:36:19 +08:00
|
|
|
type SubAndroidMkProvider interface {
|
2019-08-28 03:03:00 +08:00
|
|
|
AndroidMk(AndroidMkContext, *android.AndroidMkData)
|
|
|
|
}
|
|
|
|
|
2020-08-05 21:36:19 +08:00
|
|
|
func (mod *Module) SubAndroidMk(data *android.AndroidMkData, obj interface{}) {
|
2019-08-28 03:03:00 +08:00
|
|
|
if mod.subAndroidMkOnce == nil {
|
2020-08-05 21:36:19 +08:00
|
|
|
mod.subAndroidMkOnce = make(map[SubAndroidMkProvider]bool)
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
2020-08-05 21:36:19 +08:00
|
|
|
if androidmk, ok := obj.(SubAndroidMkProvider); ok {
|
2019-08-28 03:03:00 +08:00
|
|
|
if !mod.subAndroidMkOnce[androidmk] {
|
|
|
|
mod.subAndroidMkOnce[androidmk] = true
|
|
|
|
androidmk.AndroidMk(mod, data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) AndroidMk() android.AndroidMkData {
|
2020-04-09 21:56:02 +08:00
|
|
|
if mod.Properties.HideFromMake {
|
|
|
|
return android.AndroidMkData{
|
|
|
|
Disabled: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
ret := android.AndroidMkData{
|
|
|
|
OutputFile: mod.outputFile,
|
|
|
|
Include: "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk",
|
|
|
|
Extra: []android.AndroidMkExtraFunc{
|
|
|
|
func(w io.Writer, outputFile android.Path) {
|
|
|
|
if len(mod.Properties.AndroidMkRlibs) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_RLIB_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkRlibs, " "))
|
|
|
|
}
|
|
|
|
if len(mod.Properties.AndroidMkDylibs) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_DYLIB_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkDylibs, " "))
|
|
|
|
}
|
|
|
|
if len(mod.Properties.AndroidMkProcMacroLibs) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_PROC_MACRO_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkProcMacroLibs, " "))
|
|
|
|
}
|
|
|
|
if len(mod.Properties.AndroidMkSharedLibs) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkSharedLibs, " "))
|
|
|
|
}
|
|
|
|
if len(mod.Properties.AndroidMkStaticLibs) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_STATIC_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkStaticLibs, " "))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-08-01 01:40:31 +08:00
|
|
|
|
|
|
|
if mod.compiler != nil && !mod.compiler.Disabled() {
|
2020-08-05 21:36:19 +08:00
|
|
|
mod.SubAndroidMk(&ret, mod.compiler)
|
2020-07-08 20:39:44 +08:00
|
|
|
} else if mod.sourceProvider != nil {
|
2020-08-01 01:40:31 +08:00
|
|
|
// If the compiler is disabled, this is a SourceProvider.
|
2020-08-05 21:36:19 +08:00
|
|
|
mod.SubAndroidMk(&ret, mod.sourceProvider)
|
2020-07-08 20:39:44 +08:00
|
|
|
}
|
2019-10-25 11:47:54 +08:00
|
|
|
ret.SubName += mod.Properties.SubName
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
2020-08-05 21:36:19 +08:00
|
|
|
ctx.SubAndroidMk(ret, binary.baseCompiler)
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2020-06-15 13:24:19 +08:00
|
|
|
if binary.distFile.Valid() {
|
|
|
|
ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path())
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
ret.Class = "EXECUTABLES"
|
|
|
|
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
2020-04-09 21:56:02 +08:00
|
|
|
if binary.coverageOutputZipFile.Valid() {
|
|
|
|
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+binary.coverageOutputZipFile.String())
|
|
|
|
}
|
2019-08-28 03:03:00 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:56:47 +08:00
|
|
|
func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
2019-10-25 11:47:54 +08:00
|
|
|
test.binaryDecorator.AndroidMk(ctx, ret)
|
2019-11-15 20:14:44 +08:00
|
|
|
ret.Class = "NATIVE_TESTS"
|
2019-11-01 11:56:47 +08:00
|
|
|
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
|
|
|
if len(test.Properties.Test_suites) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
|
|
|
|
strings.Join(test.Properties.Test_suites, " "))
|
|
|
|
}
|
|
|
|
if test.testConfig != nil {
|
|
|
|
fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", test.testConfig.String())
|
|
|
|
}
|
2020-01-07 07:47:57 +08:00
|
|
|
if !BoolDefault(test.Properties.Auto_gen_config, true) {
|
|
|
|
fmt.Fprintln(w, "LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG := true")
|
|
|
|
}
|
2019-11-01 11:56:47 +08:00
|
|
|
})
|
|
|
|
// TODO(chh): add test data with androidMkWriteTestData(test.data, ctx, ret)
|
2019-10-25 11:47:54 +08:00
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
2020-08-05 21:36:19 +08:00
|
|
|
ctx.SubAndroidMk(ret, library.baseCompiler)
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
if library.rlib() {
|
|
|
|
ret.Class = "RLIB_LIBRARIES"
|
|
|
|
} else if library.dylib() {
|
|
|
|
ret.Class = "DYLIB_LIBRARIES"
|
2019-10-19 05:49:46 +08:00
|
|
|
} else if library.static() {
|
|
|
|
ret.Class = "STATIC_LIBRARIES"
|
|
|
|
} else if library.shared() {
|
|
|
|
ret.Class = "SHARED_LIBRARIES"
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
2019-10-19 05:49:46 +08:00
|
|
|
|
2020-06-15 13:24:19 +08:00
|
|
|
if library.distFile.Valid() {
|
|
|
|
ret.DistFiles = android.MakeDefaultDistFiles(library.distFile.Path())
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
2020-04-09 21:56:02 +08:00
|
|
|
if library.coverageOutputZipFile.Valid() {
|
|
|
|
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+library.coverageOutputZipFile.String())
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
2020-08-05 21:36:19 +08:00
|
|
|
ctx.SubAndroidMk(ret, procMacro.baseCompiler)
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
ret.Class = "PROC_MACRO_LIBRARIES"
|
2020-06-15 13:24:19 +08:00
|
|
|
if procMacro.distFile.Valid() {
|
|
|
|
ret.DistFiles = android.MakeDefaultDistFiles(procMacro.distFile.Path())
|
|
|
|
}
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-05 21:36:19 +08:00
|
|
|
func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
|
|
|
outFile := sourceProvider.OutputFile
|
2020-07-08 20:39:44 +08:00
|
|
|
ret.Class = "ETC"
|
|
|
|
ret.OutputFile = android.OptionalPathForPath(outFile)
|
2020-08-01 01:40:31 +08:00
|
|
|
ret.SubName += sourceProvider.subName
|
2020-07-08 20:39:44 +08:00
|
|
|
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
|
|
|
_, file := filepath.Split(outFile.String())
|
|
|
|
stem, suffix, _ := android.SplitFileExt(file)
|
|
|
|
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
|
|
|
|
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
|
2020-08-21 18:01:58 +08:00
|
|
|
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
2020-07-08 20:39:44 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
2020-08-05 21:36:19 +08:00
|
|
|
ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider)
|
2020-08-21 18:01:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
|
|
|
ctx.SubAndroidMk(ret, proto.BaseSourceProvider)
|
2020-07-08 20:39:44 +08:00
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
2020-09-09 00:46:52 +08:00
|
|
|
if compiler.path == (android.InstallPath{}) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-27 19:48:36 +08:00
|
|
|
var unstrippedOutputFile android.OptionalPath
|
2019-08-28 03:03:00 +08:00
|
|
|
// Soong installation is only supported for host modules. Have Make
|
|
|
|
// installation trigger Soong installation.
|
|
|
|
if ctx.Target().Os.Class == android.Host {
|
|
|
|
ret.OutputFile = android.OptionalPathForPath(compiler.path)
|
2020-08-27 19:48:36 +08:00
|
|
|
} else if compiler.strippedOutputFile.Valid() {
|
|
|
|
unstrippedOutputFile = ret.OutputFile
|
|
|
|
ret.OutputFile = compiler.strippedOutputFile
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
2020-08-27 19:48:36 +08:00
|
|
|
if compiler.strippedOutputFile.Valid() {
|
|
|
|
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", unstrippedOutputFile)
|
|
|
|
}
|
2019-10-03 07:01:35 +08:00
|
|
|
path, file := filepath.Split(compiler.path.ToMakePath().String())
|
2019-09-10 11:29:31 +08:00
|
|
|
stem, suffix, _ := android.SplitFileExt(file)
|
2019-08-28 03:03:00 +08:00
|
|
|
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
|
2019-10-03 07:01:35 +08:00
|
|
|
fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
|
2019-08-28 03:03:00 +08:00
|
|
|
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
|
|
|
|
})
|
|
|
|
}
|