Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Kiyoung Kim | e655807 | 2019-09-30 16:58:39 +0900 | [diff] [blame] | 16 | |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 17 | #include <climits> |
| 18 | #include <cstdlib> |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 19 | #include <cstring> |
| 20 | #include <fstream> |
| 21 | #include <iostream> |
| 22 | #include <string> |
| 23 | |
Jooyung Han | a59fbd5 | 2020-01-30 12:57:34 +0900 | [diff] [blame] | 24 | #include <errno.h> |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 25 | #include <fcntl.h> |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 26 | #include <getopt.h> |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 27 | #include <sys/stat.h> |
Jooyung Han | a59fbd5 | 2020-01-30 12:57:34 +0900 | [diff] [blame] | 28 | #include <sys/types.h> |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 29 | |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 30 | #include <android-base/result.h> |
| 31 | |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 32 | #include "linkerconfig/apex.h" |
| 33 | #include "linkerconfig/apexconfig.h" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 34 | #include "linkerconfig/baseconfig.h" |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 35 | #include "linkerconfig/context.h" |
Kiyoung Kim | e655807 | 2019-09-30 16:58:39 +0900 | [diff] [blame] | 36 | #include "linkerconfig/environment.h" |
| 37 | #include "linkerconfig/legacy.h" |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 38 | #include "linkerconfig/log.h" |
Jooyung Han | 9960aca | 2020-02-06 20:17:53 +0900 | [diff] [blame] | 39 | #include "linkerconfig/namespacebuilder.h" |
Kiyoung Kim | 09cbb08 | 2019-12-05 16:44:34 +0900 | [diff] [blame] | 40 | #include "linkerconfig/recovery.h" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 41 | #include "linkerconfig/variableloader.h" |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 42 | #include "linkerconfig/variables.h" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 43 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 44 | using android::base::ErrnoError; |
| 45 | using android::base::Error; |
| 46 | using android::base::Result; |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 47 | using android::linkerconfig::contents::Context; |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 48 | using android::linkerconfig::modules::ApexInfo; |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 49 | using android::linkerconfig::modules::Configuration; |
| 50 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 51 | namespace { |
| 52 | const static struct option program_options[] = { |
| 53 | {"target", required_argument, 0, 't'}, |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 54 | {"strict", no_argument, 0, 's'}, |
Josh Gao | 76614bb | 2019-12-11 15:28:30 -0800 | [diff] [blame] | 55 | #ifndef __ANDROID__ |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 56 | {"root", required_argument, 0, 'r'}, |
| 57 | {"vndk", required_argument, 0, 'v'}, |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 58 | {"recovery", no_argument, 0, 'y'}, |
Jooyung Han | 5bbb123 | 2019-12-23 13:35:00 +0900 | [diff] [blame] | 59 | {"legacy", no_argument, 0, 'l'}, |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 60 | #endif |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 61 | {"help", no_argument, 0, 'h'}, |
| 62 | {0, 0, 0, 0}}; |
| 63 | |
| 64 | struct ProgramArgs { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 65 | std::string target_directory; |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 66 | bool strict; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 67 | std::string root; |
| 68 | std::string vndk_version; |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 69 | bool is_recovery; |
Jooyung Han | 5bbb123 | 2019-12-23 13:35:00 +0900 | [diff] [blame] | 70 | bool is_legacy; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | [[noreturn]] void PrintUsage(int status = EXIT_SUCCESS) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 74 | std::cerr << "Usage : linkerconfig [--target <target_directory>]" |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 75 | " [--strict]" |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 76 | #ifndef __ANDROID__ |
| 77 | " --root <root dir>" |
| 78 | " --vndk <vndk version>" |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 79 | " --recovery" |
Jooyung Han | 5bbb123 | 2019-12-23 13:35:00 +0900 | [diff] [blame] | 80 | " --legacy" |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 81 | #endif |
| 82 | " [--help]" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 83 | << std::endl; |
| 84 | exit(status); |
| 85 | } |
| 86 | |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 87 | std::string RealPath(std::string_view path) { |
| 88 | char resolved_path[PATH_MAX]; |
| 89 | if (realpath(path.data(), resolved_path) != nullptr) { |
| 90 | return resolved_path; |
| 91 | } |
| 92 | PrintUsage(-1); |
| 93 | } |
| 94 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 95 | bool ParseArgs(int argc, char* argv[], ProgramArgs* args) { |
| 96 | int parse_result; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 97 | while ((parse_result = getopt_long( |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 98 | argc, argv, "t:sr:v:hyl", program_options, NULL)) != -1) { |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 99 | switch (parse_result) { |
| 100 | case 't': |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 101 | args->target_directory = optarg; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 102 | break; |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 103 | case 's': |
| 104 | args->strict = true; |
| 105 | break; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 106 | case 'r': |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 107 | args->root = RealPath(optarg); |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 108 | break; |
| 109 | case 'v': |
| 110 | args->vndk_version = optarg; |
| 111 | break; |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 112 | case 'y': |
| 113 | args->is_recovery = true; |
| 114 | break; |
Jooyung Han | 5bbb123 | 2019-12-23 13:35:00 +0900 | [diff] [blame] | 115 | case 'l': |
| 116 | args->is_legacy = true; |
| 117 | break; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 118 | case 'h': |
| 119 | PrintUsage(); |
| 120 | default: |
| 121 | return false; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if (optind < argc) { |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 132 | void LoadVariables(ProgramArgs args) { |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 133 | #ifndef __ANDROID__ |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 134 | if (!args.is_recovery && (args.root == "" || args.vndk_version == "")) { |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 135 | PrintUsage(); |
| 136 | } |
| 137 | android::linkerconfig::modules::Variables::AddValue("ro.vndk.version", |
| 138 | args.vndk_version); |
| 139 | #endif |
| 140 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 141 | if (!args.is_recovery) { |
| 142 | android::linkerconfig::generator::LoadVariables(args.root); |
| 143 | } |
| 144 | } |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 145 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 146 | Result<void> WriteConfigurationToFile(Configuration& conf, |
| 147 | std::string file_path) { |
| 148 | std::ostream* out = &std::cout; |
| 149 | std::ofstream file_out; |
| 150 | |
| 151 | if (file_path != "") { |
| 152 | file_out.open(file_path); |
| 153 | if (file_out.fail()) { |
| 154 | return ErrnoError() << "Failed to open file " << file_path; |
| 155 | } |
| 156 | out = &file_out; |
| 157 | } |
| 158 | |
| 159 | android::linkerconfig::modules::ConfigWriter config_writer; |
| 160 | |
| 161 | conf.WriteConfig(config_writer); |
| 162 | *out << config_writer.ToString(); |
| 163 | if (!out->good()) { |
| 164 | return ErrnoError() << "Failed to write content to " << file_path; |
| 165 | } |
| 166 | |
| 167 | return {}; |
| 168 | } |
| 169 | |
Jooyung Han | 5f24636 | 2020-01-28 15:44:14 +0900 | [diff] [blame] | 170 | Result<void> UpdatePermission([[maybe_unused]] const std::string& file_path) { |
| 171 | #ifdef __ANDROID__ |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 172 | if (fchmodat(AT_FDCWD, |
| 173 | file_path.c_str(), |
| 174 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, |
| 175 | AT_SYMLINK_NOFOLLOW) < 0) { |
| 176 | return ErrnoError() << "Failed to update permission of " << file_path; |
| 177 | } |
Jooyung Han | 5f24636 | 2020-01-28 15:44:14 +0900 | [diff] [blame] | 178 | #endif |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 179 | |
| 180 | return {}; |
| 181 | } |
| 182 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 183 | Context GetContext(ProgramArgs args) { |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 184 | auto apex_list = android::linkerconfig::modules::ScanActiveApexes(args.root); |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 185 | Context ctx; |
| 186 | for (auto const& apex_item : apex_list) { |
| 187 | auto apex_info = apex_item.second; |
| 188 | if (apex_info.has_bin || apex_info.has_lib) { |
| 189 | ctx.AddApexModule(std::move(apex_info)); |
| 190 | } |
| 191 | } |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 192 | if (args.strict) { |
| 193 | ctx.SetStrictMode(true); |
| 194 | } |
Jooyung Han | 9960aca | 2020-02-06 20:17:53 +0900 | [diff] [blame] | 195 | android::linkerconfig::contents::RegisterApexNamespaceBuilders(ctx); |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 196 | return ctx; |
| 197 | } |
| 198 | |
| 199 | Configuration GetConfiguration(Context& ctx) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 200 | if (android::linkerconfig::modules::IsRecoveryMode()) { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 201 | return android::linkerconfig::contents::CreateRecoveryConfiguration(ctx); |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (android::linkerconfig::modules::IsLegacyDevice()) { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 205 | return android::linkerconfig::contents::CreateLegacyConfiguration(ctx); |
Kiyoung Kim | e655807 | 2019-09-30 16:58:39 +0900 | [diff] [blame] | 206 | } |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 207 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 208 | // Use base configuration in default |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 209 | return android::linkerconfig::contents::CreateBaseConfiguration(ctx); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 210 | } |
Kiyoung Kim | e3bad04 | 2019-07-23 13:38:34 +0900 | [diff] [blame] | 211 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 212 | Result<void> GenerateConfiguration(Configuration config, std::string dir_path, |
| 213 | bool update_permission) { |
| 214 | std::string file_path = ""; |
| 215 | if (dir_path != "") { |
| 216 | file_path = dir_path + "/ld.config.txt"; |
| 217 | } |
| 218 | |
| 219 | auto write_config = WriteConfigurationToFile(config, file_path); |
Bernie Innocenti | 5c32556 | 2020-02-06 23:16:23 +0900 | [diff] [blame] | 220 | if (!write_config.ok()) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 221 | return write_config; |
| 222 | } else if (update_permission && file_path != "") { |
| 223 | return UpdatePermission(file_path); |
| 224 | } |
| 225 | |
| 226 | return {}; |
| 227 | } |
| 228 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 229 | Result<void> GenerateBaseLinkerConfiguration(Context& ctx, |
| 230 | const std::string& dir_path) { |
| 231 | return GenerateConfiguration(GetConfiguration(ctx), dir_path, true); |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 232 | } |
| 233 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 234 | Result<void> GenerateRecoveryLinkerConfiguration(Context& ctx, |
| 235 | const std::string& dir_path) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 236 | return GenerateConfiguration( |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 237 | android::linkerconfig::contents::CreateRecoveryConfiguration(ctx), |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 238 | dir_path, |
| 239 | false); |
| 240 | } |
| 241 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 242 | Result<void> GenerateLegacyLinkerConfiguration(Context& ctx, |
| 243 | const std::string& dir_path) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 244 | return GenerateConfiguration( |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 245 | android::linkerconfig::contents::CreateLegacyConfiguration(ctx), |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 246 | dir_path, |
| 247 | false); |
| 248 | } |
| 249 | |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 250 | Result<void> GenerateApexConfiguration( |
| 251 | const std::string& base_dir, android::linkerconfig::contents::Context& ctx, |
| 252 | const android::linkerconfig::modules::ApexInfo& target_apex) { |
| 253 | std::string dir_path = base_dir + "/" + target_apex.name; |
Jooyung Han | a59fbd5 | 2020-01-30 12:57:34 +0900 | [diff] [blame] | 254 | if (auto ret = mkdir(dir_path.c_str(), 0755); ret != 0 && errno != EEXIST) { |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 255 | return ErrnoError() << "Failed to create directory " << dir_path; |
| 256 | } |
| 257 | |
| 258 | return GenerateConfiguration( |
| 259 | android::linkerconfig::contents::CreateApexConfiguration(ctx, target_apex), |
| 260 | dir_path, |
| 261 | true); |
| 262 | } |
| 263 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 264 | void GenerateApexConfigurations(Context& ctx, const std::string& dir_path) { |
| 265 | for (auto const& apex_item : ctx.GetApexModules()) { |
| 266 | if (apex_item.has_bin) { |
| 267 | auto result = GenerateApexConfiguration(dir_path, ctx, apex_item); |
Bernie Innocenti | 5c32556 | 2020-02-06 23:16:23 +0900 | [diff] [blame] | 268 | if (!result.ok()) { |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 269 | LOG(WARNING) << result.error(); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 275 | void ExitOnFailure(Result<void> task) { |
Bernie Innocenti | 5c32556 | 2020-02-06 23:16:23 +0900 | [diff] [blame] | 276 | if (!task.ok()) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 277 | LOG(FATAL) << task.error(); |
| 278 | exit(EXIT_FAILURE); |
| 279 | } |
| 280 | } |
| 281 | |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 282 | #ifdef __ANDROID__ |
Kiyoung Kim | e3bad04 | 2019-07-23 13:38:34 +0900 | [diff] [blame] | 283 | struct CombinedLogger { |
| 284 | android::base::LogdLogger logd; |
| 285 | |
| 286 | void operator()(android::base::LogId id, android::base::LogSeverity severity, |
| 287 | const char* tag, const char* file, unsigned int line, |
| 288 | const char* message) { |
| 289 | logd(id, severity, tag, file, line, message); |
| 290 | KernelLogger(id, severity, tag, file, line, message); |
| 291 | } |
| 292 | }; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 293 | #endif |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 294 | } // namespace |
| 295 | |
| 296 | int main(int argc, char* argv[]) { |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 297 | android::base::InitLogging(argv |
| 298 | #ifdef __ANDROID__ |
| 299 | , |
| 300 | CombinedLogger() |
| 301 | #endif |
| 302 | ); |
Kiyoung Kim | e3bad04 | 2019-07-23 13:38:34 +0900 | [diff] [blame] | 303 | |
Jooyung Han | 5bbb123 | 2019-12-23 13:35:00 +0900 | [diff] [blame] | 304 | ProgramArgs args = {}; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 305 | |
| 306 | if (!ParseArgs(argc, argv, &args)) { |
| 307 | PrintUsage(EXIT_FAILURE); |
| 308 | } |
| 309 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 310 | LoadVariables(args); |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 311 | Context ctx = GetContext(args); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 312 | |
Jiyong Park | d601820 | 2020-02-21 13:56:52 +0900 | [diff] [blame] | 313 | // when exec'ed from init, this is 0x0077, which makes the subdirectories |
| 314 | // inaccessible for others. set umask to 0x0022 so that they can be |
| 315 | // accessible. |
| 316 | umask(0x0022); |
| 317 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 318 | if (args.is_recovery) { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 319 | ExitOnFailure( |
| 320 | GenerateRecoveryLinkerConfiguration(ctx, args.target_directory)); |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 321 | } else if (args.is_legacy) { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 322 | ExitOnFailure(GenerateLegacyLinkerConfiguration(ctx, args.target_directory)); |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 323 | } else { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 324 | ExitOnFailure(GenerateBaseLinkerConfiguration(ctx, args.target_directory)); |
| 325 | GenerateApexConfigurations(ctx, args.target_directory); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | return EXIT_SUCCESS; |
Josh Gao | 76614bb | 2019-12-11 15:28:30 -0800 | [diff] [blame] | 329 | } |