Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [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 | */ |
| 16 | |
| 17 | #include <string> |
| 18 | |
| 19 | #include <android-base/file.h> |
| 20 | #include <android-base/logging.h> |
| 21 | |
| 22 | #include "otautil/error_code.h" |
| 23 | #include "otautil/paths.h" |
| 24 | #include "updater/blockimg.h" |
Tianjie Xu | 74b0f7c | 2019-05-22 13:59:57 -0700 | [diff] [blame] | 25 | #include "updater/build_info.h" |
| 26 | #include "updater/dynamic_partitions.h" |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 27 | #include "updater/install.h" |
| 28 | #include "updater/simulator_runtime.h" |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 29 | #include "updater/updater.h" |
| 30 | |
| 31 | int main(int argc, char** argv) { |
| 32 | // Write the logs to stdout. |
| 33 | android::base::InitLogging(argv, &android::base::StderrLogger); |
| 34 | |
| 35 | if (argc != 3 && argc != 4) { |
| 36 | LOG(ERROR) << "unexpected number of arguments: " << argc << std::endl |
| 37 | << "Usage: " << argv[0] << " <source_target-file> <ota_package>"; |
Tianjie Xu | 74b0f7c | 2019-05-22 13:59:57 -0700 | [diff] [blame] | 38 | return EXIT_FAILURE; |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // TODO(xunchang) implement a commandline parser, e.g. it can take an oem property so that the |
| 42 | // file_getprop() will return correct value. |
| 43 | |
| 44 | std::string source_target_file = argv[1]; |
| 45 | std::string package_name = argv[2]; |
| 46 | |
| 47 | // Configure edify's functions. |
| 48 | RegisterBuiltins(); |
| 49 | RegisterInstallFunctions(); |
| 50 | RegisterBlockImageFunctions(); |
Tianjie Xu | d118833 | 2019-05-24 16:08:45 -0700 | [diff] [blame] | 51 | RegisterDynamicPartitionsFunctions(); |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 52 | |
| 53 | TemporaryFile temp_saved_source; |
| 54 | TemporaryFile temp_last_command; |
| 55 | TemporaryDir temp_stash_base; |
| 56 | |
| 57 | Paths::Get().set_cache_temp_source(temp_saved_source.path); |
| 58 | Paths::Get().set_last_command_file(temp_last_command.path); |
| 59 | Paths::Get().set_stash_directory_base(temp_stash_base.path); |
| 60 | |
| 61 | TemporaryFile cmd_pipe; |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 62 | TemporaryDir source_temp_dir; |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 63 | |
Tianjie Xu | 74b0f7c | 2019-05-22 13:59:57 -0700 | [diff] [blame] | 64 | BuildInfo source_build_info(source_temp_dir.path); |
| 65 | if (!source_build_info.ParseTargetFile(source_target_file, false)) { |
| 66 | LOG(ERROR) << "Failed to parse the target file " << source_target_file; |
| 67 | return EXIT_FAILURE; |
| 68 | } |
| 69 | |
| 70 | Updater updater(std::make_unique<SimulatorRuntime>(&source_build_info)); |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 71 | if (!updater.Init(cmd_pipe.release(), package_name, false)) { |
Tianjie Xu | 74b0f7c | 2019-05-22 13:59:57 -0700 | [diff] [blame] | 72 | return EXIT_FAILURE; |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | if (!updater.RunUpdate()) { |
Tianjie Xu | 74b0f7c | 2019-05-22 13:59:57 -0700 | [diff] [blame] | 76 | return EXIT_FAILURE; |
Tianjie Xu | c1a5e26 | 2019-05-22 14:34:12 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | LOG(INFO) << "\nscript succeeded, result: " << updater.GetResult(); |
| 80 | |
| 81 | return 0; |
| 82 | } |