use of com.google.devtools.build.lib.analysis.PrerequisiteArtifacts in project bazel by bazelbuild.
the class CompilationSupport method registerHeaderScanningActions.
/**
* Creates and registers ObjcHeaderScanning {@link SpawnAction}. Groups all the actions by their
* compilation command line arguments and creates a ObjcHeaderScanning action for each unique one.
*/
protected void registerHeaderScanningActions(ImmutableList<ObjcHeaderThinningInfo> headerThinningInfo, ObjcProvider objcProvider, CompilationArtifacts compilationArtifacts) {
if (headerThinningInfo.isEmpty()) {
return;
}
FilesToRunProvider headerScannerTool = getHeaderThinningToolExecutable();
PrerequisiteArtifacts appleSdks = ruleContext.getPrerequisiteArtifacts(ObjcRuleClasses.APPLE_SDK_ATTRIBUTE, Mode.TARGET);
ListMultimap<ImmutableList<String>, ObjcHeaderThinningInfo> objcHeaderThinningInfoByCommandLine = groupActionsByCommandLine(headerThinningInfo);
// Register a header scanning spawn action for each unique set of command line arguments
for (ImmutableList<String> args : objcHeaderThinningInfoByCommandLine.keySet()) {
SpawnAction.Builder builder = new SpawnAction.Builder().setMnemonic("ObjcHeaderScanning").setExecutable(headerScannerTool).addInputs(appleSdks.list());
CustomCommandLine.Builder cmdLine = CustomCommandLine.builder().add("--arch").add(appleConfiguration.getSingleArchitecture().toLowerCase()).add("--platform").add(appleConfiguration.getSingleArchPlatform().getLowerCaseNameInPlist()).add("--sdk_version").add(appleConfiguration.getSdkVersionForPlatform(appleConfiguration.getSingleArchPlatform()).toStringWithMinimumComponents(2)).add("--xcode_version").add(appleConfiguration.getXcodeVersion().toStringWithMinimumComponents(2)).add("--");
for (ObjcHeaderThinningInfo info : objcHeaderThinningInfoByCommandLine.get(args)) {
cmdLine.addJoinPaths(":", Lists.newArrayList(info.sourceFile.getExecPath(), info.headersListFile.getExecPath()));
builder.addInput(info.sourceFile).addOutput(info.headersListFile);
}
ruleContext.registerAction(builder.setCommandLine(cmdLine.add("--").add(args).build()).addInputs(compilationArtifacts.getPrivateHdrs()).addTransitiveInputs(attributes.hdrs()).addTransitiveInputs(objcProvider.get(ObjcProvider.HEADER)).addInputs(compilationArtifacts.getPchFile().asSet()).addTransitiveInputs(objcProvider.get(ObjcProvider.STATIC_FRAMEWORK_FILE)).addTransitiveInputs(objcProvider.get(ObjcProvider.DYNAMIC_FRAMEWORK_FILE)).build(ruleContext));
}
}
use of com.google.devtools.build.lib.analysis.PrerequisiteArtifacts in project bazel by bazelbuild.
the class ProtoAttributes method validate.
/**
* Validates the proto attributes for this target.
*
* <ul>
* <li>Validates that there are protos specified to be compiled.
* <li>Validates that, when enabling the open source protobuf library, the options for the PB2 are
* not specified also.
* <li>Validates that, when enabling the open source protobuf library, the rule specifies at least
* one portable proto filter file.
* </ul>
*/
public void validate() throws RuleErrorException {
PrerequisiteArtifacts prerequisiteArtifacts = ruleContext.getPrerequisiteArtifacts("deps", Mode.TARGET);
ImmutableList<Artifact> protos = prerequisiteArtifacts.filter(FileType.of(".proto")).list();
if (ruleContext.attributes().isAttributeValueExplicitlySpecified(ObjcProtoLibraryRule.PORTABLE_PROTO_FILTERS_ATTR)) {
if (!protos.isEmpty()) {
ruleContext.throwWithAttributeError("deps", FILES_NOT_ALLOWED_ERROR);
}
if (getProtoFiles().isEmpty() && !hasObjcProtoLibraryDependencies()) {
ruleContext.throwWithRuleError(NO_PROTOS_ERROR);
}
if (getPortableProtoFilters().isEmpty()) {
ruleContext.throwWithRuleError(PORTABLE_PROTO_FILTERS_EMPTY_ERROR);
}
if (usesObjcHeaderNames() || needsPerProtoIncludes() || getOptionsFile().isPresent()) {
ruleContext.throwWithRuleError(PORTABLE_PROTO_FILTERS_NOT_EXCLUSIVE_ERROR);
}
if (hasPB2Dependencies()) {
ruleContext.throwWithRuleError(PROTOCOL_BUFFERS2_IN_PROTOBUF_DEPS_ERROR);
}
} else {
if (!protos.isEmpty()) {
ruleContext.attributeWarning("deps", FILES_DEPRECATED_WARNING);
}
if (getProtoFiles().isEmpty()) {
ruleContext.throwWithRuleError(NO_PROTOS_ERROR);
}
if (!usesObjcHeaderNames()) {
ruleContext.ruleWarning("As part of the migration process, it is recommended to enable " + "use_objc_header_names. Please refer to b/29368416 for more information.");
}
if (hasObjcProtoLibraryDependencies()) {
ruleContext.throwWithRuleError(OBJC_PROTO_LIB_DEP_IN_PROTOCOL_BUFFERS2_DEPS_ERROR);
}
}
}
Aggregations