Replace aidl_interface_headers with aidl_library

aosp/2571770 introduced aidl_library module type to better map with Bazel BUILDs and enforces explicit aidl headers.  Some branches don't have system/tools/aidl so aidl_library was implemented in build/soong instead.

Since aidl_library_headers isn't used anywhere yet, this CL has no
regression.

Test: go test
Change-Id: I1c4df39947e655b649dcde33b666f27a020cfd7b
diff --git a/build/Android.bp b/build/Android.bp
index 85e3f3d..7c64996 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -28,6 +28,7 @@
         "blueprint",
         "soong",
         "soong-android",
+        "soong-aidl-library",
         "soong-bp2build",
         "soong-cc",
         "soong-genrule",
@@ -41,8 +42,8 @@
         "aidl_api.go",
         "aidl_gen_rule.go",
         "aidl_interface_backends.go",
+
         "aidl_interface_defaults.go",
-        "aidl_interface_headers.go",
         "aidl_interface_metadata_singleton.go",
         "aidl_rust_source_provider.go",
         "aidl_utils.go",
diff --git a/build/aidl_api.go b/build/aidl_api.go
index 8424ef0..233421e 100644
--- a/build/aidl_api.go
+++ b/build/aidl_api.go
@@ -15,6 +15,7 @@
 package aidl
 
 import (
+	"android/soong/aidl_library"
 	"android/soong/android"
 	"reflect"
 
@@ -387,13 +388,13 @@
 			deps.implicits = append(deps.implicits, api.checkHashTimestamps.Paths()...)
 			deps.implicits = append(deps.implicits, api.hasDevelopment)
 		case interfaceHeadersDepTag:
-			headerInfo, ok := ctx.OtherModuleProvider(dep, AidlInterfaceHeadersProvider).(AidlInterfaceHeadersInfo)
+			aidlLibraryInfo, ok := ctx.OtherModuleProvider(dep, aidl_library.AidlLibraryProvider).(aidl_library.AidlLibraryInfo)
 			if !ok {
-				ctx.PropertyErrorf("headers", "module %v does not provide AidlInterfaceHeadersInfo", dep.Name())
+				ctx.PropertyErrorf("headers", "module %v does not provide AidlLibraryInfo", dep.Name())
 				return
 			}
-			deps.implicits = append(deps.implicits, headerInfo.Srcs...)
-			deps.imports = append(deps.imports, headerInfo.IncludeDir)
+			deps.implicits = append(deps.implicits, aidlLibraryInfo.Hdrs.ToList()...)
+			deps.imports = append(deps.imports, aidlLibraryInfo.IncludeDirs.ToList().Strings()...)
 		}
 	})
 	return deps
diff --git a/build/aidl_interface.go b/build/aidl_interface.go
index f0330a9..15ef418 100644
--- a/build/aidl_interface.go
+++ b/build/aidl_interface.go
@@ -432,8 +432,7 @@
 	// --dumpapi options
 	Dumpapi DumpApiProperties
 
-	// List of aidl_interface_headers modules that provide include dependencies
-	// for the AIDL tool.
+	// List of aidl_library modules that provide aidl headers for the AIDL tool.
 	Headers []string
 }
 
diff --git a/build/aidl_interface_bp2build_test.go b/build/aidl_interface_bp2build_test.go
index 65cb3b2..91d8a2f 100644
--- a/build/aidl_interface_bp2build_test.go
+++ b/build/aidl_interface_bp2build_test.go
@@ -1,6 +1,7 @@
 package aidl
 
 import (
+	"android/soong/aidl_library"
 	"android/soong/android"
 	"android/soong/bp2build"
 	"testing"
@@ -12,37 +13,17 @@
 		t,
 		func(ctx android.RegistrationContext) {
 			ctx.RegisterModuleType("aidl_interface", AidlInterfaceFactory)
-			ctx.RegisterModuleType("aidl_interface_headers", AidlInterfaceHeadersFactory)
+			ctx.RegisterModuleType("aidl_library", aidl_library.AidlLibraryFactory)
 		},
 		tc,
 	)
 }
 
