aidl-cpp ensures that output file is at <out_dir>/<package>/<name>.cpp

Background:
When an AIDL file is put to the srcs property of a cc_* module, Soong
creates a build rule that invokes aidl-cpp to convert the AIDL file into
a CPP source code and headers. Specifically, if the AIDL file is at
subdir/android/foo/IFoo.aidl, the command is

aidl-cpp subdir/android/foo/IFoo.aidl\   // input aidl
         out/..../gen/subdir/android/foo/IFoo.aidl\  // output cpp
	 out/..../gen  // directory for output headers

In addition, the build rule has out/.../gen/subdir/android/foo/BnFoo.h,
etc. as the implicit outputs.

Problem:
In the example above, if the package of the AIDL type is "android.foo",
not "subdir.android.foo", then aidl-cpp generates the headers at
out/.../gen/android/foo/BnFoo.h, etc.  Notice the absence of 'subdir'.
These paths are different from the implicit outputs that the Soong
expects. The root cause is that Soong has an implicit assumption that
the package of an AIDL file at subdir/android/foo is
"subdir.android.foo", because it can't look into the AIDL file.

When the actual outputs and the outputs listed in the build rule are
different, Soong thanksfully triggers an error, but the error doesn't
have context and doesn't suggest a way to fix it.

The correct thing the developer should do is to set 'subdir' as the base
directory so that Soong can infer the package name from the relative
path from the base directory.

Solution:
This change adds a check to the AIDL compiler so that it triggers an
error when the output path given by Soong is different from the path
that is calculated based on the correct package name. It also emits a
message suggesting to fix this using the filegroup and the path
property.

Bug: 184586092
Test: aidl_unittests
Change-Id: I0f23b6027ba3a4755cc2901f4a7f7fc70bffd0ef
2 files changed