14427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley/* 2303b43ca5a93ce89f438ad4dd200c0ca317832deChristopher Wiley * Copyright (C) 2015, The Android Open Source Project * 34427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * Licensed under the Apache License, Version 2.0 (the "License"); 44427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * you may not use this file except in compliance with the License. 54427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * You may obtain a copy of the License at 64427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * 74427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * http://www.apache.org/licenses/LICENSE-2.0 84427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * 94427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * Unless required by applicable law or agreed to in writing, software 104427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * distributed under the License is distributed on an "AS IS" BASIS, 114427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * See the License for the specific language governing permissions and 134427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley * limitations under the License. 144427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley */ 154427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley 1689e3586afa180230fa999d4287df90df9d066cefChristopher Wiley#ifndef AIDL_OPTIONS_H_ 1789e3586afa180230fa999d4287df90df9d066cefChristopher Wiley#define AIDL_OPTIONS_H_ 18ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski 194427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley#include <memory> 20ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski#include <string> 21ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski#include <vector> 22ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski 230a62067f35e957493bc37c4b42dfdcfc16353831Elliott Hughes#include <android-base/macros.h> 244427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley#include <gtest/gtest_prod.h> 25ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski 264427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wileynamespace android { 274427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wileynamespace aidl { 28ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski 2989eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley// This object represents the parsed options to the Java generating aidl. 3089eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wileyclass JavaOptions final { 314427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley public: 324427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley enum { 33d93c5b761bf5a53b23a1f0ab954fa38109e72043Christopher Wiley COMPILE_AIDL_TO_JAVA, 34d93c5b761bf5a53b23a1f0ab954fa38109e72043Christopher Wiley PREPROCESS_AIDL, 354427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley }; 364427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley 3789eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley ~JavaOptions() = default; 384427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley 3989eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley // Parses the command line and returns a non-null pointer to an JavaOptions 4089eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley // object on success. 4189eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley // Prints the usage statement on failure. 4289eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley static std::unique_ptr<JavaOptions> Parse(int argc, const char* const* argv); 434427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley 44ef4132c27c313d9c84faf77a84a4ac97f69445b3Christopher Wiley std::string DependencyFilePath() const; 45ef4132c27c313d9c84faf77a84a4ac97f69445b3Christopher Wiley 46d93c5b761bf5a53b23a1f0ab954fa38109e72043Christopher Wiley int task{COMPILE_AIDL_TO_JAVA}; 478f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley bool fail_on_parcelable_{false}; 488f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley std::vector<std::string> import_paths_; 498f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley std::vector<std::string> preprocessed_files_; 508f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley std::string input_file_name_; 518f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley std::string output_file_name_; 528f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley std::string output_base_folder_; 538f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley std::string dep_file_name_; 548f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley bool auto_dep_file_{false}; 558f8cc9b91a8d0b4942a978e9d2edc5337503d583Christopher Wiley std::vector<std::string> files_to_preprocess_; 564427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley 574427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley private: 5889eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley JavaOptions() = default; 594427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley 604427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley FRIEND_TEST(EndToEndTest, IExampleInterface); 61632801d891bd269badc780ab5f0f08e56e6df10aChristopher Wiley FRIEND_TEST(AidlTest, FailOnParcelable); 62c1f39b4ea30e7313eeb7f3d3fd5ec66ba00f2bb5Casey Dahlin FRIEND_TEST(AidlTest, WritePreprocessedFile); 638f314b0d4c3f195c98c6dd7e671fc2b9d4bfa76fChristopher Wiley FRIEND_TEST(AidlTest, WritesCorrectDependencyFile); 64303b43ca5a93ce89f438ad4dd200c0ca317832deChristopher Wiley FRIEND_TEST(AidlTest, WritesTrivialDependencyFileForParcelable); 65303b43ca5a93ce89f438ad4dd200c0ca317832deChristopher Wiley 6689eaab56f3ff913c247397b858fac3c8d3d4a206Christopher Wiley DISALLOW_COPY_AND_ASSIGN(JavaOptions); 67ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski}; 68ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski 69a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wileyclass CppOptions final { 70a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley public: 71a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley 72a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley ~CppOptions() = default; 73a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley 74a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley // Parses the command line and returns a non-null pointer to an CppOptions 75a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley // object on success. 76a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley // Prints the usage statement on failure. 77a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley static std::unique_ptr<CppOptions> Parse(int argc, const char* const* argv); 78a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley 79054afbd3037addb4f2e245ecbc36f31d3040f877Christopher Wiley std::string InputFileName() const { return input_file_name_; } 80054afbd3037addb4f2e245ecbc36f31d3040f877Christopher Wiley std::string OutputHeaderDir() const { return output_header_dir_; } 81054afbd3037addb4f2e245ecbc36f31d3040f877Christopher Wiley std::string OutputCppFilePath() const { return output_file_name_; } 824432ccfb09ae2c28e42b9c4c58f0e2c2c5a3ba7aChristopher Wiley 83054afbd3037addb4f2e245ecbc36f31d3040f877Christopher Wiley std::vector<std::string> ImportPaths() const { return import_paths_; } 8419059cb70c5330787ba88f3860444e6da3ef3ca0Christopher Wiley std::string DependencyFilePath() const { return dep_file_name_; } 85a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley 86a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley private: 87a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley CppOptions() = default; 88a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley 89a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley std::string input_file_name_; 90a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley std::vector<std::string> import_paths_; 91054afbd3037addb4f2e245ecbc36f31d3040f877Christopher Wiley std::string output_header_dir_; 92054afbd3037addb4f2e245ecbc36f31d3040f877Christopher Wiley std::string output_file_name_; 93a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley std::string dep_file_name_; 94a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley 95a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley FRIEND_TEST(CppOptionsTests, ParsesCompileCpp); 96a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley DISALLOW_COPY_AND_ASSIGN(CppOptions); 97a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley}; 98a590de8d148bb42aa5f1f32aec6faae18a28e720Christopher Wiley 994432ccfb09ae2c28e42b9c4c58f0e2c2c5a3ba7aChristopher Wileybool EndsWith(const std::string& str, const std::string& suffix); 1004432ccfb09ae2c28e42b9c4c58f0e2c2c5a3ba7aChristopher Wileybool ReplaceSuffix(const std::string& old_suffix, 1014432ccfb09ae2c28e42b9c4c58f0e2c2c5a3ba7aChristopher Wiley const std::string& new_suffix, 1024432ccfb09ae2c28e42b9c4c58f0e2c2c5a3ba7aChristopher Wiley std::string* str); 1034432ccfb09ae2c28e42b9c4c58f0e2c2c5a3ba7aChristopher Wiley 1044427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley} // namespace android 1054427d8654985209c1ebf2fb4705bb3e1a4262be2Christopher Wiley} // namespace aidl 106ffa1686a7a8964d1f6e08ee2ab3e5eb42eb5f0b3Adam Lesinski 10789e3586afa180230fa999d4287df90df9d066cefChristopher Wiley#endif // AIDL_OPTIONS_H_ 108