Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Android Open Source Project |
| 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 rust |
| 16 | |
| 17 | import ( |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 18 | "path/filepath" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 19 | |
| 20 | "android/soong/android" |
Ivan Lozano | 9da4aa8 | 2021-01-29 12:48:05 -0500 | [diff] [blame] | 21 | "android/soong/cc" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | type AndroidMkContext interface { |
| 25 | Name() string |
| 26 | Target() android.Target |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 27 | SubAndroidMk(*android.AndroidMkEntries, interface{}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 30 | type SubAndroidMkProvider interface { |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 31 | AndroidMk(AndroidMkContext, *android.AndroidMkEntries) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 34 | func (mod *Module) SubAndroidMk(data *android.AndroidMkEntries, obj interface{}) { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 35 | if mod.subAndroidMkOnce == nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 36 | mod.subAndroidMkOnce = make(map[SubAndroidMkProvider]bool) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 37 | } |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 38 | if androidmk, ok := obj.(SubAndroidMkProvider); ok { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 39 | if !mod.subAndroidMkOnce[androidmk] { |
| 40 | mod.subAndroidMkOnce[androidmk] = true |
| 41 | androidmk.AndroidMk(mod, data) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 46 | func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 47 | if mod.Properties.HideFromMake || mod.hideApexVariantFromMake { |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 48 | |
| 49 | return []android.AndroidMkEntries{android.AndroidMkEntries{Disabled: true}} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 52 | ret := android.AndroidMkEntries{ |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 53 | OutputFile: mod.outputFile, |
| 54 | Include: "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk", |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 55 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 56 | func(entries *android.AndroidMkEntries) { |
| 57 | entries.AddStrings("LOCAL_RLIB_LIBRARIES", mod.Properties.AndroidMkRlibs...) |
| 58 | entries.AddStrings("LOCAL_DYLIB_LIBRARIES", mod.Properties.AndroidMkDylibs...) |
| 59 | entries.AddStrings("LOCAL_PROC_MACRO_LIBRARIES", mod.Properties.AndroidMkProcMacroLibs...) |
| 60 | entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.Properties.AndroidMkSharedLibs...) |
| 61 | entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 62 | entries.AddStrings("LOCAL_SOONG_LINK_TYPE", mod.makeLinkType) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 63 | }, |
| 64 | }, |
| 65 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 66 | |
| 67 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 68 | mod.SubAndroidMk(&ret, mod.compiler) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 69 | } else if mod.sourceProvider != nil { |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 70 | // If the compiler is disabled, this is a SourceProvider. |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 71 | mod.SubAndroidMk(&ret, mod.sourceProvider) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 72 | } |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 73 | ret.SubName += mod.Properties.SubName |
| 74 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 75 | return []android.AndroidMkEntries{ret} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 78 | func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 79 | ctx.SubAndroidMk(ret, binary.baseCompiler) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 80 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 81 | if binary.distFile.Valid() { |
| 82 | ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path()) |
| 83 | } |
| 84 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 85 | ret.Class = "EXECUTABLES" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 88 | func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Ivan Lozano | 9da4aa8 | 2021-01-29 12:48:05 -0500 | [diff] [blame] | 89 | ctx.SubAndroidMk(ret, test.binaryDecorator) |
| 90 | |
Chih-Hung Hsieh | 15f369e | 2019-11-15 04:14:44 -0800 | [diff] [blame] | 91 | ret.Class = "NATIVE_TESTS" |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 92 | ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) { |
Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 93 | entries.AddCompatibilityTestSuites(test.Properties.Test_suites...) |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 94 | if test.testConfig != nil { |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 95 | entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String()) |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 96 | } |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 97 | entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true)) |
| 98 | entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(test.Properties.Test_options.Unit_test)) |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 99 | }) |
Ivan Lozano | 9da4aa8 | 2021-01-29 12:48:05 -0500 | [diff] [blame] | 100 | |
| 101 | cc.AndroidMkWriteTestData(test.data, ret) |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 104 | func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 105 | ctx.SubAndroidMk(ret, library.baseCompiler) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 106 | |
| 107 | if library.rlib() { |
| 108 | ret.Class = "RLIB_LIBRARIES" |
| 109 | } else if library.dylib() { |
| 110 | ret.Class = "DYLIB_LIBRARIES" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 111 | } else if library.static() { |
| 112 | ret.Class = "STATIC_LIBRARIES" |
| 113 | } else if library.shared() { |
| 114 | ret.Class = "SHARED_LIBRARIES" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 115 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 116 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 117 | if library.distFile.Valid() { |
| 118 | ret.DistFiles = android.MakeDefaultDistFiles(library.distFile.Path()) |
| 119 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 122 | func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 123 | ctx.SubAndroidMk(ret, procMacro.baseCompiler) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 124 | |
| 125 | ret.Class = "PROC_MACRO_LIBRARIES" |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 126 | if procMacro.distFile.Valid() { |
| 127 | ret.DistFiles = android.MakeDefaultDistFiles(procMacro.distFile.Path()) |
| 128 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 129 | |
| 130 | } |
| 131 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 132 | func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 133 | outFile := sourceProvider.OutputFiles[0] |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 134 | ret.Class = "ETC" |
| 135 | ret.OutputFile = android.OptionalPathForPath(outFile) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 136 | ret.SubName += sourceProvider.subName |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 137 | ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) { |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 138 | _, file := filepath.Split(outFile.String()) |
| 139 | stem, suffix, _ := android.SplitFileExt(file) |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 140 | entries.SetString("LOCAL_MODULE_SUFFIX", suffix) |
| 141 | entries.SetString("LOCAL_MODULE_STEM", stem) |
| 142 | entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 143 | }) |
| 144 | } |
| 145 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 146 | func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 147 | ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider) |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 150 | func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 151 | ctx.SubAndroidMk(ret, proto.BaseSourceProvider) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 154 | func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 155 | if compiler.path == (android.InstallPath{}) { |
| 156 | return |
| 157 | } |
| 158 | |
ThiƩbaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 159 | var unstrippedOutputFile android.OptionalPath |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 160 | // Soong installation is only supported for host modules. Have Make |
| 161 | // installation trigger Soong installation. |
| 162 | if ctx.Target().Os.Class == android.Host { |
| 163 | ret.OutputFile = android.OptionalPathForPath(compiler.path) |
ThiƩbaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 164 | } else if compiler.strippedOutputFile.Valid() { |
| 165 | unstrippedOutputFile = ret.OutputFile |
| 166 | ret.OutputFile = compiler.strippedOutputFile |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 167 | } |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 168 | ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) { |
| 169 | entries.SetOptionalPath("LOCAL_SOONG_UNSTRIPPED_BINARY", unstrippedOutputFile) |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 170 | path, file := filepath.Split(compiler.path.ToMakePath().String()) |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 171 | stem, suffix, _ := android.SplitFileExt(file) |
Liz Kammer | 4018a8d | 2020-11-24 09:35:21 -0800 | [diff] [blame] | 172 | entries.SetString("LOCAL_MODULE_SUFFIX", suffix) |
| 173 | entries.SetString("LOCAL_MODULE_PATH", path) |
| 174 | entries.SetString("LOCAL_MODULE_STEM", stem) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 175 | }) |
| 176 | } |