aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java
blob: 45b1556930cfadb90f4e5819251632fb0bd16342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2014 The Bazel Authors. All rights reserved.
//
// 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 com.google.devtools.build.lib.rules.cpp;

import static com.google.common.truth.Truth.assertThat;

import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Unit tests for the {@code cc_toolchain_suite} rule.
 */
@RunWith(JUnit4.class)
public class CcToolchainSuiteTest extends BuildViewTestCase {
  @Test
  public void testSmoke() throws Exception {
    scratch.file(
        "cc/BUILD",
        "cc_toolchain_suite(",
        "    name = 'suite',",
        "    toolchains = { ",
        "       'cpu|cpu-compiler': ':cc-toolchain',",
        "       'k8|k8-compiler': ':cc-toolchain',",
        "       'darwin|cpu-compiler': ':cc-toolchain',",
        "       'x64_windows|cpu-compiler': ':cc-toolchain',",
        "    },",
        "    proto = \"\"\"",
        "major_version: 'v1'",
        "minor_version: '0'",
        "default_target_cpu: 'cpu'",
        "default_toolchain {",
        "  cpu: 'cpu'",
        "  toolchain_identifier: 'cpu-toolchain'",
        "}",
        "default_toolchain {",
        "  cpu: 'darwin'",
        "  toolchain_identifier: 'cpu-toolchain'",
        "}",
        "default_toolchain {",
        "  cpu: 'x64_windows'",
        "  toolchain_identifier: 'cpu-toolchain'",
        "}",
        "default_toolchain {",
        "  cpu: 'k8'",
        "  toolchain_identifier: 'k8-toolchain'",
        "}",
        "toolchain {",
        "  compiler: 'cpu-compiler'",
        "  target_cpu: 'cpu'",
        "  toolchain_identifier: 'cpu-toolchain'",
        "  host_system_name: 'linux'",
        "  target_system_name: 'linux'",
        "  abi_version: 'cpu-abi'",
        "  abi_libc_version: ''",
        "  target_libc: ''",
        "  builtin_sysroot: 'sysroot'",
        "  default_grte_top: '//cc:grtetop'",
        "  tool_path { name: 'cpu-compiler', path: 'cpu/compiler' }",
        "  tool_path { name: 'ar', path: 'cpu/ar' }",
        "  tool_path { name: 'cpp', path: 'cpu/cpp' }",
        "  tool_path { name: 'gcc', path: 'cpu/gcc' }",
        "  tool_path { name: 'gcov', path: 'cpu/gcov' }",
        "  tool_path { name: 'ld', path: 'cpu/ld' }",
        "  tool_path { name: 'nm', path: 'cpu/nm' }",
        "  tool_path { name: 'objcopy', path: 'cpu/objcopy' }",
        "  tool_path { name: 'objdump', path: 'cpu/objdump' }",
        "  tool_path { name: 'strip', path: 'cpu/strip' }",
        "}",
        "toolchain {",
        "  compiler: 'k8-compiler'",
        "  target_cpu: 'k8'",
        "  toolchain_identifier: 'k8-toolchain'",
        "  host_system_name: 'linux'",
        "  target_system_name: 'linux'",
        "  abi_version: ''",
        "  abi_libc_version: ''",
        "  target_libc: ''",
        "  builtin_sysroot: 'sysroot'",
        "  default_grte_top: '//cc:grtetop'",
        "  tool_path { name: 'k8-compiler', path: 'k8/compiler' }",
        "  tool_path { name: 'ar', path: 'k8/ar' }",
        "  tool_path { name: 'cpp', path: 'k8/cpp' }",
        "  tool_path { name: 'gcc', path: 'k8/gcc' }",
        "  tool_path { name: 'gcov', path: 'k8/gcov' }",
        "  tool_path { name: 'ld', path: 'k8/ld' }",
        "  tool_path { name: 'nm', path: 'k8/nm' }",
        "  tool_path { name: 'objcopy', path: 'k8/objcopy' }",
        "  tool_path { name: 'objdump', path: 'k8/objdump' }",
        "  tool_path { name: 'strip', path: 'k8/strip' }",
        "}",
        "\"\"\")",
        "cc_toolchain(",
        "    name = 'cc-toolchain',",
        "    module_map = 'map',",
        "    cpu = 'cpu',",
        "    compiler_files = 'compile',",
        "    dwp_files = 'dwp',",
        "    linker_files = 'link',",
        "    strip_files = ':strip',",
        "    objcopy_files = 'objcopy',",
        "    all_files = ':every-file',",
        "    dynamic_runtime_libs = ['dynamic-runtime-libs'],",
        "    static_runtime_libs = ['static-runtime-libs'])",
        "",
        "filegroup(name = 'every-file', srcs = ['//cc:everything'])");

    invalidatePackages();
    useConfiguration("--crosstool_top=//cc:suite");
    CppConfiguration cppConfig = getTargetConfiguration().getFragment(CppConfiguration.class);
    assertThat(cppConfig.getTargetCpu()).isEqualTo("cpu");
    assertThat(cppConfig.getAbi()).isEqualTo("cpu-abi");
    assertThat(cppConfig.getCompiler()).isEqualTo("cpu-compiler");
  }
}