blob: 94924e7837dcae7b8294a22b4e0b297e069920bd [file] [log] [blame]
Tianjie Xuc1a5e262019-05-22 14:34:12 -07001/*
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 Xu74b0f7c2019-05-22 13:59:57 -070025#include "updater/build_info.h"
26#include "updater/dynamic_partitions.h"
Tianjie Xuc1a5e262019-05-22 14:34:12 -070027#include "updater/install.h"
28#include "updater/simulator_runtime.h"
Tianjie Xuc1a5e262019-05-22 14:34:12 -070029#include "updater/updater.h"
30
31int 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 Xu74b0f7c2019-05-22 13:59:57 -070038 return EXIT_FAILURE;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070039 }
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();
51
52 TemporaryFile temp_saved_source;
53 TemporaryFile temp_last_command;
54 TemporaryDir temp_stash_base;
55
56 Paths::Get().set_cache_temp_source(temp_saved_source.path);
57 Paths::Get().set_last_command_file(temp_last_command.path);
58 Paths::Get().set_stash_directory_base(temp_stash_base.path);
59
60 TemporaryFile cmd_pipe;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070061 TemporaryDir source_temp_dir;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070062
Tianjie Xu74b0f7c2019-05-22 13:59:57 -070063 BuildInfo source_build_info(source_temp_dir.path);
64 if (!source_build_info.ParseTargetFile(source_target_file, false)) {
65 LOG(ERROR) << "Failed to parse the target file " << source_target_file;
66 return EXIT_FAILURE;
67 }
68
69 Updater updater(std::make_unique<SimulatorRuntime>(&source_build_info));
Tianjie Xuc1a5e262019-05-22 14:34:12 -070070 if (!updater.Init(cmd_pipe.release(), package_name, false)) {
Tianjie Xu74b0f7c2019-05-22 13:59:57 -070071 return EXIT_FAILURE;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070072 }
73
74 if (!updater.RunUpdate()) {
Tianjie Xu74b0f7c2019-05-22 13:59:57 -070075 return EXIT_FAILURE;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070076 }
77
78 LOG(INFO) << "\nscript succeeded, result: " << updater.GetResult();
79
80 return 0;
81}