1 /* 2 * Copyright (C) 2015, The Android Open Source Project * 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 16 #ifndef AIDL_OPTIONS_H_ 17 #define AIDL_OPTIONS_H_ 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include <android-base/macros.h> 24 #include <gtest/gtest_prod.h> 25 26 namespace android { 27 namespace aidl { 28 29 // This object represents the parsed options to the Java generating aidl. 30 class JavaOptions final { 31 public: 32 enum { 33 COMPILE_AIDL_TO_JAVA, 34 PREPROCESS_AIDL, 35 }; 36 37 ~JavaOptions() = default; 38 39 // Parses the command line and returns a non-null pointer to an JavaOptions 40 // object on success. 41 // Prints the usage statement on failure. 42 static std::unique_ptr<JavaOptions> Parse(int argc, const char* const* argv); 43 44 std::string DependencyFilePath() const; DependencyFileNinja()45 bool DependencyFileNinja() const { return dep_file_ninja_; } 46 47 int task{COMPILE_AIDL_TO_JAVA}; 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 bool dep_file_ninja_{false}; 57 std::vector<std::string> files_to_preprocess_; 58 59 private: 60 JavaOptions() = default; 61 62 FRIEND_TEST(EndToEndTest, IExampleInterface); 63 FRIEND_TEST(AidlTest, FailOnParcelable); 64 FRIEND_TEST(AidlTest, WritePreprocessedFile); 65 FRIEND_TEST(AidlTest, WritesCorrectDependencyFile); 66 FRIEND_TEST(AidlTest, WritesCorrectDependencyFileNinja); 67 FRIEND_TEST(AidlTest, WritesTrivialDependencyFileForParcelable); 68 69 DISALLOW_COPY_AND_ASSIGN(JavaOptions); 70 }; 71 72 class CppOptions final { 73 public: 74 75 ~CppOptions() = default; 76 77 // Parses the command line and returns a non-null pointer to an CppOptions 78 // object on success. 79 // Prints the usage statement on failure. 80 static std::unique_ptr<CppOptions> Parse(int argc, const char* const* argv); 81 InputFileName()82 std::string InputFileName() const { return input_file_name_; } OutputHeaderDir()83 std::string OutputHeaderDir() const { return output_header_dir_; } OutputCppFilePath()84 std::string OutputCppFilePath() const { return output_file_name_; } 85 ImportPaths()86 std::vector<std::string> ImportPaths() const { return import_paths_; } DependencyFilePath()87 std::string DependencyFilePath() const { return dep_file_name_; } DependencyFileNinja()88 bool DependencyFileNinja() const { return dep_file_ninja_; } 89 90 private: 91 CppOptions() = default; 92 93 std::string input_file_name_; 94 std::vector<std::string> import_paths_; 95 std::string output_header_dir_; 96 std::string output_file_name_; 97 std::string dep_file_name_; 98 bool dep_file_ninja_{false}; 99 100 FRIEND_TEST(CppOptionsTests, ParsesCompileCpp); 101 FRIEND_TEST(CppOptionsTests, ParsesCompileCppNinja); 102 DISALLOW_COPY_AND_ASSIGN(CppOptions); 103 }; 104 105 bool EndsWith(const std::string& str, const std::string& suffix); 106 bool ReplaceSuffix(const std::string& old_suffix, 107 const std::string& new_suffix, 108 std::string* str); 109 110 } // namespace android 111 } // namespace aidl 112 113 #endif // AIDL_OPTIONS_H_ 114