public static HaskellPackageRule from( BuildTarget target, BuildRuleParams baseParams, final SourcePathResolver resolver, final Tool ghcPkg, HaskellPackageInfo packageInfo, final ImmutableSortedMap<String, HaskellPackage> depPackages, ImmutableSortedSet<String> modules, final ImmutableSortedSet<SourcePath> libraries, final ImmutableSortedSet<SourcePath> interfaces) { return new HaskellPackageRule( baseParams.copyWithChanges( target, Suppliers.memoize( () -> ImmutableSortedSet.<BuildRule>naturalOrder() .addAll(ghcPkg.getDeps(resolver)) .addAll( FluentIterable.from(depPackages.values()) .transformAndConcat(HaskellPackage.getDepsFunction(resolver))) .addAll( resolver.filterBuildRuleInputs(Iterables.concat(libraries, interfaces))) .build()), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, ghcPkg, packageInfo, depPackages, modules, libraries, interfaces); }
private void addResourceProcessingSteps( Path sourcePath, Path destinationPath, ImmutableList.Builder<Step> stepsBuilder) { String sourcePathExtension = Files.getFileExtension(sourcePath.toString()).toLowerCase(Locale.US); switch (sourcePathExtension) { case "plist": case "stringsdict": LOG.debug("Converting plist %s to binary plist %s", sourcePath, destinationPath); stepsBuilder.add( new PlistProcessStep( sourcePath, destinationPath, ImmutableMap.<String, NSObject>of(), ImmutableMap.<String, NSObject>of(), PlistProcessStep.OutputFormat.BINARY)); break; case "xib": String compiledNibFilename = Files.getNameWithoutExtension(destinationPath.toString()) + ".nib"; Path compiledNibPath = destinationPath.getParent().resolve(compiledNibFilename); LOG.debug("Compiling XIB %s to NIB %s", sourcePath, destinationPath); stepsBuilder.add( new IbtoolStep(ibtool.getCommandPrefix(getResolver()), sourcePath, compiledNibPath)); break; default: stepsBuilder.add(CopyStep.forFile(sourcePath, destinationPath)); break; } }
public CxxBoostTest( BuildRuleParams params, SourcePathResolver resolver, CxxLink binary, Tool executable, Supplier<ImmutableMap<String, String>> env, Supplier<ImmutableList<String>> args, Supplier<ImmutableSortedSet<BuildRule>> additionalDeps, ImmutableSet<Label> labels, ImmutableSet<String> contacts, ImmutableSet<BuildRule> sourceUnderTest, boolean runTestSeparately, Optional<Long> testRuleTimeoutMs) { super( params, resolver, executable.getEnvironment(resolver), env, args, additionalDeps, labels, contacts, sourceUnderTest, runTestSeparately, testRuleTimeoutMs); this.binary = binary; this.executable = executable; }
// The C++ test rules just wrap a test binary produced by another rule, so make sure that's // always available to run the test. @Override public ImmutableSortedSet<BuildRule> getRuntimeDeps() { return ImmutableSortedSet.<BuildRule>naturalOrder() .addAll(super.getRuntimeDeps()) .addAll(executable.getDeps(getResolver())) .build(); }
@Override public ImmutableList<Step> getBuildSteps( BuildContext context, BuildableContext buildableContext) { Path outputDir = getPathToOutput(); String shortName = getBuildTarget().getShortName(); buildableContext.recordArtifact(objectOutputPath(getBuildTarget(), getProjectFilesystem())); buildableContext.recordArtifact(headerOutputPath(getBuildTarget(), getProjectFilesystem())); ImmutableList.Builder<Step> commands = ImmutableList.builder(); ProjectFilesystem projectFilesystem = getProjectFilesystem(); commands.add(new MakeCleanDirectoryStep(projectFilesystem, outputDir)); commands.add( new HalideCompilerStep( projectFilesystem.getRootPath(), halideCompiler.getEnvironment(getResolver()), halideCompiler.getCommandPrefix(getResolver()), outputDir, shortName, targetPlatform)); return commands.build(); }
@Override protected ImmutableList<String> getShellCommand(ExecutionContext context, Path output) { return ImmutableList.<String>builder() .addAll(executable.getCommandPrefix(getResolver())) .add("--log_format=hrf") .add("--log_level=test_suite") .add("--report_format=xml") .add("--report_level=detailed") .add("--result_code=no") .add("--report_sink=" + getProjectFilesystem().resolve(output)) .build(); }
@Override public ExternalTestRunnerTestSpec getExternalTestRunnerSpec( ExecutionContext executionContext, TestRunningOptions testRunningOptions) { return ExternalTestRunnerTestSpec.builder() .setTarget(getBuildTarget()) .setType("boost") .addAllCommand(executable.getCommandPrefix(getResolver())) .addAllCommand(getArgs().get()) .putAllEnv(getEnv().get()) .addAllLabels(getLabels()) .addAllContacts(getContacts()) .build(); }
@Override public ImmutableList<Step> getBuildSteps( BuildContext context, BuildableContext buildableContext) { String shortName = getBuildTarget().getShortName(); buildableContext.recordArtifact(outputDir.resolve(shortName + ".h")); buildableContext.recordArtifact(outputDir.resolve(shortName + ".o")); ImmutableList.Builder<Step> commands = ImmutableList.builder(); commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir)); commands.add( new HalideCompilerStep( getProjectFilesystem().getRootPath(), halideCompiler.getCommandPrefix(getResolver()), outputDir, shortName)); return commands.build(); }
@Override public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException { ImmutableList<String> lldbCommandPrefix = lldb.getCommandPrefix(resolver); ProcessExecutorParams params = ProcessExecutorParams.builder() .addCommand(lldbCommandPrefix.toArray(new String[lldbCommandPrefix.size()])) .build(); return StepExecutionResult.of( context .getProcessExecutor() .launchAndExecute( params, ImmutableSet.<ProcessExecutor.Option>of(), Optional.of( String.format( "target create %s\ntarget symbols add %s", binaryBuildRule.getPathToOutput(), location)), Optional.<Long>absent(), Optional.<Function<Process, Void>>absent()) .getExitCode()); }
public DepsBuilder add(Tool tool) { builder.addAll(tool.getDeps(getPathResolver())); return this; }
public Pair<ImmutableList<Step>, ExternalTestRunnerTestSpec> getTestCommand( ExecutionContext context, TestRunningOptions options, TestRule.TestReportingCallback testReportingCallback) { ImmutableList.Builder<Step> steps = ImmutableList.builder(); ExternalTestRunnerTestSpec.Builder externalSpec = ExternalTestRunnerTestSpec.builder() .setTarget(getBuildTarget()) .setLabels(getLabels()) .setContacts(getContacts()); Path resolvedTestBundleDirectory = getProjectFilesystem().resolve(Preconditions.checkNotNull(testBundle.getPathToOutput())); 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 = getProjectFilesystem() .resolve(Preconditions.checkNotNull(testHostApp.get().getPathToOutput())); 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; } XctoolRunTestsStep xctoolStep = new XctoolRunTestsStep( getProjectFilesystem(), getResolver().getAbsolutePath(xctool.get()), options.getEnvironmentOverrides(), xctoolStutterTimeout, platformName, destinationSpecifierArg, logicTestPathsBuilder.build(), appTestPathsToHostAppsBuilder.build(), resolvedTestOutputPath, xctoolStdoutReader, xcodeDeveloperDirSupplier, options.getTestSelectorList(), Optional.of(testLogDirectoryEnvironmentVariable), Optional.of(resolvedTestLogsPath), Optional.of(testLogLevelEnvironmentVariable), Optional.of(testLogLevel), testRuleTimeoutMs); 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(getResolver())); environment.putAll(options.getEnvironmentOverrides()); if (testHostAppPath.isPresent()) { environment.put("XCInjectBundleInto", testHostAppPath.get().toString()); } XctestRunTestsStep xctestStep = new XctestRunTestsStep( getProjectFilesystem(), ImmutableMap.copyOf(environment), xctest.getCommandPrefix(getResolver()), 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()); }
public Pair<ImmutableList<Step>, ExternalTestRunnerTestSpec> getTestCommand( ExecutionContext context, TestRunningOptions options, TestRule.TestReportingCallback testReportingCallback) { ImmutableList.Builder<Step> steps = ImmutableList.builder(); ExternalTestRunnerTestSpec.Builder externalSpec = ExternalTestRunnerTestSpec.builder() .setTarget(getBuildTarget()) .setLabels(getLabels()) .setContacts(getContacts()); Path resolvedTestBundleDirectory = getProjectFilesystem().resolve(Preconditions.checkNotNull(testBundle.getPathToOutput())); Path pathToTestOutput = getProjectFilesystem().resolve(getPathToTestOutputDirectory()); steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput)); Path resolvedTestOutputPath = getProjectFilesystem().resolve(testOutputPath); Optional<Path> testHostAppPath = Optional.absent(); if (testHostApp.isPresent()) { Path resolvedTestHostAppDirectory = getProjectFilesystem() .resolve(Preconditions.checkNotNull(testHostApp.get().getPathToOutput())); 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(), new Function<Map.Entry<String, String>, String>() { @Override public String apply(Map.Entry<String, String> input) { return input.getKey() + "=" + input.getValue(); } }))); } else { destinationSpecifierArg = defaultDestinationSpecifier; } XctoolRunTestsStep xctoolStep = new XctoolRunTestsStep( getProjectFilesystem(), getResolver().getAbsolutePath(xctool.get()), xctoolStutterTimeout, platformName, destinationSpecifierArg, logicTestPathsBuilder.build(), appTestPathsToHostAppsBuilder.build(), resolvedTestOutputPath, xctoolStdoutReader, xcodeDeveloperDirSupplier, options.getTestSelectorList()); steps.add(xctoolStep); externalSpec.setType("xctool-" + (testHostApp.isPresent() ? "application" : "logic")); externalSpec.setCommand(xctoolStep.getCommand()); externalSpec.setEnv(xctoolStep.getEnv(context)); } else { Tool testRunningTool; if (testBundleExtension.equals("xctest")) { testRunningTool = xctest; } else if (otest.isPresent()) { testRunningTool = otest.get(); } else { throw new HumanReadableException( "Cannot run non-xctest bundle type %s (otest not present)", testBundleExtension); } XctestRunTestsStep xctestStep = new XctestRunTestsStep( getProjectFilesystem(), testRunningTool.getCommandPrefix(getResolver()), (testBundleExtension.equals("xctest") ? "-XCTest" : "-SenTest"), resolvedTestBundleDirectory, resolvedTestOutputPath, xcodeDeveloperDirSupplier); steps.add(xctestStep); externalSpec.setType("xctest"); externalSpec.setCommand(xctestStep.getCommand()); externalSpec.setEnv(xctestStep.getEnv(context)); } return new Pair<>(steps.build(), externalSpec.build()); }
@Override public ImmutableList<Step> getBuildSteps( BuildContext context, BuildableContext buildableContext) { ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder(); Path metadataPath = getMetadataPath(); Path infoPlistInputPath = getResolver().getPath(infoPlist); Path infoPlistSubstitutionTempPath = BuildTargets.getScratchPath(getBuildTarget(), "%s.plist"); Path infoPlistOutputPath = metadataPath.resolve("Info.plist"); stepsBuilder.add( new MakeCleanDirectoryStep(bundleRoot), new MkdirStep(metadataPath), // TODO(user): This is only appropriate for .app bundles. new WriteFileStep("APPLWRUN", metadataPath.resolve("PkgInfo"), /* executable */ false), new FindAndReplaceStep( infoPlistInputPath, infoPlistSubstitutionTempPath, InfoPlistSubstitution.createVariableExpansionFunction( withDefaults( infoPlistSubstitutions, ImmutableMap.of( "EXECUTABLE_NAME", binaryName, "PRODUCT_NAME", binaryName)))), new PlistProcessStep( infoPlistSubstitutionTempPath, infoPlistOutputPath, getInfoPlistAdditionalKeys(platformName, sdkName), getInfoPlistOverrideKeys(platformName), PlistProcessStep.OutputFormat.BINARY)); if (binary.isPresent() && binary.get().getPathToOutput() != null) { stepsBuilder.add(new MkdirStep(bundleRoot.resolve(this.destinations.getExecutablesPath()))); Path bundleBinaryPath = bundleRoot.resolve(binaryPath); stepsBuilder.add(CopyStep.forFile(binary.get().getPathToOutput(), bundleBinaryPath)); stepsBuilder.add( new DsymStep( dsymutil.getCommandPrefix(getResolver()), bundleBinaryPath, bundleBinaryPath.resolveSibling( bundleBinaryPath.getFileName().toString() + ".dSYM"))); stepsBuilder.add( new DefaultShellStep( ImmutableList.<String>builder() .addAll(strip.getCommandPrefix(getResolver())) .add("-S") .add(getProjectFilesystem().resolve(bundleBinaryPath).toString()) .build())); } Path bundleDestinationPath = bundleRoot.resolve(this.destinations.getResourcesPath()); for (SourcePath dir : resourceDirs) { stepsBuilder.add(new MkdirStep(bundleDestinationPath)); stepsBuilder.add( CopyStep.forDirectory( getResolver().getPath(dir), bundleDestinationPath, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS)); } for (SourcePath dir : dirsContainingResourceDirs) { stepsBuilder.add(new MkdirStep(bundleDestinationPath)); stepsBuilder.add( CopyStep.forDirectory( getResolver().getPath(dir), bundleDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY)); } for (SourcePath file : resourceFiles) { stepsBuilder.add(new MkdirStep(bundleDestinationPath)); Path resolvedFilePath = getResolver().getPath(file); Path destinationPath = bundleDestinationPath.resolve(resolvedFilePath.getFileName()); addResourceProcessingSteps(resolvedFilePath, destinationPath, stepsBuilder); } addStepsToCopyExtensionBundlesDependencies(stepsBuilder); if (resourceVariantFiles.isPresent()) { for (SourcePath variantSourcePath : resourceVariantFiles.get()) { Path variantFilePath = getResolver().getPath(variantSourcePath); Path variantDirectory = variantFilePath.getParent(); if (variantDirectory == null || !variantDirectory.toString().endsWith(".lproj")) { throw new HumanReadableException( "Variant files have to be in a directory with name ending in '.lproj', " + "but '%s' is not.", variantFilePath); } Path bundleVariantDestinationPath = bundleDestinationPath.resolve(variantDirectory.getFileName()); stepsBuilder.add(new MkdirStep(bundleVariantDestinationPath)); Path destinationPath = bundleVariantDestinationPath.resolve(variantFilePath.getFileName()); addResourceProcessingSteps(variantFilePath, destinationPath, stepsBuilder); } } if (assetCatalog.isPresent()) { Path bundleDir = assetCatalog.get().getOutputDir(); stepsBuilder.add( CopyStep.forDirectory(bundleDir, bundleRoot, CopyStep.DirectoryMode.CONTENTS_ONLY)); } // Copy the .mobileprovision file if the platform requires it. if (provisioningProfiles.isPresent()) { Optional<Path> entitlementsPlist = Optional.absent(); final String srcRoot = context.getProjectRoot().resolve(getBuildTarget().getBasePath()).toString(); Optional<String> entitlementsPlistString = InfoPlistSubstitution.getVariableExpansionForPlatform( CODE_SIGN_ENTITLEMENTS, platformName, withDefaults( infoPlistSubstitutions, ImmutableMap.of( "SOURCE_ROOT", srcRoot, "SRCROOT", srcRoot))); if (entitlementsPlistString.isPresent()) { entitlementsPlist = Optional.of(Paths.get(entitlementsPlistString.get())); } final Path signingEntitlementsTempPath = BuildTargets.getScratchPath(getBuildTarget(), "%s.xcent"); stepsBuilder.add( new ProvisioningProfileCopyStep( infoPlistOutputPath, Optional.<String>absent(), // Provisioning profile UUID -- find automatically. entitlementsPlist, provisioningProfiles.get(), bundleDestinationPath.resolve("embedded.mobileprovision"), signingEntitlementsTempPath)); stepsBuilder.add( new CodeSignStep( bundleDestinationPath, signingEntitlementsTempPath, codeSignIdentity.get().getHash())); } // Ensure the bundle directory is archived so we can fetch it later. buildableContext.recordArtifact(getPathToOutput()); return stepsBuilder.build(); }