| 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 | |
| Christopher Wiley | 89e3586 | 2015-08-30 10:57:07 -0700 | [diff] [blame] | 16 | #ifndef AIDL_OPTIONS_H_ |
| 17 | #define AIDL_OPTIONS_H_ |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 18 | |
| 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 | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 26 | using std::string; |
| 27 | using std::vector; |
| 28 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 29 | // A simple wrapper around ostringstream. This is just to make Options class |
| 30 | // copiable by the implicit copy constructor. If ostingstream is not wrapped, |
| 31 | // the implcit copy constructor is not generated because ostringstream isn't |
| 32 | // copiable. This class makes the field copiable by having a copy constructor |
| 33 | // that does not copy the underlying stream. |
| 34 | class ErrorMessage { |
| 35 | public: |
| 36 | ErrorMessage() = default; |
| 37 | ErrorMessage(const ErrorMessage&) {} |
| 38 | std::ostringstream stream_; |
| Jiyong Park | e1d0268 | 2018-08-01 12:18:02 +0900 | [diff] [blame] | 39 | |
| 40 | template <typename T> |
| 41 | ErrorMessage& operator<<(T& t) { |
| 42 | stream_ << t; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 43 | return *this; |
| 44 | } |
| Jiyong Park | e1d0268 | 2018-08-01 12:18:02 +0900 | [diff] [blame] | 45 | |
| 46 | template <typename T> |
| 47 | ErrorMessage& operator<<(const T& t) { |
| 48 | stream_ << t; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 49 | return *this; |
| 50 | } |
| Jiyong Park | e1d0268 | 2018-08-01 12:18:02 +0900 | [diff] [blame] | 51 | |
| 52 | // for "<< endl" |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 53 | ErrorMessage& operator<<(std::ostream& (*f)(std::ostream&)) { |
| 54 | f(stream_); |
| 55 | return *this; |
| 56 | } |
| 57 | }; |
| 58 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 59 | class Options final { |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 60 | public: |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 61 | enum class Language { UNSPECIFIED, JAVA, CPP }; |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 62 | |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame^] | 63 | enum class Task { UNSPECIFIED, COMPILE, PREPROCESS, DUMP_API, CHECK_API }; |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 64 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 65 | Options(int argc, const char* const argv[], Language default_lang = Language::UNSPECIFIED); |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 66 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 67 | static Options From(const string& cmdline); |
| 68 | |
| 69 | static Options From(const vector<string>& args); |
| 70 | |
| Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 71 | // Contain no references to unstructured data types (such as a parcelable that is |
| 72 | // implemented in Java). These interfaces aren't inherently stable but they have the |
| 73 | // capacity to be stabilized. |
| 74 | bool IsStructured() const { return structured_; } |
| 75 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 76 | Language TargetLanguage() const { return language_; } |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 77 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 78 | Task GetTask() const { return task_; } |
| 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 | const vector<string>& ImportPaths() const { return import_paths_; } |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 81 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 82 | const vector<string>& PreprocessedFiles() const { return preprocessed_files_; } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 83 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 84 | string DependencyFile() const { |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 85 | return dependency_file_; |
| 86 | } |
| Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 87 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 88 | bool AutoDepFile() const { return auto_dep_file_; } |
| Christopher Wiley | ef4132c | 2015-11-05 15:47:40 -0800 | [diff] [blame] | 89 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 90 | bool GenTraces() const { return gen_traces_; } |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 91 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 92 | bool GenTransactionNames() const { return gen_transaction_names_; } |
| Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 93 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 94 | bool DependencyFileNinja() const { return dependency_file_ninja_; } |
| 95 | |
| 96 | const vector<string>& InputFiles() const { return input_files_; } |
| 97 | |
| 98 | // Path to the output file. This is used only when there is only one |
| 99 | // output file for the invocation. When there are multiple outputs |
| 100 | // (e.g. compile multiple AIDL files), output files are created under |
| 101 | // OutputDir(). |
| 102 | const string& OutputFile() const { return output_file_; } |
| 103 | |
| 104 | // Path to the directory where output file(s) will be generated under. |
| 105 | const string& OutputDir() const { return output_dir_; } |
| 106 | |
| 107 | // Path to the directory where header file(s) will be generated under. |
| 108 | // Only used when TargetLanguage() == Language::CPP |
| 109 | const string& OutputHeaderDir() const { return output_header_dir_; } |
| 110 | |
| 111 | bool FailOnParcelable() const { return fail_on_parcelable_; } |
| 112 | |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 113 | int Version() const { return version_; } |
| 114 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 115 | bool Ok() const { return error_message_.stream_.str().empty(); } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 116 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 117 | string GetErrorMessage() const { return error_message_.stream_.str(); } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 118 | |
| 119 | string GetUsage() const; |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 120 | |
| Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 121 | // 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] | 122 | // Threshold of interface methods to enable outlining of onTransact cases. |
| 123 | size_t onTransact_outline_threshold_{275u}; |
| 124 | // Number of cases to _not_ outline, if outlining is enabled. |
| 125 | size_t onTransact_non_outline_count_{275u}; |
| 126 | |
| Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 127 | private: |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 128 | Options() = default; |
| Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 129 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 130 | const string myname_; |
| Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 131 | bool structured_ = false; |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 132 | Language language_ = Language::UNSPECIFIED; |
| 133 | Task task_ = Task::COMPILE; |
| 134 | vector<string> import_paths_; |
| 135 | vector<string> preprocessed_files_; |
| 136 | string dependency_file_; |
| 137 | bool gen_traces_ = false; |
| 138 | bool gen_transaction_names_ = false; |
| 139 | bool dependency_file_ninja_ = false; |
| 140 | string output_dir_; |
| 141 | string output_header_dir_; |
| 142 | bool fail_on_parcelable_ = false; |
| 143 | bool auto_dep_file_ = false; |
| 144 | vector<string> input_files_; |
| 145 | string output_file_; |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 146 | int version_ = 0; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 147 | ErrorMessage error_message_; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
| Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 150 | } // namespace android |
| 151 | } // namespace aidl |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 152 | |
| Christopher Wiley | 89e3586 | 2015-08-30 10:57:07 -0700 | [diff] [blame] | 153 | #endif // AIDL_OPTIONS_H_ |