blob: d10453c2f2bbcb2d89e240bdfb164d6d5a3b571e [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"
25#include "updater/install.h"
26#include "updater/simulator_runtime.h"
27#include "updater/target_files.h"
28#include "updater/updater.h"
29
30int main(int argc, char** argv) {
31 // Write the logs to stdout.
32 android::base::InitLogging(argv, &android::base::StderrLogger);
33
34 if (argc != 3 && argc != 4) {
35 LOG(ERROR) << "unexpected number of arguments: " << argc << std::endl
36 << "Usage: " << argv[0] << " <source_target-file> <ota_package>";
37 return 1;
38 }
39
40 // TODO(xunchang) implement a commandline parser, e.g. it can take an oem property so that the
41 // file_getprop() will return correct value.
42
43 std::string source_target_file = argv[1];
44 std::string package_name = argv[2];
45
46 // Configure edify's functions.
47 RegisterBuiltins();
48 RegisterInstallFunctions();
49 RegisterBlockImageFunctions();
50
51 TemporaryFile temp_saved_source;
52 TemporaryFile temp_last_command;
53 TemporaryDir temp_stash_base;
54
55 Paths::Get().set_cache_temp_source(temp_saved_source.path);
56 Paths::Get().set_last_command_file(temp_last_command.path);
57 Paths::Get().set_stash_directory_base(temp_stash_base.path);
58
59 TemporaryFile cmd_pipe;
60
61 TemporaryDir source_temp_dir;
62 TargetFiles source(source_target_file, source_temp_dir.path);
63
64 Updater updater(std::make_unique<SimulatorRuntime>(&source));
65 if (!updater.Init(cmd_pipe.release(), package_name, false)) {
66 return 1;
67 }
68
69 if (!updater.RunUpdate()) {
70 return 1;
71 }
72
73 LOG(INFO) << "\nscript succeeded, result: " << updater.GetResult();
74
75 return 0;
76}