use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class HalideLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = params.getBuildTarget();
ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(target.getFlavors());
CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
if (flavors.contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR)) {
ImmutableMap.Builder<Path, SourcePath> headersBuilder = ImmutableMap.builder();
BuildTarget compileTarget = resolver.requireRule(target.withFlavors(HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor())).getBuildTarget();
Path outputPath = HalideCompile.headerOutputPath(compileTarget, params.getProjectFilesystem(), args.functionName);
headersBuilder.put(outputPath.getFileName(), new ExplicitBuildTargetSourcePath(compileTarget, outputPath));
return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, cxxPlatform, headersBuilder.build(), HeaderVisibility.PUBLIC, true);
} else if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, hostCxxPlatform, params);
} else if (flavors.contains(HALIDE_COMPILER_FLAVOR)) {
// We always want to build the halide "compiler" for the host platform, so
// we use the host flavor here, regardless of the flavors on the build
// target.
CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
final ImmutableSortedSet<BuildTarget> compilerDeps = args.compilerDeps;
return createHalideCompiler(params.withAppendedFlavor(HALIDE_COMPILER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(resolver.getAllRules(compilerDeps)), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, pathResolver, ruleFinder, hostCxxPlatform, args.srcs, args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, args.linkerFlags, args.platformLinkerFlags, args.includeDirs);
} else if (flavors.contains(CxxDescriptionEnhancer.STATIC_FLAVOR) || flavors.contains(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR)) {
// See: https://github.com/halide/Halide/blob/e3c301f3/src/LLVM_Output.cpp#L152
return createHalideStaticLibrary(params, resolver, ruleFinder, cxxPlatform, args);
} else if (flavors.contains(CxxDescriptionEnhancer.SHARED_FLAVOR)) {
throw new HumanReadableException("halide_library '%s' does not support shared libraries as output", params.getBuildTarget());
} else if (flavors.contains(HALIDE_COMPILE_FLAVOR)) {
return createHalideCompile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, cxxPlatform, Optional.of(args.compilerInvocationFlags), args.functionName);
}
return new HalideLibrary(params, resolver, args.supportedPlatformsRegex);
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class DownloadStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
BuckEventBus eventBus = context.getBuckEventBus();
try {
Path resolved = filesystem.resolve(output);
boolean success = downloader.fetch(eventBus, url, resolved);
if (!success) {
return StepExecutionResult.of(reportFailedDownload(eventBus));
}
HashCode readHash = Files.asByteSource(resolved.toFile()).hash(Hashing.sha1());
if (!sha1.equals(readHash)) {
eventBus.post(ConsoleEvent.severe("Unable to download %s (hashes do not match. Expected %s, saw %s)", url, sha1, readHash));
return StepExecutionResult.of(-1);
}
} catch (IOException e) {
return StepExecutionResult.of(reportFailedDownload(eventBus));
} catch (HumanReadableException e) {
eventBus.post(ConsoleEvent.severe(e.getHumanReadableErrorMessage(), e));
return StepExecutionResult.of(-1);
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class MavenUrlDecoder method toHttpUrl.
public static URI toHttpUrl(Optional<String> mavenRepo, URI uri) {
Preconditions.checkArgument("mvn".equals(uri.getScheme()), "URI must start with mvn: " + uri);
Preconditions.checkArgument(mavenRepo.isPresent(), "You must specify the maven repo in the \"download->maven_repo\" section of your " + ".buckconfig");
String repo = mavenRepo.get();
if (!repo.endsWith("/")) {
repo += "/";
}
Matcher matcher = URL_PATTERN.matcher(uri.getSchemeSpecificPart());
if (!matcher.matches()) {
throw new HumanReadableException("Unable to parse: " + uri);
}
String host = matcher.group("host");
if (Strings.isNullOrEmpty(host)) {
host = repo;
}
String group = matcher.group("group").replace('.', '/');
String artifactId = matcher.group("id");
String type = matcher.group("type");
String version = matcher.group("version");
Optional<String> classifier = Optional.ofNullable(matcher.group("classifier"));
if (!host.endsWith("/")) {
host += "/";
}
try {
String plainUri = String.format("%s%s/%s/%s/%s", host, group, artifactId, version, fileNameFor(artifactId, version, type, classifier));
URI generated = new URI(plainUri);
if ("https".equals(generated.getScheme()) || "http".equals(generated.getScheme())) {
return generated;
}
throw new HumanReadableException("Can only download maven artifacts over HTTP or HTTPS: %s", generated);
} catch (URISyntaxException e) {
throw new HumanReadableException("Unable to parse URL: " + uri);
}
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class RemoteFileDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
HashCode sha1;
try {
sha1 = HashCode.fromString(args.sha1);
} catch (IllegalArgumentException e) {
throw new HumanReadableException(e, "%s when parsing sha1 of %s", e.getMessage(), params.getBuildTarget().getUnflavoredBuildTarget().getFullyQualifiedName());
}
String out = args.out.orElse(params.getBuildTarget().getShortNameAndFlavorPostfix());
RemoteFile.Type type = args.type.orElse(RemoteFile.Type.DATA);
if (type == RemoteFile.Type.EXECUTABLE) {
return new RemoteFileBinary(params, downloader, args.url, sha1, out, type);
}
return new RemoteFile(params, downloader, args.url, sha1, out, type);
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class DotnetFramework method resolveFramework.
// TODO(t8390117): Use official Win32 APIs to find the framework
@VisibleForTesting
static DotnetFramework resolveFramework(FileSystem osFilesystem, ImmutableMap<String, String> env, FrameworkVersion version) {
Path programFiles = findProgramFiles(osFilesystem, env);
Path baseDir = programFiles.resolve("Reference Assemblies").resolve("Microsoft").resolve("Framework");
Path frameworkDir;
switch(version) {
case NET35:
frameworkDir = baseDir.resolve("v3.5");
break;
case NET40:
// fall through
case NET45:
// fall through
case NET46:
frameworkDir = baseDir.resolve(".NETFramework").resolve(version.getDirName());
break;
// Which we should never reach
default:
throw new HumanReadableException("Unknown .net framework version: %s", version);
}
if (!Files.exists(frameworkDir)) {
throw new HumanReadableException("Resolved framework dir for %s does not exist: %s", version, frameworkDir);
}
if (!Files.isDirectory(frameworkDir)) {
throw new HumanReadableException("Resolved framework directory is not a directory: %s", frameworkDir);
}
return new DotnetFramework(version, frameworkDir);
}
Aggregations