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 | #include <gtest/gtest_prod.h> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 24 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace aidl { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 27 | |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame^] | 28 | using std::string; |
| 29 | using std::vector; |
| 30 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 31 | class Options final { |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 32 | public: |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 33 | enum class Language { UNSPECIFIED, JAVA, CPP }; |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 34 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 35 | enum class Task { UNSPECIFIED, COMPILE, PREPROCESS, DUMPAPI }; |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 36 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 37 | Options(int argc, const char* const argv[], Language default_lang = Language::UNSPECIFIED); |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 38 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 39 | Language TargetLanguage() const { return language_; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 40 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 41 | Task GetTask() const { return task_; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 42 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 43 | const vector<string>& ImportPaths() const { return import_paths_; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 44 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 45 | const vector<string>& PreprocessedFiles() const { return preprocessed_files_; } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 46 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 47 | string DependencyFile() const { |
| 48 | if (auto_dep_file_) { |
| 49 | return output_file_ + ".d"; |
| 50 | } |
| 51 | return dependency_file_; |
| 52 | } |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 53 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 54 | bool AutoDepFile() const { return auto_dep_file_; } |
Christopher Wiley | ef4132c | 2015-11-05 15:47:40 -0800 | [diff] [blame] | 55 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 56 | bool GenTraces() const { return gen_traces_; } |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 57 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 58 | bool GenTransactionNames() const { return gen_transaction_names_; } |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 59 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 60 | bool DependencyFileNinja() const { return dependency_file_ninja_; } |
| 61 | |
| 62 | const vector<string>& InputFiles() const { return input_files_; } |
| 63 | |
| 64 | // Path to the output file. This is used only when there is only one |
| 65 | // output file for the invocation. When there are multiple outputs |
| 66 | // (e.g. compile multiple AIDL files), output files are created under |
| 67 | // OutputDir(). |
| 68 | const string& OutputFile() const { return output_file_; } |
| 69 | |
| 70 | // Path to the directory where output file(s) will be generated under. |
| 71 | const string& OutputDir() const { return output_dir_; } |
| 72 | |
| 73 | // Path to the directory where header file(s) will be generated under. |
| 74 | // Only used when TargetLanguage() == Language::CPP |
| 75 | const string& OutputHeaderDir() const { return output_header_dir_; } |
| 76 | |
| 77 | bool FailOnParcelable() const { return fail_on_parcelable_; } |
| 78 | |
| 79 | bool Ok() const { return error_message_.str().empty(); } |
| 80 | |
| 81 | string GetErrorMessage() const { return error_message_.str(); } |
| 82 | |
| 83 | string GetUsage() const; |
Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 84 | |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 85 | // 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] | 86 | // Threshold of interface methods to enable outlining of onTransact cases. |
| 87 | size_t onTransact_outline_threshold_{275u}; |
| 88 | // Number of cases to _not_ outline, if outlining is enabled. |
| 89 | size_t onTransact_non_outline_count_{275u}; |
| 90 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 91 | private: |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 92 | Options() = default; |
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 | const string myname_; |
| 95 | Language language_ = Language::UNSPECIFIED; |
| 96 | Task task_ = Task::COMPILE; |
| 97 | vector<string> import_paths_; |
| 98 | vector<string> preprocessed_files_; |
| 99 | string dependency_file_; |
| 100 | bool gen_traces_ = false; |
| 101 | bool gen_transaction_names_ = false; |
| 102 | bool dependency_file_ninja_ = false; |
| 103 | string output_dir_; |
| 104 | string output_header_dir_; |
| 105 | bool fail_on_parcelable_ = false; |
| 106 | bool auto_dep_file_ = false; |
| 107 | vector<string> input_files_; |
| 108 | string output_file_; |
| 109 | std::ostringstream error_message_; |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 110 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 111 | FRIEND_TEST(EndToEndTest, IExampleInterface); |
Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 112 | FRIEND_TEST(EndToEndTest, IExampleInterface_WithTransactionNames); |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 113 | FRIEND_TEST(EndToEndTest, IExampleInterface_WithTrace); |
Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 114 | FRIEND_TEST(EndToEndTest, IExampleInterface_Outlining); |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 115 | FRIEND_TEST(AidlTest, FailOnParcelable); |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 116 | FRIEND_TEST(AidlTest, WritePreprocessedFile); |
Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 117 | FRIEND_TEST(AidlTest, WritesCorrectDependencyFile); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 118 | FRIEND_TEST(AidlTest, WritesCorrectDependencyFileNinja); |
Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 119 | FRIEND_TEST(AidlTest, WritesTrivialDependencyFileForParcelable); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 120 | FRIEND_TEST(AidlTest, ApiDump); |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame^] | 121 | FRIEND_TEST(AidlTest, CheckNumGenericTypeSecifier); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 124 | } // namespace android |
| 125 | } // namespace aidl |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 126 | |
Christopher Wiley | 89e3586 | 2015-08-30 10:57:07 -0700 | [diff] [blame] | 127 | #endif // AIDL_OPTIONS_H_ |