1313// limitations under the License.
1414package com .google .devtools .build .lib .packages .util ;
1515
16- import static java .util .stream .Collectors .joining ;
17-
1816import com .google .common .base .Joiner ;
1917import com .google .common .base .Preconditions ;
2018import com .google .common .collect .ImmutableList ;
21- import com .google .devtools .build .lib .cmdline .Label ;
2219import com .google .devtools .build .lib .packages .util .Crosstool .CcToolchainConfig ;
2320import com .google .devtools .build .lib .rules .cpp .CppRuleClasses ;
2421import com .google .devtools .build .lib .testutil .TestConstants ;
@@ -59,8 +56,6 @@ public static final class CcToolchainConfig {
5956 private final ImmutableList <Pair <String , String >> toolPaths ;
6057 private final ImmutableList <String > cxxBuiltinIncludeDirectories ;
6158 private final ImmutableList <Pair <String , String >> makeVariables ;
62- private final ImmutableList <String > toolchainExecConstraints ;
63- private final ImmutableList <String > toolchainTargetConstraints ;
6459
6560 private CcToolchainConfig (
6661 String cpu ,
@@ -78,9 +73,7 @@ private CcToolchainConfig(
7873 ImmutableList <ImmutableList <String >> artifactNamePatterns ,
7974 ImmutableList <Pair <String , String >> toolPaths ,
8075 ImmutableList <String > cxxBuiltinIncludeDirectories ,
81- ImmutableList <Pair <String , String >> makeVariables ,
82- ImmutableList <String > toolchainExecConstraints ,
83- ImmutableList <String > toolchainTargetConstraints ) {
76+ ImmutableList <Pair <String , String >> makeVariables ) {
8477 this .cpu = cpu ;
8578 this .compiler = compiler ;
8679 this .toolchainIdentifier = toolchainIdentifier ;
@@ -97,8 +90,6 @@ private CcToolchainConfig(
9790 this .cxxBuiltinIncludeDirectories = cxxBuiltinIncludeDirectories ;
9891 this .makeVariables = makeVariables ;
9992 this .ccTargetOs = ccTargetOs ;
100- this .toolchainExecConstraints = toolchainExecConstraints ;
101- this .toolchainTargetConstraints = toolchainTargetConstraints ;
10293 }
10394
10495 public static Builder builder () {
@@ -123,8 +114,6 @@ public static class Builder {
123114 private String targetLibc = "local" ;
124115 private String abiVersion = "local" ;
125116 private String abiLibcVersion = "local" ;
126- private ImmutableList <String > toolchainExecConstraints = ImmutableList .of ();
127- private ImmutableList <String > toolchainTargetConstraints = ImmutableList .of ();
128117
129118 public Builder withCpu (String cpu ) {
130119 this .cpu = cpu ;
@@ -212,16 +201,6 @@ public Builder withMakeVariables(Pair<String, String>... makeVariables) {
212201 return this ;
213202 }
214203
215- public Builder withToolchainExecConstraints (String ... execConstraints ) {
216- this .toolchainExecConstraints = ImmutableList .copyOf (execConstraints );
217- return this ;
218- }
219-
220- public Builder withToolchainTargetConstraints (String ... targetConstraints ) {
221- this .toolchainTargetConstraints = ImmutableList .copyOf (targetConstraints );
222- return this ;
223- }
224-
225204 public CcToolchainConfig build () {
226205 return new CcToolchainConfig (
227206 cpu ,
@@ -239,9 +218,7 @@ public CcToolchainConfig build() {
239218 artifactNamePatterns ,
240219 toolPaths ,
241220 cxxBuiltinIncludeDirectories ,
242- makeVariables ,
243- toolchainExecConstraints ,
244- toolchainTargetConstraints );
221+ makeVariables );
245222 }
246223 }
247224
@@ -257,35 +234,6 @@ public String getCompiler() {
257234 return compiler ;
258235 }
259236
260- private static String formatConstraints (String type , ImmutableList <String > constraints ) {
261- if (constraints .isEmpty ()) {
262- return "" ;
263- }
264-
265- String output =
266- constraints .stream ()
267- .map (constraint -> String .format ("'%s'," , constraint ))
268- .collect (joining ("\n " ));
269-
270- return String .format ("%s_compatible_with = [\n %s\n ]," , type , output );
271- }
272-
273- public String getToolchainExecConstraints () {
274- return formatConstraints ("exec" , toolchainExecConstraints );
275- }
276-
277- public String getToolchainTargetConstraints () {
278- ImmutableList <String > constraints = this .toolchainTargetConstraints ;
279- if (constraints .isEmpty () && getTargetCpu ().equals ("k8" )) {
280- // Use default constraints
281- constraints =
282- ImmutableList .of (
283- TestConstants .CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64" ,
284- TestConstants .CONSTRAINTS_PACKAGE_ROOT + "os:linux" );
285- }
286- return formatConstraints ("target" , constraints );
287- }
288-
289237 public boolean hasStaticLinkCppRuntimesFeature () {
290238 return features .contains (CppRuleClasses .STATIC_LINK_CPP_RUNTIMES );
291239 }
@@ -307,9 +255,7 @@ public static CcToolchainConfig getCcToolchainConfigForCpu(String cpu) {
307255 /* artifactNamePatterns= */ ImmutableList .of (),
308256 /* toolPaths= */ ImmutableList .of (),
309257 /* cxxBuiltinIncludeDirectories= */ ImmutableList .of (),
310- /* makeVariables= */ ImmutableList .of (),
311- /* toolchainExecConstraints= */ ImmutableList .of (),
312- /* toolchainTargetConstraints= */ ImmutableList .of ());
258+ /* makeVariables= */ ImmutableList .of ());
313259 }
314260
315261 public static CcToolchainConfig getDefaultCcToolchainConfig () {
@@ -377,16 +323,14 @@ public String getCcToolchainConfigRule() {
377323 private final MockToolsConfig config ;
378324
379325 private final String crosstoolTop ;
380- private final Label crosstoolTopLabel ;
381326 private String ccToolchainConfigFileContents ;
382327 private ImmutableList <String > archs ;
383328 private boolean supportsHeaderParsing ;
384329 private ImmutableList <CcToolchainConfig > ccToolchainConfigList = ImmutableList .of ();
385330
386- Crosstool (MockToolsConfig config , String crosstoolTop , Label crosstoolTopLabel ) {
331+ Crosstool (MockToolsConfig config , String crosstoolTop ) {
387332 this .config = config ;
388333 this .crosstoolTop = crosstoolTop ;
389- this .crosstoolTopLabel = crosstoolTopLabel ;
390334 }
391335
392336 public Crosstool setCcToolchainFile (String ccToolchainConfigFileContents ) {
@@ -483,12 +427,8 @@ public void write() throws IOException {
483427 .join (
484428 "toolchain(" ,
485429 " name = 'cc-toolchain-" + suffix + "'," ,
486- " toolchain_type = '"
487- + TestConstants .TOOLS_REPOSITORY
488- + "//tools/cpp:toolchain_type'," ,
430+ " toolchain_type = ':toolchain_type'," ,
489431 " toolchain = ':cc-compiler-" + suffix + "'," ,
490- toolchain .getToolchainExecConstraints (),
491- toolchain .getToolchainTargetConstraints (),
492432 ")" ,
493433 toolchain .getCcToolchainConfigRule (),
494434 "cc_toolchain(" ,
@@ -557,12 +497,17 @@ public void write() throws IOException {
557497 config .create (crosstoolTop + "/mock_version/x86/bin/ld" );
558498 config .overwrite (crosstoolTop + "/BUILD" , build );
559499 config .overwrite (crosstoolTop + "/cc_toolchain_config.bzl" , ccToolchainConfigFileContents );
500+ config .overwrite (
501+ TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/cpp/cc_toolchain_config_lib.bzl" ,
502+ ResourceLoader .readFromResources (
503+ TestConstants .BAZEL_REPO_PATH + "tools/cpp/cc_toolchain_config_lib.bzl" ));
504+ config .overwrite (
505+ TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/build_defs/cc/action_names.bzl" ,
506+ ResourceLoader .readFromResources (
507+ TestConstants .BAZEL_REPO_PATH + "tools/build_defs/cc/action_names.bzl" ));
508+ config .create (TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/build_defs/cc/BUILD" );
509+ config .append (TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/cpp/BUILD" , "" );
560510 config .create (crosstoolTop + "/crosstool.cppmap" , "module crosstool {}" );
561- config .append (
562- "WORKSPACE" ,
563- String .format (
564- "register_toolchains('%s:all')" ,
565- crosstoolTopLabel .getPackageIdentifier ().getCanonicalForm ()));
566511 }
567512
568513 public void writeOSX () throws IOException {
@@ -638,7 +583,6 @@ public void writeOSX() throws IOException {
638583 " objcopy_files = ':empty'," ,
639584 " strip_files = ':empty'," ,
640585 " supports_param_files = 0," ,
641- supportsHeaderParsing ? " supports_header_parsing = 1," : "" ,
642586 ")" ,
643587 "toolchain(name = 'cc-toolchain-" + toolchainConfig .getTargetCpu () + "'," ,
644588 " exec_compatible_with = []," ,
@@ -657,5 +601,15 @@ public void writeOSX() throws IOException {
657601 MockObjcSupport .DEFAULT_OSX_CROSSTOOL_DIR + "/BUILD" ,
658602 Joiner .on ("\n " ).join (crosstoolBuild .build ()));
659603 config .overwrite (crosstoolTop + "/cc_toolchain_config.bzl" , ccToolchainConfigFileContents );
604+ config .overwrite (
605+ TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/cpp/cc_toolchain_config_lib.bzl" ,
606+ ResourceLoader .readFromResources (
607+ TestConstants .BAZEL_REPO_PATH + "tools/cpp/cc_toolchain_config_lib.bzl" ));
608+ config .overwrite (
609+ TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/build_defs/cc/action_names.bzl" ,
610+ ResourceLoader .readFromResources (
611+ TestConstants .BAZEL_REPO_PATH + "tools/build_defs/cc/action_names.bzl" ));
612+ config .overwrite (TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/build_defs/cc/BUILD" );
613+ config .append (TestConstants .TOOLS_REPOSITORY_SCRATCH + "tools/cpp/BUILD" , "" );
660614 }
661615}
0 commit comments