Home | History | Annotate | Download | only in aidl
      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;
     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   bool gen_traces_{false};
     58   std::vector<std::string> files_to_preprocess_;
     59 
     60   // The following are for testability, but cannot be influenced on the command line.
     61 
     62   // Threshold of interface methods to enable outlining of onTransact cases.
     63   size_t onTransact_outline_threshold_{275u};
     64   // Number of cases to _not_ outline, if outlining is enabled.
     65   size_t onTransact_non_outline_count_{275u};
     66 
     67  private:
     68   JavaOptions() = default;
     69 
     70   FRIEND_TEST(EndToEndTest, IExampleInterface);
     71   FRIEND_TEST(EndToEndTest, IExampleInterface_WithTrace);
     72   FRIEND_TEST(EndToEndTest, IExampleInterface_Outlining);
     73   FRIEND_TEST(AidlTest, FailOnParcelable);
     74   FRIEND_TEST(AidlTest, WritePreprocessedFile);
     75   FRIEND_TEST(AidlTest, WritesCorrectDependencyFile);
     76   FRIEND_TEST(AidlTest, WritesCorrectDependencyFileNinja);
     77   FRIEND_TEST(AidlTest, WritesTrivialDependencyFileForParcelable);
     78 
     79   DISALLOW_COPY_AND_ASSIGN(JavaOptions);
     80 };
     81 
     82 class CppOptions final {
     83  public:
     84 
     85   ~CppOptions() = default;
     86 
     87   // Parses the command line and returns a non-null pointer to an CppOptions
     88   // object on success.
     89   // Prints the usage statement on failure.
     90   static std::unique_ptr<CppOptions> Parse(int argc, const char* const* argv);
     91 
     92   std::string InputFileName() const { return input_file_name_; }
     93   std::string OutputHeaderDir() const { return output_header_dir_; }
     94   std::string OutputCppFilePath() const { return output_file_name_; }
     95 
     96   std::vector<std::string> ImportPaths() const { return import_paths_; }
     97   std::string DependencyFilePath() const { return dep_file_name_; }
     98   bool DependencyFileNinja() const { return dep_file_ninja_; }
     99   bool ShouldGenTraces() const { return gen_traces_; }
    100 
    101  private:
    102   CppOptions() = default;
    103 
    104   std::string input_file_name_;
    105   std::vector<std::string> import_paths_;
    106   std::string output_header_dir_;
    107   std::string output_file_name_;
    108   std::string dep_file_name_;
    109   bool gen_traces_{false};
    110   bool dep_file_ninja_{false};
    111 
    112   FRIEND_TEST(CppOptionsTests, ParsesCompileCpp);
    113   FRIEND_TEST(CppOptionsTests, ParsesCompileCppNinja);
    114   DISALLOW_COPY_AND_ASSIGN(CppOptions);
    115 };
    116 
    117 bool EndsWith(const std::string& str, const std::string& suffix);
    118 bool ReplaceSuffix(const std::string& old_suffix,
    119                    const std::string& new_suffix,
    120                    std::string* str);
    121 
    122 }  // namespace android
    123 }  // namespace aidl
    124 
    125 #endif // AIDL_OPTIONS_H_
    126