blob: 019c404ef39c61fc7bd2acb13e59bed9526de84d [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();
Tianjie Xud1188332019-05-24 16:08:45 -070051 RegisterDynamicPartitionsFunctions();
Tianjie Xuc1a5e262019-05-22 14:34:12 -070052
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 Xuc1a5e262019-05-22 14:34:12 -070062 TemporaryDir source_temp_dir;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070063
Tianjie Xu74b0f7c2019-05-22 13:59:57 -070064 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 Xuc1a5e262019-05-22 14:34:12 -070071 if (!updater.Init(cmd_pipe.release(), package_name, false)) {
Tianjie Xu74b0f7c2019-05-22 13:59:57 -070072 return EXIT_FAILURE;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070073 }
74
75 if (!updater.RunUpdate()) {
Tianjie Xu74b0f7c2019-05-22 13:59:57 -070076 return EXIT_FAILURE;
Tianjie Xuc1a5e262019-05-22 14:34:12 -070077 }
78
79 LOG(INFO) << "\nscript succeeded, result: " << updater.GetResult();
80
81 return 0;
82}