1 /*
2 * Copyright (C) 2015, 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 "aidl.h"
18 #include "aidl_checkapi.h"
19 #include "io_delegate.h"
20 #include "logging.h"
21 #include "options.h"
22
23 #include <iostream>
24
25 #ifdef AIDL_CPP_BUILD
26 constexpr Options::Language kDefaultLang = Options::Language::CPP;
27 #else
28 constexpr Options::Language kDefaultLang = Options::Language::JAVA;
29 #endif
30
31 using android::aidl::Options;
32
process_options(const Options & options)33 int process_options(const Options& options) {
34 android::aidl::IoDelegate io_delegate;
35 switch (options.GetTask()) {
36 case Options::Task::COMPILE:
37 return android::aidl::compile_aidl(options, io_delegate);
38 case Options::Task::PREPROCESS:
39 return android::aidl::preprocess_aidl(options, io_delegate) ? 0 : 1;
40 case Options::Task::DUMP_API:
41 return android::aidl::dump_api(options, io_delegate) ? 0 : 1;
42 case Options::Task::CHECK_API:
43 return android::aidl::check_api(options, io_delegate) ? 0 : 1;
44 case Options::Task::DUMP_MAPPINGS:
45 return android::aidl::dump_mappings(options, io_delegate) ? 0 : 1;
46 default:
47 LOG(FATAL) << "aidl: internal error" << std::endl;
48 return 1;
49 }
50 }
51
main(int argc,char * argv[])52 int main(int argc, char* argv[]) {
53 android::base::InitLogging(argv);
54 LOG(DEBUG) << "aidl starting";
55
56 Options options(argc, argv, kDefaultLang);
57 if (!options.Ok()) {
58 std::cerr << options.GetErrorMessage();
59 std::cerr << options.GetUsage();
60 return 1;
61 }
62
63 int ret = process_options(options);
64
65 // compiler invariants
66
67 // once AIDL_ERROR/AIDL_FATAL are used everywhere instead of std::cerr/LOG, we
68 // can make this assertion in both directions.
69 if (ret == 0) {
70 AIDL_FATAL_IF(AidlError::hadError(), "Compiler success, but error emitted");
71 }
72
73 return ret;
74 }
75