diff options
-rw-r--r-- | aidl_unittest.cpp | 34 | ||||
-rw-r--r-- | options.cpp | 13 |
2 files changed, 40 insertions, 7 deletions
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp index 8c4d7965..3c5c6413 100644 --- a/aidl_unittest.cpp +++ b/aidl_unittest.cpp @@ -1323,5 +1323,39 @@ TEST_F(AidlTest, FailOnPartiallyAssignedIds) { EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); } +class AidlOutputPathTest : public AidlTest { + protected: + void SetUp() override { + AidlTest::SetUp(); + io_delegate_.SetFileContents("sub/dir/foo/bar/IFoo.aidl", "package foo.bar; interface IFoo {}"); + } + + void Test(const Options& options, const std::string expected_output_path) { + EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); + // check the existence + EXPECT_TRUE(io_delegate_.GetWrittenContents(expected_output_path, nullptr)); + } +}; + +TEST_F(AidlOutputPathTest, OutDirWithNoOutputFile) { + // <out_dir> / <package_name> / <type_name>.java + Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl"), "out/foo/bar/IFoo.java"); +} + +TEST_F(AidlOutputPathTest, OutDirWithOutputFile) { + // when output file is explicitly set, it is always respected. -o option is + // ignored. + Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl output/IFoo.java"), "output/IFoo.java"); +} + +TEST_F(AidlOutputPathTest, NoOutDirWithOutputFile) { + Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl output/IFoo.java"), "output/IFoo.java"); +} + +TEST_F(AidlOutputPathTest, NoOutDirWithNoOutputFile) { + // output is the same as the input file except for the suffix + Test(Options::From("aidl sub/dir/foo/bar/IFoo.aidl"), "sub/dir/foo/bar/IFoo.java"); +} + } // namespace aidl } // namespace android diff --git a/options.cpp b/options.cpp index 351b4f6a..ff99dad0 100644 --- a/options.cpp +++ b/options.cpp @@ -309,18 +309,17 @@ Options::Options(int argc, const char* const argv[], Options::Language default_l input_files_.emplace_back(argv[optind++]); if (argc - optind >= 1) { output_file_ = argv[optind++]; - } else { - // when output is omitted, output is by default set to the input - // file path with .aidl is replaced to .java. + } else if (output_dir_.empty()) { + // when output is omitted and -o option isn't set, the output is by + // default set to the input file path with .aidl is replaced to .java. + // If -o option is set, the output path is calculated by + // generate_outputFileName which returns "<output_dir>/<package/name>/ + // <typename>.java" output_file_ = input_files_.front(); if (android::base::EndsWith(output_file_, ".aidl")) { output_file_ = output_file_.substr(0, output_file_.length() - strlen(".aidl")); } output_file_ += ".java"; - - if (!output_dir_.empty()) { - output_file_ = output_dir_ + output_file_; - } } } else if (IsCppOutput()) { input_files_.emplace_back(argv[optind++]); |