1// Copyright 2022 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18	"testing"
19
20	"github.com/google/blueprint"
21
22	"android/soong/android"
23)
24
25func TestNdkHeaderDependency(t *testing.T) {
26	isDep := func(ctx *android.TestResult, from, toExpected android.Module) bool {
27		foundDep := false
28		ctx.VisitDirectDeps(from, func(toActual blueprint.Module) {
29			if toExpected.Name() == toActual.Name() {
30				foundDep = true
31			}
32		})
33		return foundDep
34	}
35	bp := `
36	ndk_library {
37		name: "libfoo",
38		first_version: "29",
39		symbol_file: "libfoo.map.txt",
40		export_header_libs: ["libfoo_headers"],
41	}
42	ndk_headers {
43		name: "libfoo_headers",
44		srcs: ["foo.h"],
45		license: "NOTICE",
46	}
47	//This module is needed since Soong creates a dep edge on source
48	cc_library {
49		name: "libfoo",
50	}
51	`
52	ctx := prepareForCcTest.RunTestWithBp(t, bp)
53	libfoo := ctx.ModuleForTests("libfoo.ndk", "android_arm64_armv8-a_sdk_shared")
54	libfoo_headers := ctx.ModuleForTests("libfoo_headers", "")
55	android.AssertBoolEquals(t, "Could not find headers of ndk_library", true, isDep(ctx, libfoo.Module(), libfoo_headers.Module()))
56}
57