use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class AndroidInstrumentationTest method runTests.
@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
Preconditions.checkArgument(executionContext.getAdbOptions().isPresent());
if (executionContext.getAdbOptions().get().isMultiInstallModeEnabled()) {
throw new HumanReadableException("Running android instrumentation tests with multiple devices is not supported.");
}
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Path pathToTestOutput = getPathToTestOutputDirectory();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
steps.add(new ApkInstallStep(pathResolver, apk));
if (apk instanceof AndroidInstrumentationApk) {
steps.add(new ApkInstallStep(pathResolver, ((AndroidInstrumentationApk) apk).getApkUnderTest()));
}
AdbHelper adb = AdbHelper.get(executionContext, true);
IDevice device;
try {
device = adb.getSingleDevice();
} catch (InterruptedException e) {
throw new HumanReadableException("Unable to get connected device.");
}
steps.add(getInstrumentationStep(pathResolver, executionContext.getPathToAdbExecutable(), Optional.of(getProjectFilesystem().resolve(pathToTestOutput)), Optional.of(device.getSerialNumber()), Optional.empty(), getFilterString(options), Optional.empty()));
return steps.build();
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class ApplePackageDescription method getApplePackageConfig.
/**
* Get the correct package configuration based on the platform flavors of this build target.
*
* Validates that all named platforms yields the identical package config.
*
* @return If found, a package config for this target.
* @throws HumanReadableException if there are multiple possible package configs.
*/
private Optional<ApplePackageConfigAndPlatformInfo> getApplePackageConfig(BuildTarget target, Function<String, com.facebook.buck.rules.args.Arg> macroExpander) {
Set<Flavor> platformFlavors = getPlatformFlavorsOrDefault(target);
// Ensure that different platforms generate the same config.
// The value of this map is just for error reporting.
Multimap<Optional<ApplePackageConfigAndPlatformInfo>, Flavor> packageConfigs = MultimapBuilder.hashKeys().arrayListValues().build();
for (Flavor flavor : platformFlavors) {
AppleCxxPlatform platform = appleCxxPlatformFlavorDomain.getValue(flavor);
Optional<ApplePackageConfig> packageConfig = config.getPackageConfigForPlatform(platform.getAppleSdk().getApplePlatform());
packageConfigs.put(packageConfig.isPresent() ? Optional.of(ApplePackageConfigAndPlatformInfo.of(packageConfig.get(), macroExpander, platform)) : Optional.empty(), flavor);
}
if (packageConfigs.isEmpty()) {
return Optional.empty();
} else if (packageConfigs.keySet().size() == 1) {
return Iterables.getOnlyElement(packageConfigs.keySet());
} else {
throw new HumanReadableException("In target %s: Multi-architecture package has different package configs for targets: %s", target.getFullyQualifiedName(), packageConfigs.asMap().values());
}
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class AppleTest method getTestCommand.
public Pair<ImmutableList<Step>, ExternalTestRunnerTestSpec> getTestCommand(ExecutionContext context, TestRunningOptions options, SourcePathResolver pathResolver, TestRule.TestReportingCallback testReportingCallback) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
ExternalTestRunnerTestSpec.Builder externalSpec = ExternalTestRunnerTestSpec.builder().setTarget(getBuildTarget()).setLabels(getLabels()).setContacts(getContacts());
Path resolvedTestBundleDirectory = pathResolver.getAbsolutePath(Preconditions.checkNotNull(testBundle.getSourcePathToOutput()));
Path pathToTestOutput = getProjectFilesystem().resolve(getPathToTestOutputDirectory());
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
Path resolvedTestLogsPath = getProjectFilesystem().resolve(testLogsPath);
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), resolvedTestLogsPath));
Path resolvedTestOutputPath = getProjectFilesystem().resolve(testOutputPath);
Optional<Path> testHostAppPath = Optional.empty();
if (testHostApp.isPresent()) {
Path resolvedTestHostAppDirectory = pathResolver.getAbsolutePath(Preconditions.checkNotNull(testHostApp.get().getSourcePathToOutput()));
testHostAppPath = Optional.of(resolvedTestHostAppDirectory.resolve(testHostApp.get().getUnzippedOutputFilePathToBinary()));
}
if (!useXctest) {
if (!xctool.isPresent()) {
throw new HumanReadableException("Set xctool_path = /path/to/xctool or xctool_zip_target = //path/to:xctool-zip " + "in the [apple] section of .buckconfig to run this test");
}
ImmutableSet.Builder<Path> logicTestPathsBuilder = ImmutableSet.builder();
ImmutableMap.Builder<Path, Path> appTestPathsToHostAppsBuilder = ImmutableMap.builder();
if (testHostAppPath.isPresent()) {
appTestPathsToHostAppsBuilder.put(resolvedTestBundleDirectory, testHostAppPath.get());
} else {
logicTestPathsBuilder.add(resolvedTestBundleDirectory);
}
xctoolStdoutReader = Optional.of(new AppleTestXctoolStdoutReader(testReportingCallback));
Optional<String> destinationSpecifierArg;
if (!destinationSpecifier.get().isEmpty()) {
destinationSpecifierArg = Optional.of(Joiner.on(',').join(Iterables.transform(destinationSpecifier.get().entrySet(), input -> input.getKey() + "=" + input.getValue())));
} else {
destinationSpecifierArg = defaultDestinationSpecifier;
}
Optional<String> snapshotReferenceImagesPath = Optional.empty();
if (this.snapshotReferenceImagesPath.isPresent()) {
if (this.snapshotReferenceImagesPath.get().isLeft()) {
snapshotReferenceImagesPath = Optional.of(pathResolver.getAbsolutePath(this.snapshotReferenceImagesPath.get().getLeft()).toString());
} else if (this.snapshotReferenceImagesPath.get().isRight()) {
snapshotReferenceImagesPath = Optional.of(getProjectFilesystem().getPathForRelativePath(this.snapshotReferenceImagesPath.get().getRight()).toString());
}
}
XctoolRunTestsStep xctoolStep = new XctoolRunTestsStep(getProjectFilesystem(), pathResolver.getAbsolutePath(xctool.get()), options.getEnvironmentOverrides(), xctoolStutterTimeout, platformName, destinationSpecifierArg, logicTestPathsBuilder.build(), appTestPathsToHostAppsBuilder.build(), resolvedTestOutputPath, xctoolStdoutReader, xcodeDeveloperDirSupplier, options.getTestSelectorList(), context.isDebugEnabled(), Optional.of(testLogDirectoryEnvironmentVariable), Optional.of(resolvedTestLogsPath), Optional.of(testLogLevelEnvironmentVariable), Optional.of(testLogLevel), testRuleTimeoutMs, snapshotReferenceImagesPath);
steps.add(xctoolStep);
externalSpec.setType("xctool-" + (testHostApp.isPresent() ? "application" : "logic"));
externalSpec.setCommand(xctoolStep.getCommand());
externalSpec.setEnv(xctoolStep.getEnv(context));
} else {
xctestOutputReader = Optional.of(new AppleTestXctestOutputReader(testReportingCallback));
HashMap<String, String> environment = new HashMap<>();
environment.putAll(xctest.getEnvironment(pathResolver));
environment.putAll(options.getEnvironmentOverrides());
if (testHostAppPath.isPresent()) {
environment.put("XCInjectBundleInto", testHostAppPath.get().toString());
}
XctestRunTestsStep xctestStep = new XctestRunTestsStep(getProjectFilesystem(), ImmutableMap.copyOf(environment), xctest.getCommandPrefix(pathResolver), resolvedTestBundleDirectory, resolvedTestOutputPath, xctestOutputReader, xcodeDeveloperDirSupplier);
steps.add(xctestStep);
externalSpec.setType("xctest");
externalSpec.setCommand(xctestStep.getCommand());
externalSpec.setEnv(xctestStep.getEnv(context));
}
return new Pair<>(steps.build(), externalSpec.build());
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class AppleTestDescription method createTestHostInfo.
private TestHostInfo createTestHostInfo(BuildRuleParams params, BuildRuleResolver resolver, BuildTarget testHostAppBuildTarget, AppleDebugFormat debugFormat, Iterable<Flavor> additionalFlavors, ImmutableList<CxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
BuildRule rule = resolver.requireRule(BuildTarget.builder(testHostAppBuildTarget).addAllFlavors(additionalFlavors).addFlavors(debugFormat.getFlavor()).addFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor()).build());
if (!(rule instanceof AppleBundle)) {
throw new HumanReadableException("Apple test rule '%s' has test_host_app '%s' not of type '%s'.", params.getBuildTarget(), testHostAppBuildTarget, Description.getBuildRuleType(AppleBundleDescription.class));
}
AppleBundle testHostApp = (AppleBundle) rule;
SourcePath testHostAppBinarySourcePath = testHostApp.getBinaryBuildRule().getSourcePathToOutput();
ImmutableMap<BuildTarget, NativeLinkable> roots = NativeLinkables.getNativeLinkableRoots(testHostApp.getBinary().get().getDeps(), x -> true);
// Union the blacklist of all the platforms. This should give a superset for each particular
// platform, which should be acceptable as items in the blacklist thare are unmatched are simply
// ignored.
ImmutableSet.Builder<BuildTarget> blacklistBuilder = ImmutableSet.builder();
for (CxxPlatform platform : cxxPlatforms) {
blacklistBuilder.addAll(NativeLinkables.getTransitiveNativeLinkables(platform, roots.values()).keySet());
}
return TestHostInfo.of(testHostApp, testHostAppBinarySourcePath, blacklistBuilder.build());
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class NewNativeTargetProjectMutator method addResourcesFileReference.
private void addResourcesFileReference(PBXGroup targetGroup, ImmutableSet<Path> resourceFiles, ImmutableSet<Path> resourceDirs, ImmutableSet<Path> variantResourceFiles, Consumer<? super PBXFileReference> resourceCallback, Consumer<? super PBXVariantGroup> variantGroupCallback) {
if (resourceFiles.isEmpty() && resourceDirs.isEmpty() && variantResourceFiles.isEmpty()) {
return;
}
PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
for (Path path : resourceFiles) {
PBXFileReference fileReference = resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(path), Optional.empty()));
resourceCallback.accept(fileReference);
}
for (Path path : resourceDirs) {
PBXFileReference fileReference = resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(path), Optional.of("folder")));
resourceCallback.accept(fileReference);
}
Map<String, PBXVariantGroup> variantGroups = Maps.newHashMap();
for (Path variantFilePath : variantResourceFiles) {
String lprojSuffix = ".lproj";
Path variantDirectory = variantFilePath.getParent();
if (variantDirectory == null || !variantDirectory.toString().endsWith(lprojSuffix)) {
throw new HumanReadableException("Variant files have to be in a directory with name ending in '.lproj', " + "but '%s' is not.", variantFilePath);
}
String variantDirectoryName = variantDirectory.getFileName().toString();
String variantLocalization = variantDirectoryName.substring(0, variantDirectoryName.length() - lprojSuffix.length());
String variantFileName = variantFilePath.getFileName().toString();
PBXVariantGroup variantGroup = variantGroups.get(variantFileName);
if (variantGroup == null) {
variantGroup = resourcesGroup.getOrCreateChildVariantGroupByName(variantFileName);
variantGroupCallback.accept(variantGroup);
variantGroups.put(variantFileName, variantGroup);
}
SourceTreePath sourceTreePath = new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(variantFilePath), Optional.empty());
variantGroup.getOrCreateVariantFileReferenceByNameAndSourceTreePath(variantLocalization, sourceTreePath);
}
}
Aggregations