aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-06-13 03:11:02 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-06-13 03:11:02 +0000
commit770c9e632c3097d8c66d94ca299ffc0365001080 (patch)
tree22a04d95ef122fa7e11fb773115ce817489b2a60
parent8722501946b58f477c2cb1dc9ed0d6453f1d40b8 (diff)
parentc34c45be4ee0612974848004942f143a7882683d (diff)
downloadaidl-android10-qpr1-c-s1-release.tar.gz
Change-Id: I373c71f1f987637a2539a20870679914970814a5
-rw-r--r--aidl_unittest.cpp34
-rw-r--r--options.cpp13
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++]);