-func TestAidlInterfaceHeaders(t *testing.T) {
-	runAidlInterfaceTestCase(t, bp2build.Bp2buildTestCase{
-		Description: `aidl_interface_headers`,
-		Blueprint: `
-			aidl_interface_headers {
-				name: "aidl-interface-headers",
-				include_dir: "src",
-				srcs: [
-					"src/A.aidl",
-				],
-			}`,
-		ExpectedBazelTargets: []string{
-			bp2build.MakeBazelTargetNoRestrictions("aidl_library", "aidl-interface-headers", bp2build.AttrNameToString{
-				"strip_import_prefix": `"src"`,
-				"hdrs":                `["src/A.aidl"]`,
-			}),
-		},
-	})
-}
-
 func TestAidlInterface(t *testing.T) {
 	runAidlInterfaceTestCase(t, bp2build.Bp2buildTestCase{
 		Description: `aidl_interface with single "latest" aidl_interface import`,
 		Blueprint: `
-			aidl_interface_headers {
+			aidl_library {
 				name: "aidl-interface-headers",
 			}
 			aidl_interface {
@@ -68,7 +49,9 @@
 				],
 			}`,
 		ExpectedBazelTargets: []string{
-			bp2build.MakeBazelTargetNoRestrictions("aidl_library", "aidl-interface-headers", bp2build.AttrNameToString{}),
+			bp2build.MakeBazelTargetNoRestrictions("aidl_library", "aidl-interface-headers", bp2build.AttrNameToString{
+				"tags": `["apex_available=//apex_available:anyapex"]`,
+			}),
 			bp2build.MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface-import", bp2build.AttrNameToString{
 				"java_config": `{
         "enabled": True,
diff --git a/build/aidl_interface_headers.go b/build/aidl_interface_headers.go
deleted file mode 100644
index 523526e..0000000
--- a/build/aidl_interface_headers.go
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (C) 2022 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
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package aidl
-
-import (
-	"path/filepath"
-
-	"android/soong/android"
-	"android/soong/bazel"
-
-	"github.com/google/blueprint"
-	"github.com/google/blueprint/proptools"
-)
-
-func init() {
-	android.RegisterModuleType("aidl_interface_headers", AidlInterfaceHeadersFactory)
-}
-
-type AidlInterfaceHeadersInfo struct {
-	Srcs       android.Paths
-	IncludeDir string
-}
-
-var AidlInterfaceHeadersProvider = blueprint.NewProvider(AidlInterfaceHeadersInfo{})
-
-type aidlInterfaceHeadersProperties struct {
-	// List of .aidl files which compose this interface.
-	Srcs []string `android:"path"`
-
-	// Relative path for includes. assumes AIDL path is relative to current directory.
-	Include_dir *string
-}
-
-type aidlInterfaceHeaders struct {
-	android.ModuleBase
-	android.BazelModuleBase
-
-	properties aidlInterfaceHeadersProperties
-
-	srcs android.Paths
-}
-
-// Modules which provide AIDL sources that are only used to provide "-I" flags to the
-// aidl tool. No language bindings are generated from these modules. Typically this will
-// be used to provide includes for UnstructuredParcelable AIDL definitions such as those
-// coming from framework modules.
-func AidlInterfaceHeadersFactory() android.Module {
-	i := &aidlInterfaceHeaders{}
-	i.AddProperties(&i.properties)
-	android.InitAndroidModule(i)
-	android.InitBazelModule(i)
-	return i
-}
-
-func (i *aidlInterfaceHeaders) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
-	srcs := android.BazelLabelForModuleSrc(ctx, i.properties.Srcs)
-
-	attrs := &aidlLibraryAttributes{
-		Hdrs:                bazel.MakeLabelListAttribute(srcs),
-		Strip_import_prefix: i.properties.Include_dir,
-	}
-
-	ctx.CreateBazelTargetModule(
-		bazel.BazelTargetModuleProperties{
-			Rule_class:        "aidl_library",
-			Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl",
-		},
-		android.CommonAttributes{Name: i.Name()},
-		attrs,
-	)
-}
-
-func (i *aidlInterfaceHeaders) GenerateAndroidBuildActions(ctx android.ModuleContext) {
-	ctx.SetProvider(AidlInterfaceHeadersProvider, AidlInterfaceHeadersInfo{
-		Srcs:       android.PathsForModuleSrc(ctx, i.properties.Srcs),
-		IncludeDir: filepath.Join(ctx.ModuleDir(), proptools.String(i.properties.Include_dir)),
-	})
-}
diff --git a/build/aidl_test.go b/build/aidl_test.go
index f0a951b..4904cd5 100644
--- a/build/aidl_test.go
+++ b/build/aidl_test.go
@@ -24,6 +24,7 @@
 	"github.com/google/blueprint"
 	"github.com/google/blueprint/proptools"
 
+	"android/soong/aidl_library"
 	"android/soong/android"
 	"android/soong/cc"
 	"android/soong/genrule"
@@ -181,12 +182,13 @@
 		rust.PrepareForTestWithRustBuildComponents,
 		android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
 			ctx.RegisterModuleType("aidl_interface", AidlInterfaceFactory)
-			ctx.RegisterModuleType("aidl_interface_headers", AidlInterfaceHeadersFactory)
 			ctx.RegisterModuleType("aidl_interface_defaults", AidlInterfaceDefaultsFactory)
 			ctx.RegisterModuleType("aidl_interfaces_metadata", aidlInterfacesMetadataSingletonFactory)
 			ctx.RegisterModuleType("rust_defaults", func() android.Module {
 				return rust.DefaultsFactory()
 			})
+			ctx.RegisterModuleType("aidl_library", aidl_library.AidlLibraryFactory)
+
 			ctx.PreArchMutators(registerPreArchMutators)
 			ctx.PostDepsMutators(registerPostDepsMutators)
 		}),
@@ -1573,7 +1575,7 @@
 		"baz/aidl_api/baz-iface/1/.hash":            nil,
 
 		"boq/Android.bp": []byte(`
-			aidl_interface_headers {
+			aidl_library {
 				name: "boq-iface-headers",
 				srcs: ["b/Boq.aidl"],
 			}