Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 1 | /* |
Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 2 | * Copyright (C) 2015, The Android Open Source Project * |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
Steven Moreland | 9fccf58 | 2018-08-27 20:36:27 -0700 | [diff] [blame] | 16 | #pragma once |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 17 | |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 18 | #include <set> |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 19 | #include <sstream> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace aidl { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 25 | |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 26 | using std::set; |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 27 | using std::string; |
| 28 | using std::vector; |
| 29 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 30 | // A simple wrapper around ostringstream. This is just to make Options class |
| 31 | // copiable by the implicit copy constructor. If ostingstream is not wrapped, |
| 32 | // the implcit copy constructor is not generated because ostringstream isn't |
| 33 | // copiable. This class makes the field copiable by having a copy constructor |
| 34 | // that does not copy the underlying stream. |
| 35 | class ErrorMessage { |
| 36 | public: |
| 37 | ErrorMessage() = default; |
| 38 | ErrorMessage(const ErrorMessage&) {} |
| 39 | std::ostringstream stream_; |
Jiyong Park | e1d0268 | 2018-08-01 12:18:02 +0900 | [diff] [blame] | 40 | |
| 41 | template <typename T> |
| 42 | ErrorMessage& operator<<(T& t) { |
| 43 | stream_ << t; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 44 | return *this; |
| 45 | } |
Jiyong Park | e1d0268 | 2018-08-01 12:18:02 +0900 | [diff] [blame] | 46 | |
| 47 | template <typename T> |
| 48 | ErrorMessage& operator<<(const T& t) { |
| 49 | stream_ << t; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 50 | return *this; |
| 51 | } |
Jiyong Park | e1d0268 | 2018-08-01 12:18:02 +0900 | [diff] [blame] | 52 | |
| 53 | // for "<< endl" |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 54 | ErrorMessage& operator<<(std::ostream& (*f)(std::ostream&)) { |
| 55 | f(stream_); |
| 56 | return *this; |
| 57 | } |
| 58 | }; |
| 59 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 60 | class Options final { |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 61 | public: |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 62 | enum class Language { UNSPECIFIED, JAVA, CPP, NDK }; |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 63 | |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 64 | enum class Task { UNSPECIFIED, COMPILE, PREPROCESS, DUMP_API, CHECK_API, DUMP_MAPPINGS }; |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 65 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 66 | Options(int argc, const char* const argv[], Language default_lang = Language::UNSPECIFIED); |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 67 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 68 | static Options From(const string& cmdline); |
| 69 | |
| 70 | static Options From(const vector<string>& args); |
| 71 | |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 72 | // Contain no references to unstructured data types (such as a parcelable that is |
| 73 | // implemented in Java). These interfaces aren't inherently stable but they have the |
| 74 | // capacity to be stabilized. |
| 75 | bool IsStructured() const { return structured_; } |
| 76 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 77 | Language TargetLanguage() const { return language_; } |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 78 | bool IsCppOutput() const { return language_ == Language::CPP || language_ == Language::NDK; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 79 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 80 | Task GetTask() const { return task_; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 81 | |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 82 | const set<string>& ImportDirs() const { return import_dirs_; } |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 83 | |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 84 | const set<string>& ImportFiles() const { return import_files_; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 85 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 86 | const vector<string>& PreprocessedFiles() const { return preprocessed_files_; } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 87 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 88 | string DependencyFile() const { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 89 | return dependency_file_; |
| 90 | } |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 91 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 92 | bool AutoDepFile() const { return auto_dep_file_; } |
Christopher Wiley | ef4132c | 2015-11-05 15:47:40 -0800 | [diff] [blame] | 93 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 94 | bool GenTraces() const { return gen_traces_; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 95 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 96 | bool GenTransactionNames() const { return gen_transaction_names_; } |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 97 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 98 | bool DependencyFileNinja() const { return dependency_file_ninja_; } |
| 99 | |
| 100 | const vector<string>& InputFiles() const { return input_files_; } |
| 101 | |
| 102 | // Path to the output file. This is used only when there is only one |
| 103 | // output file for the invocation. When there are multiple outputs |
| 104 | // (e.g. compile multiple AIDL files), output files are created under |
| 105 | // OutputDir(). |
| 106 | const string& OutputFile() const { return output_file_; } |
| 107 | |
| 108 | // Path to the directory where output file(s) will be generated under. |
| 109 | const string& OutputDir() const { return output_dir_; } |
| 110 | |
| 111 | // Path to the directory where header file(s) will be generated under. |
| 112 | // Only used when TargetLanguage() == Language::CPP |
| 113 | const string& OutputHeaderDir() const { return output_header_dir_; } |
| 114 | |
| 115 | bool FailOnParcelable() const { return fail_on_parcelable_; } |
| 116 | |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 117 | int Version() const { return version_; } |
| 118 | |
Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 119 | bool GenLog() const { return gen_log_; } |
| 120 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 121 | bool Ok() const { return error_message_.stream_.str().empty(); } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 122 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 123 | string GetErrorMessage() const { return error_message_.stream_.str(); } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 124 | |
| 125 | string GetUsage() const; |
Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 126 | |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 127 | bool GenApiMapping() const { return task_ == Task::DUMP_MAPPINGS; } |
| 128 | |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 129 | // The following are for testability, but cannot be influenced on the command line. |
Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 130 | // Threshold of interface methods to enable outlining of onTransact cases. |
| 131 | size_t onTransact_outline_threshold_{275u}; |
| 132 | // Number of cases to _not_ outline, if outlining is enabled. |
| 133 | size_t onTransact_non_outline_count_{275u}; |
| 134 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 135 | private: |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 136 | Options() = default; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 137 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 138 | const string myname_; |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 139 | bool structured_ = false; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 140 | Language language_ = Language::UNSPECIFIED; |
| 141 | Task task_ = Task::COMPILE; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 142 | set<string> import_dirs_; |
| 143 | set<string> import_files_; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 144 | vector<string> preprocessed_files_; |
| 145 | string dependency_file_; |
| 146 | bool gen_traces_ = false; |
| 147 | bool gen_transaction_names_ = false; |
| 148 | bool dependency_file_ninja_ = false; |
| 149 | string output_dir_; |
| 150 | string output_header_dir_; |
| 151 | bool fail_on_parcelable_ = false; |
| 152 | bool auto_dep_file_ = false; |
| 153 | vector<string> input_files_; |
| 154 | string output_file_; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 155 | int version_ = 0; |
Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 156 | bool gen_log_ = false; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 157 | ErrorMessage error_message_; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 158 | }; |
| 159 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 160 | } // namespace android |
| 161 | } // namespace aidl |