xref: /aosp_15_r20/build/soong/cc/binary_test.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
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	"android/soong/android"
21)
22
23func TestBinaryLinkerScripts(t *testing.T) {
24	t.Parallel()
25	result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
26		cc_binary {
27			name: "foo",
28			srcs: ["foo.cc"],
29			linker_scripts: ["foo.ld", "bar.ld"],
30		}`)
31
32	binFoo := result.ModuleForTests("foo", "android_arm64_armv8-a").Rule("ld")
33
34	android.AssertStringListContains(t, "missing dependency on linker_scripts",
35		binFoo.Implicits.Strings(), "foo.ld")
36	android.AssertStringListContains(t, "missing dependency on linker_scripts",
37		binFoo.Implicits.Strings(), "bar.ld")
38	android.AssertStringDoesContain(t, "missing flag for linker_scripts",
39		binFoo.Args["ldFlags"], "-Wl,--script,foo.ld")
40	android.AssertStringDoesContain(t, "missing flag for linker_scripts",
41		binFoo.Args["ldFlags"], "-Wl,--script,bar.ld")
42}
43