Skip to content

Commit

Permalink
Improves the error message for invalid cpu (--cpu or --fat_apk_cpu).
Browse files Browse the repository at this point in the history
Before:

ERROR: No toolchain found for cpu 'x84'.

After:

ERROR: No toolchain found for cpu 'x84'. Valid cpus are: [
  armeabi,
  armeabi-v7a,
  armeabi-v7a-hard,
  armeabi-thumb,
  armeabi-v7a-thumb,
  armeabi-v7a-hard-thumb,
  arm64-v8a,
  mips,
  mips64,
  x86,
  x86_64,
].

--
MOS_MIGRATED_REVID=105324190
  • Loading branch information
ahumesky authored and fweikert committed Oct 13, 2015
1 parent 4bf8880 commit 6cfa830
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,24 @@ public static CrosstoolConfig.CToolchain selectToolchain(
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() + "'");
}
Expand All @@ -369,14 +381,11 @@ private static void describeToolchainList(StringBuilder message,
* spaces, letters, digits or underscores (i.e. matches the following regular expression:
* "[a-zA-Z_][\.\- \w]*").
*
* @throws InvalidConfigurationException if selectedIdentifier is null or does not match the
* @throws InvalidConfigurationException if selectedIdentifier does not match the
* aforementioned regular expression.
*/
private static void checkToolChain(String selectedIdentifier, String cpu)
throws InvalidConfigurationException {
if (selectedIdentifier == null) {
throw new InvalidConfigurationException("No toolchain found for cpu '" + cpu + "'");
}
// If you update this regex, please do so in the javadoc comment too, and also in the
// crosstool_config.proto file.
String rx = "[a-zA-Z_][\\.\\- \\w]*";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2006-2015 Google Inc. All rights reserved.
// 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.
Expand Down Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.common.options.Options;

import java.util.Map;
import java.util.regex.Pattern;

/**
* Tests for {@link BuildConfiguration}.
Expand Down Expand Up @@ -117,17 +118,18 @@ public void testCaching() throws Exception {
assertEquals(a.cacheKey(), b.cacheKey());
}

private void checkInvalidCpuError(String cpuOption, String expectedMessage) throws Exception {
private void checkInvalidCpuError(String cpuOption, Pattern messageRegex) throws Exception {
try {
create("--" + cpuOption + "=bogus");
fail();
} catch (InvalidConfigurationException e) {
assertThat(e).hasMessage(expectedMessage);
assertThat(e.getMessage()).matches(messageRegex);
}
}

public void testInvalidCpu() throws Exception {
checkInvalidCpuError("cpu", "No toolchain found for cpu 'bogus'");
checkInvalidCpuError("cpu", Pattern.compile(
"No toolchain found for cpu 'bogus'. Valid cpus are: \\[\n( [\\w-]+,\n)+]"));
}

public void testConfigurationsHaveUniqueOutputDirectories() throws Exception {
Expand Down

0 comments on commit 6cfa830

Please sign in to comment.