blob: ced99034867b4d3d88c6c620fe8965aab79cac34 [file] [log] [blame]
Christopher Wiley4427d862015-09-14 11:07:39 -07001/*
Christopher Wileyb1bbdf82016-04-21 11:43:45 -07002 * Copyright (C) 2015, The Android Open Source Project *
Christopher Wiley4427d862015-09-14 11:07:39 -07003 * 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 Wiley89e35862015-08-30 10:57:07 -070016#ifndef AIDL_OPTIONS_H_
17#define AIDL_OPTIONS_H_
Adam Lesinskiffa16862014-01-23 18:17:42 -080018
Jiyong Park74595c12018-07-23 15:22:50 +090019#include <sstream>
Adam Lesinskiffa16862014-01-23 18:17:42 -080020#include <string>
21#include <vector>
22
Christopher Wiley4427d862015-09-14 11:07:39 -070023#include <gtest/gtest_prod.h>
Adam Lesinskiffa16862014-01-23 18:17:42 -080024
Jiyong Park74595c12018-07-23 15:22:50 +090025using std::string;
26using std::vector;
27
Christopher Wiley4427d862015-09-14 11:07:39 -070028namespace android {
29namespace aidl {
Adam Lesinskiffa16862014-01-23 18:17:42 -080030
Jiyong Park74595c12018-07-23 15:22:50 +090031class Options final {
Steven Morelandda0654f2018-07-17 12:24:38 -070032 public:
Jiyong Park74595c12018-07-23 15:22:50 +090033 enum class Language { UNSPECIFIED, JAVA, CPP };
Steven Morelandda0654f2018-07-17 12:24:38 -070034
Jiyong Park74595c12018-07-23 15:22:50 +090035 enum class Task { UNSPECIFIED, COMPILE, PREPROCESS, DUMPAPI };
Steven Morelandda0654f2018-07-17 12:24:38 -070036
Jiyong Park74595c12018-07-23 15:22:50 +090037 Options(int argc, const char* const argv[], Language default_lang = Language::UNSPECIFIED);
Steven Morelandda0654f2018-07-17 12:24:38 -070038
Jiyong Park74595c12018-07-23 15:22:50 +090039 Language TargetLanguage() const { return language_; }
Steven Morelandda0654f2018-07-17 12:24:38 -070040
Jiyong Park74595c12018-07-23 15:22:50 +090041 Task GetTask() const { return task_; }
Steven Morelandda0654f2018-07-17 12:24:38 -070042
Jiyong Park74595c12018-07-23 15:22:50 +090043 const vector<string>& ImportPaths() const { return import_paths_; }
Steven Morelandda0654f2018-07-17 12:24:38 -070044
Jiyong Park74595c12018-07-23 15:22:50 +090045 const vector<string>& PreprocessedFiles() const { return preprocessed_files_; }
Adam Lesinskiffa16862014-01-23 18:17:42 -080046
Jiyong Park74595c12018-07-23 15:22:50 +090047 string DependencyFile() const {
48 if (auto_dep_file_) {
49 return output_file_ + ".d";
50 }
51 return dependency_file_;
52 }
Christopher Wiley4427d862015-09-14 11:07:39 -070053
Jiyong Park74595c12018-07-23 15:22:50 +090054 bool AutoDepFile() const { return auto_dep_file_; }
Christopher Wileyef4132c2015-11-05 15:47:40 -080055
Jiyong Park74595c12018-07-23 15:22:50 +090056 bool GenTraces() const { return gen_traces_; }
Steven Morelandda0654f2018-07-17 12:24:38 -070057
Jiyong Park74595c12018-07-23 15:22:50 +090058 bool GenTransactionNames() const { return gen_transaction_names_; }
Christopher Wiley4427d862015-09-14 11:07:39 -070059
Jiyong Park74595c12018-07-23 15:22:50 +090060 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 Gampee9c816e2018-03-14 09:05:48 -070084
Steven Morelandda0654f2018-07-17 12:24:38 -070085 // The following are for testability, but cannot be influenced on the command line.
Andreas Gampee9c816e2018-03-14 09:05:48 -070086 // 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 Wiley4427d862015-09-14 11:07:39 -070091 private:
Jiyong Park74595c12018-07-23 15:22:50 +090092 Options() = default;
Christopher Wiley4427d862015-09-14 11:07:39 -070093
Jiyong Park74595c12018-07-23 15:22:50 +090094 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 Morelandda0654f2018-07-17 12:24:38 -0700110
Christopher Wiley4427d862015-09-14 11:07:39 -0700111 FRIEND_TEST(EndToEndTest, IExampleInterface);
Olivier Gaillard11401402018-07-05 15:01:34 +0100112 FRIEND_TEST(EndToEndTest, IExampleInterface_WithTransactionNames);
Martijn Coenenf1b50782018-02-21 21:06:23 +0100113 FRIEND_TEST(EndToEndTest, IExampleInterface_WithTrace);
Andreas Gampee9c816e2018-03-14 09:05:48 -0700114 FRIEND_TEST(EndToEndTest, IExampleInterface_Outlining);
Christopher Wiley632801d2015-11-05 14:15:49 -0800115 FRIEND_TEST(AidlTest, FailOnParcelable);
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800116 FRIEND_TEST(AidlTest, WritePreprocessedFile);
Christopher Wileyf8136192016-04-12 14:19:35 -0700117 FRIEND_TEST(AidlTest, WritesCorrectDependencyFile);
Dan Willemsen93298ee2016-11-10 23:55:55 -0800118 FRIEND_TEST(AidlTest, WritesCorrectDependencyFileNinja);
Christopher Wileyb1bbdf82016-04-21 11:43:45 -0700119 FRIEND_TEST(AidlTest, WritesTrivialDependencyFileForParcelable);
Jiyong Park02da7422018-07-16 16:00:26 +0900120 FRIEND_TEST(AidlTest, ApiDump);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800121};
122
Christopher Wiley4432ccf2015-09-18 18:32:08 -0700123
Christopher Wiley4427d862015-09-14 11:07:39 -0700124} // namespace android
125} // namespace aidl
Adam Lesinskiffa16862014-01-23 18:17:42 -0800126
Christopher Wiley89e35862015-08-30 10:57:07 -0700127#endif // AIDL_OPTIONS_H_