use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.
the class AppleSdkDiscovery method buildSdkFromPath.
private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException {
try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist"));
BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) {
NSDictionary sdkSettings;
try {
sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist);
} catch (PropertyListFormatException | ParseException | SAXException e) {
LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir);
return false;
} catch (ParserConfigurationException e) {
throw new IOException(e);
}
String name = sdkSettings.objectForKey("CanonicalName").toString();
String version = sdkSettings.objectForKey("Version").toString();
NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties");
Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name);
boolean foundToolchain = false;
if (!toolchains.isPresent()) {
NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains");
if (settingsToolchains != null) {
toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString).collect(MoreCollectors.toImmutableList()));
}
}
if (toolchains.isPresent()) {
for (String toolchainId : toolchains.get()) {
AppleToolchain toolchain = xcodeToolchains.get(toolchainId);
if (toolchain != null) {
foundToolchain = true;
sdkBuilder.addToolchains(toolchain);
} else {
LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir);
}
}
}
if (!foundToolchain && defaultToolchain.isPresent()) {
foundToolchain = true;
sdkBuilder.addToolchains(defaultToolchain.get());
}
if (!foundToolchain) {
LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir);
return false;
} else {
NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME");
ApplePlatform applePlatform = ApplePlatform.of(platformName.toString());
sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform);
ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir);
sdkBuilder.addAllArchitectures(architectures);
return true;
}
} catch (NoSuchFileException e) {
LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir);
return false;
}
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList 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 org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.
the class AppleTestDescription method getXctool.
private Optional<SourcePath> getXctool(BuildRuleParams params, BuildRuleResolver resolver) {
// can use that directly.
if (appleConfig.getXctoolZipTarget().isPresent()) {
final BuildRule xctoolZipBuildRule = resolver.getRule(appleConfig.getXctoolZipTarget().get());
BuildTarget unzipXctoolTarget = BuildTarget.builder(xctoolZipBuildRule.getBuildTarget()).addFlavors(UNZIP_XCTOOL_FLAVOR).build();
final Path outputDirectory = BuildTargets.getGenPath(params.getProjectFilesystem(), unzipXctoolTarget, "%s/unzipped");
if (!resolver.getRuleOptional(unzipXctoolTarget).isPresent()) {
BuildRuleParams unzipXctoolParams = params.withBuildTarget(unzipXctoolTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(xctoolZipBuildRule)), Suppliers.ofInstance(ImmutableSortedSet.of()));
resolver.addToIndex(new AbstractBuildRule(unzipXctoolParams) {
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(outputDirectory);
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory), new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(xctoolZipBuildRule.getSourcePathToOutput())), outputDirectory));
}
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), outputDirectory);
}
});
}
return Optional.of(new ExplicitBuildTargetSourcePath(unzipXctoolTarget, outputDirectory.resolve("bin/xctool")));
} else if (appleConfig.getXctoolPath().isPresent()) {
return Optional.of(new PathSourcePath(params.getProjectFilesystem(), appleConfig.getXctoolPath().get()));
} else {
return Optional.empty();
}
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.
the class BuiltinApplePackage method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> commands = ImmutableList.builder();
// Remove the output .ipa file if it exists already
commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile));
// Create temp folder to store the files going to be zipped
commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
Path payloadDir = temp.resolve("Payload");
commands.add(new MkdirStep(getProjectFilesystem(), payloadDir));
// Recursively copy the .app directory into the Payload folder
Path bundleOutputPath = context.getSourcePathResolver().getRelativePath(Preconditions.checkNotNull(bundle.getSourcePathToOutput()));
appendAdditionalAppleWatchSteps(commands);
commands.add(CopyStep.forDirectory(getProjectFilesystem(), bundleOutputPath, payloadDir, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
appendAdditionalSwiftSteps(context.getSourcePathResolver(), commands);
// do the zipping
commands.add(new MkdirStep(getProjectFilesystem(), pathToOutputFile.getParent()));
commands.add(new ZipStep(getProjectFilesystem(), pathToOutputFile, ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, temp));
buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
return commands.build();
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.
the class XctoolRunTestsStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
ImmutableMap<String, String> env = getEnv(context);
ProcessExecutorParams.Builder processExecutorParamsBuilder = ProcessExecutorParams.builder().addAllCommand(command).setDirectory(filesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).setEnvironment(env);
if (!testSelectorList.isEmpty()) {
try {
ImmutableList.Builder<String> xctoolFilterParamsBuilder = ImmutableList.builder();
int returnCode = listAndFilterTestsThenFormatXctoolParams(context.getProcessExecutor(), context.getConsole(), testSelectorList, // Copy the entire xctool command and environment but add a -listTestsOnly arg.
ProcessExecutorParams.builder().from(processExecutorParamsBuilder.build()).addCommand("-listTestsOnly").build(), xctoolFilterParamsBuilder);
if (returnCode != 0) {
context.getConsole().printErrorText("Failed to query tests with xctool");
return StepExecutionResult.of(returnCode);
}
ImmutableList<String> xctoolFilterParams = xctoolFilterParamsBuilder.build();
if (xctoolFilterParams.isEmpty()) {
context.getConsole().printBuildFailure(String.format(Locale.US, "No tests found matching specified filter (%s)", testSelectorList.getExplanation()));
return StepExecutionResult.SUCCESS;
}
processExecutorParamsBuilder.addAllCommand(xctoolFilterParams);
} catch (IOException e) {
context.getConsole().printErrorText("Failed to get list of tests from test bundle");
context.getConsole().printBuildFailureWithStacktrace(e);
return StepExecutionResult.ERROR;
}
}
ProcessExecutorParams processExecutorParams = processExecutorParamsBuilder.build();
// Only launch one instance of xctool at the time
final AtomicBoolean stutterLockIsNotified = new AtomicBoolean(false);
try {
LOG.debug("Running command: %s", processExecutorParams);
try {
acquireStutterLock(stutterLockIsNotified);
// Start the process.
ProcessExecutor.LaunchedProcess launchedProcess = context.getProcessExecutor().launchProcess(processExecutorParams);
int exitCode = -1;
String stderr = "Unexpected termination";
try {
ProcessStdoutReader stdoutReader = new ProcessStdoutReader(launchedProcess);
ProcessStderrReader stderrReader = new ProcessStderrReader(launchedProcess);
Thread stdoutReaderThread = new Thread(stdoutReader);
Thread stderrReaderThread = new Thread(stderrReader);
stdoutReaderThread.start();
stderrReaderThread.start();
exitCode = waitForProcessAndGetExitCode(context.getProcessExecutor(), launchedProcess, timeoutInMs);
stdoutReaderThread.join(timeoutInMs.orElse(1000L));
stderrReaderThread.join(timeoutInMs.orElse(1000L));
Optional<IOException> exception = stdoutReader.getException();
if (exception.isPresent()) {
throw exception.get();
}
stderr = stderrReader.getStdErr();
LOG.debug("Finished running command, exit code %d, stderr %s", exitCode, stderr);
} finally {
context.getProcessExecutor().destroyLaunchedProcess(launchedProcess);
context.getProcessExecutor().waitForLaunchedProcess(launchedProcess);
}
if (exitCode != 0) {
if (!stderr.isEmpty()) {
context.getConsole().printErrorText(String.format(Locale.US, "xctool failed with exit code %d: %s", exitCode, stderr));
} else {
context.getConsole().printErrorText(String.format(Locale.US, "xctool failed with exit code %d", exitCode));
}
}
return StepExecutionResult.of(exitCode);
} catch (Exception e) {
LOG.error(e, "Exception while running %s", processExecutorParams.getCommand());
MoreThrowables.propagateIfInterrupt(e);
context.getConsole().printBuildFailureWithStacktrace(e);
return StepExecutionResult.ERROR;
}
} finally {
releaseStutterLock(stutterLockIsNotified);
}
}
Aggregations