use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.
the class CrosstoolConfigurationLoader method findCrosstoolConfiguration.
private static CrosstoolFile findCrosstoolConfiguration(ConfigurationEnvironment env, Label crosstoolTop) throws IOException, InvalidConfigurationException, InterruptedException {
CrosstoolProto crosstoolProto = getCrosstoolProtofromBuildFile(env, crosstoolTop);
if (crosstoolProto == null) {
crosstoolProto = getCrosstoolProtoFromCrosstoolFile(env, crosstoolTop);
}
if (crosstoolProto == null) {
throw new InvalidConfigurationException("The crosstool_top you specified was resolved to '" + crosstoolTop + "', which does not contain a CROSSTOOL file. " + "You can use a crosstool from the depot by specifying its label.");
} else {
// Do this before we read the data, so if it changes, we get a different MD5 the next time.
// Alternatively, we could calculate the MD5 of the contents, which we also read, but this
// is faster if the file comes from a file system with md5 support.
final CrosstoolProto finalProto = crosstoolProto;
String md5 = BaseEncoding.base16().lowerCase().encode(finalProto.getMd5());
CrosstoolConfig.CrosstoolRelease release;
try {
release = crosstoolReleaseCache.get(md5, new Callable<CrosstoolRelease>() {
@Override
public CrosstoolRelease call() throws Exception {
return toReleaseConfiguration(finalProto.getName(), finalProto.getContents());
}
});
} catch (ExecutionException e) {
throw new InvalidConfigurationException(e);
}
return new CrosstoolFile(finalProto.getName(), release, md5);
}
}
use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.
the class CrosstoolConfigurationLoader method selectToolchain.
/**
* Selects a crosstool toolchain corresponding to the given crosstool
* configuration options. If all of these options are null, it returns the default
* toolchain specified in the crosstool release. If only cpu is non-null, it
* returns the default toolchain for that cpu, as specified in the crosstool
* release. Otherwise, all values must be non-null, and this method
* returns the toolchain which matches all of the values.
*
* @throws NullPointerException if {@code release} is null
* @throws InvalidConfigurationException if no matching toolchain can be found, or
* if the input parameters do not obey the constraints described above
*/
public static CrosstoolConfig.CToolchain selectToolchain(CrosstoolConfig.CrosstoolRelease release, BuildOptions options, Function<String, String> cpuTransformer) throws InvalidConfigurationException {
CrosstoolConfigurationIdentifier config = CrosstoolConfigurationIdentifier.fromOptions(options);
if ((config.getCompiler() != null) || (config.getLibc() != null)) {
ArrayList<CrosstoolConfig.CToolchain> candidateToolchains = new ArrayList<>();
for (CrosstoolConfig.CToolchain toolchain : release.getToolchainList()) {
if (config.isCandidateToolchain(toolchain)) {
candidateToolchains.add(toolchain);
}
}
switch(candidateToolchains.size()) {
case 0:
{
StringBuilder message = new StringBuilder();
message.append("No toolchain found for");
message.append(config.describeFlags());
message.append(". Valid toolchains are: ");
describeToolchainList(message, release.getToolchainList());
throw new InvalidConfigurationException(message.toString());
}
case 1:
return candidateToolchains.get(0);
default:
{
StringBuilder message = new StringBuilder();
message.append("Multiple toolchains found for");
message.append(config.describeFlags());
message.append(": ");
describeToolchainList(message, candidateToolchains);
throw new InvalidConfigurationException(message.toString());
}
}
}
String selectedIdentifier = null;
// We use fake CPU values to allow cross-platform builds for other languages that use the
// C++ toolchain. Translate to the actual target architecture.
String desiredCpu = cpuTransformer.apply(config.getCpu());
for (CrosstoolConfig.DefaultCpuToolchain selector : release.getDefaultToolchainList()) {
if (selector.getCpu().equals(desiredCpu)) {
selectedIdentifier = selector.getToolchainIdentifier();
break;
}
}
if (selectedIdentifier == null) {
StringBuilder cpuBuilder = new StringBuilder();
for (CrosstoolConfig.DefaultCpuToolchain selector : release.getDefaultToolchainList()) {
cpuBuilder.append(" ").append(selector.getCpu()).append(",\n");
}
throw new InvalidConfigurationException("No toolchain found for cpu '" + desiredCpu + "'. Valid cpus are: [\n" + cpuBuilder + "]");
}
checkToolChain(selectedIdentifier, desiredCpu);
for (CrosstoolConfig.CToolchain toolchain : release.getToolchainList()) {
if (toolchain.getToolchainIdentifier().equals(selectedIdentifier)) {
return toolchain;
}
}
throw new InvalidConfigurationException("Inconsistent crosstool configuration; no toolchain " + "corresponding to '" + selectedIdentifier + "' found for cpu '" + config.getCpu() + "'");
}
use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.
the class JvmConfigurationLoader method createDefault.
@Nullable
private static Jvm createDefault(ConfigurationEnvironment lookup, String javaHome, String cpu) throws InvalidConfigurationException, LabelSyntaxException, InterruptedException {
try {
Label label = Label.parseAbsolute(javaHome);
label = RedirectChaser.followRedirects(lookup, label, "jdk");
if (label == null) {
return null;
}
Target javaHomeTarget = lookup.getTarget(label);
if (javaHomeTarget instanceof Rule) {
if (!((Rule) javaHomeTarget).getRuleClass().equals("java_runtime_suite")) {
throw new InvalidConfigurationException("Unexpected javabase rule kind '" + ((Rule) javaHomeTarget).getRuleClass() + "'");
}
return createFromRuntimeSuite(lookup, (Rule) javaHomeTarget, cpu);
}
throw new InvalidConfigurationException("No JVM target found under " + javaHome + " that would work for " + cpu);
} catch (NoSuchThingException e) {
lookup.getEventHandler().handle(Event.error(e.getMessage()));
throw new InvalidConfigurationException(e.getMessage(), e);
}
}
use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.
the class JvmConfigurationLoader method selectRuntime.
private static Label selectRuntime(Rule javaRuntimeSuite, String cpu) throws InvalidConfigurationException {
RawAttributeMapper suiteAttributes = RawAttributeMapper.of(javaRuntimeSuite);
Map<String, Label> runtimes = suiteAttributes.get("runtimes", BuildType.LABEL_DICT_UNARY);
if (runtimes.containsKey(cpu)) {
return runtimes.get(cpu);
}
if (suiteAttributes.isAttributeValueExplicitlySpecified("default")) {
return suiteAttributes.get("default", BuildType.LABEL);
}
throw new InvalidConfigurationException("No JVM target found under " + javaRuntimeSuite + " that would work for " + cpu);
}
use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.
the class InfoCommand method exec.
@Override
public ExitCode exec(final CommandEnvironment env, final OptionsProvider optionsProvider) {
final BlazeRuntime runtime = env.getRuntime();
env.getReporter().switchToAnsiAllowingHandler();
Options infoOptions = optionsProvider.getOptions(Options.class);
OutErr outErr = env.getReporter().getOutErr();
// Creating a BuildConfiguration is expensive and often unnecessary. Delay the creation until
// it is needed.
Supplier<BuildConfiguration> configurationSupplier = new Supplier<BuildConfiguration>() {
private BuildConfiguration configuration;
@Override
public BuildConfiguration get() {
if (configuration != null) {
return configuration;
}
try {
// In order to be able to answer configuration-specific queries, we need to setup the
// package path. Since info inherits all the build options, all the necessary information
// is available here.
env.setupPackageCache(optionsProvider, runtime.getDefaultsPackageContent(optionsProvider));
// TODO(bazel-team): What if there are multiple configurations? [multi-config]
configuration = env.getConfigurations(optionsProvider).getTargetConfigurations().get(0);
return configuration;
} catch (InvalidConfigurationException e) {
env.getReporter().handle(Event.error(e.getMessage()));
throw new ExitCausingRuntimeException(ExitCode.COMMAND_LINE_ERROR);
} catch (AbruptExitException e) {
throw new ExitCausingRuntimeException("unknown error: " + e.getMessage(), e.getExitCode());
} catch (InterruptedException e) {
env.getReporter().handle(Event.error("interrupted"));
throw new ExitCausingRuntimeException(ExitCode.INTERRUPTED);
}
}
};
Map<String, InfoItem> items = getInfoItemMap(env, optionsProvider);
try {
if (infoOptions.showMakeEnvironment) {
Map<String, String> makeEnv = configurationSupplier.get().getMakeEnvironment();
for (Map.Entry<String, String> entry : makeEnv.entrySet()) {
InfoItem item = new InfoItem.MakeInfoItem(entry.getKey(), entry.getValue());
items.put(item.getName(), item);
}
}
List<String> residue = optionsProvider.getResidue();
if (residue.size() > 1) {
env.getReporter().handle(Event.error("at most one key may be specified"));
return ExitCode.COMMAND_LINE_ERROR;
}
String key = residue.size() == 1 ? residue.get(0) : null;
env.getEventBus().post(new NoBuildEvent());
if (key != null) {
// print just the value for the specified key:
byte[] value;
if (items.containsKey(key)) {
value = items.get(key).get(configurationSupplier, env);
} else {
env.getReporter().handle(Event.error("unknown key: '" + key + "'"));
return ExitCode.COMMAND_LINE_ERROR;
}
try {
outErr.getOutputStream().write(value);
outErr.getOutputStream().flush();
} catch (IOException e) {
env.getReporter().handle(Event.error("Cannot write info block: " + e.getMessage()));
return ExitCode.ANALYSIS_FAILURE;
}
} else {
// print them all
// We'll need this later anyway
configurationSupplier.get();
for (InfoItem infoItem : items.values()) {
if (infoItem.isHidden()) {
continue;
}
outErr.getOutputStream().write((infoItem.getName() + ": ").getBytes(StandardCharsets.UTF_8));
outErr.getOutputStream().write(infoItem.get(configurationSupplier, env));
}
}
} catch (AbruptExitException e) {
return e.getExitCode();
} catch (ExitCausingRuntimeException e) {
return e.getExitCode();
} catch (IOException e) {
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
} catch (InterruptedException e) {
return ExitCode.INTERRUPTED;
}
return ExitCode.SUCCESS;
}
Aggregations