blob: 7d503f4a6dc31d71bf97d170221d14137ba424f9 [file] [log] [blame]
Christopher Wiley4427d862015-09-14 11:07:39 -07001/*
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
Christopher Wiley89e35862015-08-30 10:57:07 -070017#ifndef AIDL_OPTIONS_H_
18#define AIDL_OPTIONS_H_
Adam Lesinskiffa16862014-01-23 18:17:42 -080019
Christopher Wiley4427d862015-09-14 11:07:39 -070020#include <memory>
Adam Lesinskiffa16862014-01-23 18:17:42 -080021#include <string>
22#include <vector>
23
Christopher Wiley4427d862015-09-14 11:07:39 -070024#include <base/macros.h>
25#include <gtest/gtest_prod.h>
Adam Lesinskiffa16862014-01-23 18:17:42 -080026
Christopher Wiley4427d862015-09-14 11:07:39 -070027namespace android {
28namespace aidl {
Adam Lesinskiffa16862014-01-23 18:17:42 -080029
Christopher Wiley89eaab52015-09-15 14:46:46 -070030// This object represents the parsed options to the Java generating aidl.
31class JavaOptions final {
Christopher Wiley4427d862015-09-14 11:07:39 -070032 public:
33 enum {
Christopher Wileyd93c5b72015-09-14 13:21:37 -070034 COMPILE_AIDL_TO_JAVA,
35 PREPROCESS_AIDL,
Christopher Wiley4427d862015-09-14 11:07:39 -070036 };
Adam Lesinskiffa16862014-01-23 18:17:42 -080037
Christopher Wiley89eaab52015-09-15 14:46:46 -070038 ~JavaOptions() = default;
Christopher Wiley4427d862015-09-14 11:07:39 -070039
Christopher Wiley89eaab52015-09-15 14:46:46 -070040 // Parses the command line and returns a non-null pointer to an JavaOptions
41 // object on success.
42 // Prints the usage statement on failure.
43 static std::unique_ptr<JavaOptions> Parse(int argc, const char* const* argv);
Christopher Wiley4427d862015-09-14 11:07:39 -070044
Christopher Wileyef4132c2015-11-05 15:47:40 -080045 std::string DependencyFilePath() const;
46
Christopher Wileyd93c5b72015-09-14 13:21:37 -070047 int task{COMPILE_AIDL_TO_JAVA};
Christopher Wiley8f8cc9b2015-09-14 13:47:40 -070048 bool fail_on_parcelable_{false};
49 std::vector<std::string> import_paths_;
50 std::vector<std::string> preprocessed_files_;
51 std::string input_file_name_;
52 std::string output_file_name_;
53 std::string output_base_folder_;
54 std::string dep_file_name_;
55 bool auto_dep_file_{false};
56 std::vector<std::string> files_to_preprocess_;
Christopher Wiley4427d862015-09-14 11:07:39 -070057
Casey Dahlin0edf3422015-10-07 12:34:59 -070058 // TODO: Mock file IO and remove this (b/24816077)
59 std::string output_file_name_for_deps_test_;
60
Christopher Wiley4427d862015-09-14 11:07:39 -070061 private:
Christopher Wiley89eaab52015-09-15 14:46:46 -070062 JavaOptions() = default;
Christopher Wiley4427d862015-09-14 11:07:39 -070063
64 FRIEND_TEST(EndToEndTest, IExampleInterface);
Christopher Wiley89eaab52015-09-15 14:46:46 -070065 DISALLOW_COPY_AND_ASSIGN(JavaOptions);
Adam Lesinskiffa16862014-01-23 18:17:42 -080066};
67
Christopher Wileya590de82015-09-15 15:46:28 -070068class CppOptions final {
69 public:
70
71 ~CppOptions() = default;
72
73 // Parses the command line and returns a non-null pointer to an CppOptions
74 // object on success.
75 // Prints the usage statement on failure.
76 static std::unique_ptr<CppOptions> Parse(int argc, const char* const* argv);
77
Christopher Wiley054afbd2015-10-16 17:08:43 -070078 std::string InputFileName() const { return input_file_name_; }
79 std::string OutputHeaderDir() const { return output_header_dir_; }
80 std::string OutputCppFilePath() const { return output_file_name_; }
Christopher Wiley4432ccf2015-09-18 18:32:08 -070081
Christopher Wiley054afbd2015-10-16 17:08:43 -070082 std::vector<std::string> ImportPaths() const { return import_paths_; }
83 std::string DependencyFilepath() const { return dep_file_name_; }
Christopher Wileya590de82015-09-15 15:46:28 -070084
85 private:
86 CppOptions() = default;
87
88 std::string input_file_name_;
89 std::vector<std::string> import_paths_;
Christopher Wiley054afbd2015-10-16 17:08:43 -070090 std::string output_header_dir_;
91 std::string output_file_name_;
Christopher Wileya590de82015-09-15 15:46:28 -070092 std::string dep_file_name_;
93
94 FRIEND_TEST(CppOptionsTests, ParsesCompileCpp);
95 DISALLOW_COPY_AND_ASSIGN(CppOptions);
96};
97
Christopher Wiley4432ccf2015-09-18 18:32:08 -070098bool EndsWith(const std::string& str, const std::string& suffix);
99bool ReplaceSuffix(const std::string& old_suffix,
100 const std::string& new_suffix,
101 std::string* str);
102
Christopher Wiley4427d862015-09-14 11:07:39 -0700103} // namespace android
104} // namespace aidl
Adam Lesinskiffa16862014-01-23 18:17:42 -0800105
Christopher Wiley89e35862015-08-30 10:57:07 -0700106#endif // AIDL_OPTIONS_H_