// Copyright 2015 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.packages.util; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain; import com.google.protobuf.TextFormat; import java.io.IOException; /** * Creates mock BUILD files required for the C/C++ rules. */ public abstract class MockCcSupport { /** * Filter to remove implicit crosstool artifact and module map inputs * of C/C++ rules. */ public static final Predicate CC_ARTIFACT_FILTER = new Predicate() { @Override public boolean apply(Artifact artifact) { String basename = artifact.getExecPath().getBaseName(); String pathString = artifact.getExecPathString(); return !pathString.startsWith("third_party/crosstool/") && !(pathString.contains("/internal/_middlemen") && basename.contains("crosstool")) && !pathString.startsWith("_bin/build_interface_so") && !pathString.endsWith(".cppmap"); } }; /** * A feature configuration snippet useful for testing header processing. */ public static final String HEADER_PROCESSING_FEATURE_CONFIGURATION = "" + "feature {" + " name: 'parse_headers'" + " flag_set {" + " action: 'c++-header-parsing'" + " flag_group {" + " flag: ''" + " }" + " }" + "}" + "feature {" + " name: 'preprocess_headers'" + " flag_set {" + " action: 'c++-header-preprocessing'" + " flag_group {" + " flag: ''" + " }" + " }" + "}"; /** * A feature configuration snippet useful for testing the layering check. */ public static final String LAYERING_CHECK_FEATURE_CONFIGURATION = "" + "feature {" + " name: 'layering_check'" + " flag_set {" + " action: 'c-compile'" + " action: 'c++-compile'" + " action: 'c++-header-parsing'" + " action: 'c++-header-preprocessing'" + " action: 'c++-module-compile'" + " flag_group {" + " flag: 'dependent_module_map_file:%{dependent_module_map_files}'" + " }" + " }" + "}"; /** * A feature configuration snippet useful for testing header modules. */ public static final String HEADER_MODULES_FEATURE_CONFIGURATION = "" + "feature {" + " name: 'header_modules'" + " implies: 'module_maps'" + " implies: 'use_header_modules'" + "}" + "feature {" + " name: 'module_maps'" + " flag_set {" + " action: 'c-compile'" + " action: 'c++-compile'" + " action: 'c++-header-parsing'" + " action: 'c++-header-preprocessing'" + " action: 'c++-module-compile'" + " flag_group {" + " flag: 'module_name:%{module_name}'" + " flag: 'module_map_file:%{module_map_file}'" + " }" + " }" + "}" + "feature {" + " name: 'use_header_modules'" + " flag_set {" + " action: 'c-compile'" + " action: 'c++-compile'" + " action: 'c++-header-parsing'" + " action: 'c++-header-preprocessing'" + " action: 'c++-modules-compile'" + " flag_group {" + " flag: 'module_file:%{module_files}'" + " }" + " }" + "}"; /** * A feature configuration snippet useful for testing environment variables. */ public static final String ENV_VAR_FEATURE_CONFIGURATION = "" + "feature {" + " name: 'env_feature'" + " implies: 'static_env_feature'" + " implies: 'module_maps'" + "}" + "feature {" + " name: 'static_env_feature'" + " env_set {" + " action: 'c-compile'" + " action: 'c++-compile'" + " action: 'c++-header-parsing'" + " action: 'c++-header-preprocessing'" + " action: 'c++-module-compile'" + " env_entry {" + " key: 'cat'" + " value: 'meow'" + " }" + " }" + "}" + "feature {" + " name: 'module_maps'" + " env_set {" + " action: 'c-compile'" + " action: 'c++-compile'" + " action: 'c++-header-parsing'" + " action: 'c++-header-preprocessing'" + " action: 'c++-module-compile'" + " env_entry {" + " key: 'module'" + " value: 'module_name:%{module_name}'" + " }" + " }" + "}"; public static final String THIN_LTO_CONFIGURATION = "" + "feature { " + " name: 'thin_lto'" + " flag_set {" + " action: 'c-compile'" + " action: 'c++-compile'" + " flag_group {" + " flag: '-Xclang-only=-Wno-inconsistent-missing-override'" + " flag: '-flto'" + " flag: '-O2'" + " }" + " }" + "}"; /** Filter to remove implicit dependencies of C/C++ rules. */ private final Predicate