2019-08-27 21:03:00 +02: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 (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2021-01-29 18:48:05 +01:00
|
|
|
"android/soong/cc"
|
2019-08-27 21:03:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type AndroidMkContext interface {
|
|
|
|
Name() string
|
|
|
|
Target() android.Target
|
2020-11-24 18:35:21 +01:00
|
|
|
SubAndroidMk(*android.AndroidMkEntries, interface{})
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
type SubAndroidMkProvider interface {
|
2020-11-24 18:35:21 +01:00
|
|
|
AndroidMk(AndroidMkContext, *android.AndroidMkEntries)
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (mod *Module) SubAndroidMk(data *android.AndroidMkEntries, obj interface{}) {
|
2019-08-27 21:03:00 +02:00
|
|
|
if mod.subAndroidMkOnce == nil {
|
2020-08-05 15:36:19 +02:00
|
|
|
mod.subAndroidMkOnce = make(map[SubAndroidMkProvider]bool)
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2020-08-05 15:36:19 +02:00
|
|
|
if androidmk, ok := obj.(SubAndroidMkProvider); ok {
|
2019-08-27 21:03:00 +02:00
|
|
|
if !mod.subAndroidMkOnce[androidmk] {
|
|
|
|
mod.subAndroidMkOnce[androidmk] = true
|
|
|
|
androidmk.AndroidMk(mod, data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
|
2020-11-17 14:21:02 +01:00
|
|
|
if mod.Properties.HideFromMake || mod.hideApexVariantFromMake {
|
2020-11-24 18:35:21 +01:00
|
|
|
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{Disabled: true}}
|
2020-04-09 15:56:02 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
ret := android.AndroidMkEntries{
|
2021-04-07 08:08:04 +02:00
|
|
|
OutputFile: mod.unstrippedOutputFile,
|
2019-08-27 21:03:00 +02:00
|
|
|
Include: "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk",
|
2020-11-24 18:35:21 +01:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-03 22:18:24 +02:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2020-11-24 18:35:21 +01:00
|
|
|
entries.AddStrings("LOCAL_RLIB_LIBRARIES", mod.Properties.AndroidMkRlibs...)
|
|
|
|
entries.AddStrings("LOCAL_DYLIB_LIBRARIES", mod.Properties.AndroidMkDylibs...)
|
|
|
|
entries.AddStrings("LOCAL_PROC_MACRO_LIBRARIES", mod.Properties.AndroidMkProcMacroLibs...)
|
|
|
|
entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.Properties.AndroidMkSharedLibs...)
|
|
|
|
entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...)
|
2020-12-02 15:15:16 +01:00
|
|
|
entries.AddStrings("LOCAL_SOONG_LINK_TYPE", mod.makeLinkType)
|
2021-04-02 18:41:32 +02:00
|
|
|
if mod.UseVndk() {
|
|
|
|
entries.SetBool("LOCAL_USE_VNDK", true)
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-07-31 19:40:31 +02:00
|
|
|
|
|
|
|
if mod.compiler != nil && !mod.compiler.Disabled() {
|
2020-08-05 15:36:19 +02:00
|
|
|
mod.SubAndroidMk(&ret, mod.compiler)
|
2020-07-08 14:39:44 +02:00
|
|
|
} else if mod.sourceProvider != nil {
|
2020-07-31 19:40:31 +02:00
|
|
|
// If the compiler is disabled, this is a SourceProvider.
|
2020-08-05 15:36:19 +02:00
|
|
|
mod.SubAndroidMk(&ret, mod.sourceProvider)
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
2021-04-01 22:59:27 +02:00
|
|
|
|
|
|
|
if mod.sanitize != nil {
|
|
|
|
mod.SubAndroidMk(&ret, mod.sanitize)
|
|
|
|
}
|
|
|
|
|
2021-04-02 18:41:32 +02:00
|
|
|
ret.SubName += mod.Properties.RustSubName
|
2019-10-25 05:47:54 +02:00
|
|
|
ret.SubName += mod.Properties.SubName
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
return []android.AndroidMkEntries{ret}
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2020-08-05 15:36:19 +02:00
|
|
|
ctx.SubAndroidMk(ret, binary.baseCompiler)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2020-06-15 07:24:19 +02:00
|
|
|
if binary.distFile.Valid() {
|
|
|
|
ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path())
|
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
ret.Class = "EXECUTABLES"
|
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2021-01-29 18:48:05 +01:00
|
|
|
ctx.SubAndroidMk(ret, test.binaryDecorator)
|
|
|
|
|
2019-11-15 13:14:44 +01:00
|
|
|
ret.Class = "NATIVE_TESTS"
|
2020-07-03 22:18:24 +02:00
|
|
|
ret.ExtraEntries = append(ret.ExtraEntries,
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
|
|
|
entries.AddCompatibilityTestSuites(test.Properties.Test_suites...)
|
|
|
|
if test.testConfig != nil {
|
|
|
|
entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
|
|
|
|
}
|
|
|
|
entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true))
|
|
|
|
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(test.Properties.Test_options.Unit_test))
|
|
|
|
})
|
2021-01-29 18:48:05 +01:00
|
|
|
|
|
|
|
cc.AndroidMkWriteTestData(test.data, ret)
|
2019-10-25 05:47:54 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 15:57:27 +01:00
|
|
|
func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
|
|
|
benchmark.binaryDecorator.AndroidMk(ctx, ret)
|
|
|
|
ret.Class = "NATIVE_TESTS"
|
|
|
|
ret.ExtraEntries = append(ret.ExtraEntries,
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
|
|
|
entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...)
|
|
|
|
if benchmark.testConfig != nil {
|
|
|
|
entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
|
|
|
|
}
|
|
|
|
entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
|
|
|
|
entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(benchmark.Properties.Auto_gen_config, true))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2020-08-05 15:36:19 +02:00
|
|
|
ctx.SubAndroidMk(ret, library.baseCompiler)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
if library.rlib() {
|
|
|
|
ret.Class = "RLIB_LIBRARIES"
|
|
|
|
} else if library.dylib() {
|
|
|
|
ret.Class = "DYLIB_LIBRARIES"
|
2019-10-18 23:49:46 +02:00
|
|
|
} else if library.static() {
|
|
|
|
ret.Class = "STATIC_LIBRARIES"
|
|
|
|
} else if library.shared() {
|
|
|
|
ret.Class = "SHARED_LIBRARIES"
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2019-10-18 23:49:46 +02:00
|
|
|
|
2020-06-15 07:24:19 +02:00
|
|
|
if library.distFile.Valid() {
|
|
|
|
ret.DistFiles = android.MakeDefaultDistFiles(library.distFile.Path())
|
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2020-08-05 15:36:19 +02:00
|
|
|
ctx.SubAndroidMk(ret, procMacro.baseCompiler)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
ret.Class = "PROC_MACRO_LIBRARIES"
|
2020-06-15 07:24:19 +02:00
|
|
|
if procMacro.distFile.Valid() {
|
|
|
|
ret.DistFiles = android.MakeDefaultDistFiles(procMacro.distFile.Path())
|
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2020-10-02 06:25:05 +02:00
|
|
|
outFile := sourceProvider.OutputFiles[0]
|
2020-07-08 14:39:44 +02:00
|
|
|
ret.Class = "ETC"
|
|
|
|
ret.OutputFile = android.OptionalPathForPath(outFile)
|
2020-07-31 19:40:31 +02:00
|
|
|
ret.SubName += sourceProvider.subName
|
2020-07-03 22:18:24 +02:00
|
|
|
ret.ExtraEntries = append(ret.ExtraEntries,
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
|
|
|
_, file := filepath.Split(outFile.String())
|
|
|
|
stem, suffix, _ := android.SplitFileExt(file)
|
|
|
|
entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
|
|
|
|
entries.SetString("LOCAL_MODULE_STEM", stem)
|
|
|
|
entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
|
|
|
|
})
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2020-08-05 15:36:19 +02:00
|
|
|
ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider)
|
2020-08-21 12:01:58 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2020-08-21 12:01:58 +02:00
|
|
|
ctx.SubAndroidMk(ret, proto.BaseSourceProvider)
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 18:35:21 +01:00
|
|
|
func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
2020-09-08 18:46:52 +02:00
|
|
|
if compiler.path == (android.InstallPath{}) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-27 13:48:36 +02:00
|
|
|
var unstrippedOutputFile android.OptionalPath
|
2019-08-27 21:03:00 +02: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 13:48:36 +02:00
|
|
|
} else if compiler.strippedOutputFile.Valid() {
|
|
|
|
unstrippedOutputFile = ret.OutputFile
|
|
|
|
ret.OutputFile = compiler.strippedOutputFile
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2020-07-03 22:18:24 +02:00
|
|
|
ret.ExtraEntries = append(ret.ExtraEntries,
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
|
|
|
entries.SetOptionalPath("LOCAL_SOONG_UNSTRIPPED_BINARY", unstrippedOutputFile)
|
|
|
|
path, file := filepath.Split(compiler.path.ToMakePath().String())
|
|
|
|
stem, suffix, _ := android.SplitFileExt(file)
|
|
|
|
entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
|
|
|
|
entries.SetString("LOCAL_MODULE_PATH", path)
|
|
|
|
entries.SetString("LOCAL_MODULE_STEM", stem)
|
|
|
|
})
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2021-04-29 21:50:47 +02:00
|
|
|
|
|
|
|
func (fuzz *fuzzDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
|
|
|
ctx.SubAndroidMk(entries, fuzz.binaryDecorator)
|
|
|
|
|
|
|
|
var fuzzFiles []string
|
|
|
|
for _, d := range fuzz.corpus {
|
|
|
|
fuzzFiles = append(fuzzFiles,
|
|
|
|
filepath.Dir(fuzz.corpusIntermediateDir.String())+":corpus/"+d.Base())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, d := range fuzz.data {
|
|
|
|
fuzzFiles = append(fuzzFiles,
|
|
|
|
filepath.Dir(fuzz.dataIntermediateDir.String())+":data/"+d.Rel())
|
|
|
|
}
|
|
|
|
|
|
|
|
if fuzz.dictionary != nil {
|
|
|
|
fuzzFiles = append(fuzzFiles,
|
|
|
|
filepath.Dir(fuzz.dictionary.String())+":"+fuzz.dictionary.Base())
|
|
|
|
}
|
|
|
|
|
|
|
|
if fuzz.config != nil {
|
|
|
|
fuzzFiles = append(fuzzFiles,
|
|
|
|
filepath.Dir(fuzz.config.String())+":config.json")
|
|
|
|
}
|
|
|
|
|
|
|
|
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext,
|
|
|
|
entries *android.AndroidMkEntries) {
|
|
|
|
entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
|
|
|
|
if len(fuzzFiles) > 0 {
|
|
|
|
entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|