blob: db6fb3a3e589a0488d04f4a6cbed1a24addd80ab [file] [log] [blame]
Yu Liu7f3605f2022-02-08 14:15:12 -08001// 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 (
Sasha Smundakedd16662022-10-07 14:44:50 -070018 "android/soong/bazel/cquery"
Yu Liu7f3605f2022-02-08 14:15:12 -080019 "testing"
20
21 "android/soong/android"
22)
23
24func TestCcBinaryWithBazel(t *testing.T) {
25 bp := `
26cc_binary {
27 name: "foo",
28 srcs: ["foo.cc"],
29 bazel_module: { label: "//foo/bar:bar" },
30}`
31 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
32 config.BazelContext = android.MockBazelContext{
33 OutputBaseDir: "outputbase",
Sasha Smundakedd16662022-10-07 14:44:50 -070034 LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{
35 "//foo/bar:bar": cquery.CcUnstrippedInfo{
36 OutputFile: "foo",
37 UnstrippedOutput: "foo.unstripped",
38 },
Yu Liu7f3605f2022-02-08 14:15:12 -080039 },
40 }
41 ctx := testCcWithConfig(t, config)
42
43 binMod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module()
44 producer := binMod.(android.OutputFileProducer)
45 outputFiles, err := producer.OutputFiles("")
46 if err != nil {
47 t.Errorf("Unexpected error getting cc_binary outputfiles %s", err)
48 }
49 expectedOutputFiles := []string{"outputbase/execroot/__main__/foo"}
50 android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
51
52 unStrippedFilePath := binMod.(*Module).UnstrippedOutputFile()
Sasha Smundakedd16662022-10-07 14:44:50 -070053 expectedUnStrippedFile := "outputbase/execroot/__main__/foo.unstripped"
Yu Liu7f3605f2022-02-08 14:15:12 -080054 android.AssertStringEquals(t, "Unstripped output file", expectedUnStrippedFile, unStrippedFilePath.String())
55}
David Brazdil958c9572022-04-22 15:17:54 +010056
57func TestBinaryLinkerScripts(t *testing.T) {
58 result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
59 cc_binary {
60 name: "foo",
61 srcs: ["foo.cc"],
62 linker_scripts: ["foo.ld", "bar.ld"],
63 }`)
64
65 binFoo := result.ModuleForTests("foo", "android_arm64_armv8-a").Rule("ld")
66
67 android.AssertStringListContains(t, "missing dependency on linker_scripts",
68 binFoo.Implicits.Strings(), "foo.ld")
69 android.AssertStringListContains(t, "missing dependency on linker_scripts",
70 binFoo.Implicits.Strings(), "bar.ld")
71 android.AssertStringDoesContain(t, "missing flag for linker_scripts",
David Brazdil3ac9d2b2022-05-09 19:35:10 +010072 binFoo.Args["ldFlags"], "-Wl,--script,foo.ld")
David Brazdil958c9572022-04-22 15:17:54 +010073 android.AssertStringDoesContain(t, "missing flag for linker_scripts",
David Brazdil3ac9d2b2022-05-09 19:35:10 +010074 binFoo.Args["ldFlags"], "-Wl,--script,bar.ld")
David Brazdil958c9572022-04-22 15:17:54 +010075}