Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 1 | /* |
| 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 Wiley | 89e3586 | 2015-08-30 10:57:07 -0700 | [diff] [blame] | 17 | #ifndef AIDL_OPTIONS_H_ |
| 18 | #define AIDL_OPTIONS_H_ |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 19 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 20 | #include <memory> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 24 | #include <base/macros.h> |
| 25 | #include <gtest/gtest_prod.h> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 26 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace aidl { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 29 | |
Christopher Wiley | 89eaab5 | 2015-09-15 14:46:46 -0700 | [diff] [blame] | 30 | // This object represents the parsed options to the Java generating aidl. |
| 31 | class JavaOptions final { |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 32 | public: |
| 33 | enum { |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 34 | COMPILE_AIDL_TO_JAVA, |
| 35 | PREPROCESS_AIDL, |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 36 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 37 | |
Christopher Wiley | 89eaab5 | 2015-09-15 14:46:46 -0700 | [diff] [blame] | 38 | ~JavaOptions() = default; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 39 | |
Christopher Wiley | 89eaab5 | 2015-09-15 14:46:46 -0700 | [diff] [blame] | 40 | // 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 Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 44 | |
Christopher Wiley | ef4132c | 2015-11-05 15:47:40 -0800 | [diff] [blame^] | 45 | std::string DependencyFilePath() const; |
| 46 | |
Christopher Wiley | d93c5b7 | 2015-09-14 13:21:37 -0700 | [diff] [blame] | 47 | int task{COMPILE_AIDL_TO_JAVA}; |
Christopher Wiley | 8f8cc9b | 2015-09-14 13:47:40 -0700 | [diff] [blame] | 48 | 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 Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 57 | |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 58 | // TODO: Mock file IO and remove this (b/24816077) |
| 59 | std::string output_file_name_for_deps_test_; |
| 60 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 61 | private: |
Christopher Wiley | 89eaab5 | 2015-09-15 14:46:46 -0700 | [diff] [blame] | 62 | JavaOptions() = default; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 63 | |
| 64 | FRIEND_TEST(EndToEndTest, IExampleInterface); |
Christopher Wiley | 89eaab5 | 2015-09-15 14:46:46 -0700 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(JavaOptions); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 68 | class 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 Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 78 | 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 Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 81 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 82 | std::vector<std::string> ImportPaths() const { return import_paths_; } |
| 83 | std::string DependencyFilepath() const { return dep_file_name_; } |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 84 | |
| 85 | private: |
| 86 | CppOptions() = default; |
| 87 | |
| 88 | std::string input_file_name_; |
| 89 | std::vector<std::string> import_paths_; |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 90 | std::string output_header_dir_; |
| 91 | std::string output_file_name_; |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 92 | std::string dep_file_name_; |
| 93 | |
| 94 | FRIEND_TEST(CppOptionsTests, ParsesCompileCpp); |
| 95 | DISALLOW_COPY_AND_ASSIGN(CppOptions); |
| 96 | }; |
| 97 | |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 98 | bool EndsWith(const std::string& str, const std::string& suffix); |
| 99 | bool ReplaceSuffix(const std::string& old_suffix, |
| 100 | const std::string& new_suffix, |
| 101 | std::string* str); |
| 102 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 103 | } // namespace android |
| 104 | } // namespace aidl |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 105 | |
Christopher Wiley | 89e3586 | 2015-08-30 10:57:07 -0700 | [diff] [blame] | 106 | #endif // AIDL_OPTIONS_H_ |