diff options
author | Christopher Wiley <wiley@google.com> | 2016-04-21 11:43:45 -0700 |
---|---|---|
committer | Christopher Wiley <wiley@google.com> | 2016-04-21 13:58:29 -0700 |
commit | 303b43ca5a93ce89f438ad4dd200c0ca317832de (patch) | |
tree | 82329096a2e8db7dcc643ca56ceda5e2aa57e6c7 | |
parent | 8f314b0d4c3f195c98c6dd7e671fc2b9d4bfa76f (diff) | |
download | aidl-303b43ca5a93ce89f438ad4dd200c0ca317832de.tar.gz |
Generate a trivial dep file for parcelables
It turns out that the SDK tools request this.
This is a cherry-pick of b1bbdf80cb9fcd8181aa2cb326317929cfac890c.
Bug: 28091660
Change-Id: Iba08f116086953d01c0383f4e26049b2ddfe9b29
Test: unittests pass, added another
-rw-r--r-- | aidl.cpp | 4 | ||||
-rw-r--r-- | aidl_unittest.cpp | 26 | ||||
-rw-r--r-- | options.h | 5 |
3 files changed, 32 insertions, 3 deletions
@@ -684,7 +684,9 @@ int compile_aidl_to_java(const JavaOptions& options, if (aidl_err == AidlError::FOUND_PARCELABLE && !options.fail_on_parcelable_) { // We aborted code generation because this file contains parcelables. // However, we were not told to complain if we find parcelables. - // Just exit quietly. + // Just generate a dep file and exit quietly. The dep file is for a legacy + // use case by the SDK. + write_java_dep_file(options, imports, io_delegate, ""); return 0; } if (aidl_err != AidlError::OK) { diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp index 01a16e17..3375ed97 100644 --- a/aidl_unittest.cpp +++ b/aidl_unittest.cpp @@ -48,6 +48,13 @@ R"(place/for/output/p/IFoo.java : \ p/IFoo.aidl : )"; +const char kExpectedParcelableDepFileContents[] = +R"( : \ + p/Foo.aidl + +p/Foo.aidl : +)"; + } // namespace class AidlTest : public ::testing::Test { @@ -300,5 +307,24 @@ TEST_F(AidlTest, WritesCorrectDependencyFile) { EXPECT_EQ(actual_dep_file_contents, kExpectedDepFileContents); } +TEST_F(AidlTest, WritesTrivialDependencyFileForParcelable) { + // The SDK uses aidl to decide whether a .aidl file is a parcelable. It does + // this by calling aidl with every .aidl file it finds, then parsing the + // generated dependency files. Those that reference .java output files are + // for interfaces and those that do not are parcelables. However, for both + // parcelables and interfaces, we *must* generate a non-empty dependency file. + JavaOptions options; + options.input_file_name_ = "p/Foo.aidl"; + options.output_base_folder_ = "place/for/output"; + options.dep_file_name_ = "dep/file/path"; + io_delegate_.SetFileContents(options.input_file_name_, + "package p; parcelable Foo;"); + EXPECT_EQ(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_)); + string actual_dep_file_contents; + EXPECT_TRUE(io_delegate_.GetWrittenContents(options.dep_file_name_, + &actual_dep_file_contents)); + EXPECT_EQ(actual_dep_file_contents, kExpectedParcelableDepFileContents); +} + } // namespace aidl } // namespace android @@ -1,6 +1,5 @@ /* - * Copyright (C) 2015, The Android Open Source Project - * + * Copyright (C) 2015, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -62,6 +61,8 @@ class JavaOptions final { FRIEND_TEST(AidlTest, FailOnParcelable); FRIEND_TEST(AidlTest, WritePreprocessedFile); FRIEND_TEST(AidlTest, WritesCorrectDependencyFile); + FRIEND_TEST(AidlTest, WritesTrivialDependencyFileForParcelable); + DISALLOW_COPY_AND_ASSIGN(JavaOptions); }; |