private void deserializeInputFile(DeserializationContext context, Build.SourceFile sourceFile) throws PackageDeserializationException { InputFile inputFile; try { inputFile = context.packageBuilder.createInputFile( deserializeLabel(sourceFile.getName()).getName(), EmptyLocation.INSTANCE); } catch (GeneratedLabelConflict e) { throw new PackageDeserializationException(e); } if (!sourceFile.getVisibilityLabelList().isEmpty() || sourceFile.hasLicense()) { context.packageBuilder.setVisibilityAndLicense( inputFile, PackageFactory.getVisibility(deserializeLabels(sourceFile.getVisibilityLabelList())), deserializeLicense(sourceFile.getLicense())); } }
/** * Creates a rule with the attribute values that are already parsed. * * <p><b>WARNING:</b> This assumes that the attribute values here have the right type and bypasses * some sanity checks. If they are of the wrong type, everything will come down burning. */ @SuppressWarnings("unchecked") private static Rule createRuleWithParsedAttributeValues( RuleClass ruleClass, Label label, Package.Builder pkgBuilder, Location ruleLocation, Map<String, ParsedAttributeValue> attributeValues, EventHandler eventHandler, AttributeContainer attributeContainer) throws LabelSyntaxException, InterruptedException { Rule rule = pkgBuilder.newRuleWithLabelAndAttrContainer( label, ruleClass, null, ruleLocation, attributeContainer); rule.checkValidityPredicate(eventHandler); for (Attribute attribute : rule.getRuleClassObject().getAttributes()) { ParsedAttributeValue value = attributeValues.get(attribute.getName()); if (attribute.isMandatory()) { Preconditions.checkState(value != null); } if (value == null) { continue; } rule.setAttributeValue(attribute, value.value, value.explicitlySpecified); ruleClass.checkAllowedValues(rule, attribute, eventHandler); if (attribute.getName().equals("visibility")) { // TODO(bazel-team): Verify that this cast works rule.setVisibility(PackageFactory.getVisibility((List<Label>) value.value)); } } rule.populateOutputFiles(eventHandler, pkgBuilder); Preconditions.checkState(!rule.containsErrors()); return rule; }
/** * Deserialize a package from its representation as a protocol message. The inverse of {@link * PackageSerializer#serialize}. * * @throws IOException * @throws InterruptedException */ private void deserializeInternal( Build.Package packagePb, StoredEventHandler eventHandler, Package.Builder builder, InputStream in) throws PackageDeserializationException, IOException, InterruptedException { Path buildFile = packageDeserializationEnvironment.getPath(packagePb.getBuildFilePath()); Preconditions.checkNotNull(buildFile); DeserializationContext context = new DeserializationContext(builder); builder.setFilename(buildFile); if (packagePb.hasDefaultVisibilitySet() && packagePb.getDefaultVisibilitySet()) { builder.setDefaultVisibility( PackageFactory.getVisibility( deserializeLabels(packagePb.getDefaultVisibilityLabelList()))); } // It's important to do this after setting the default visibility, since that implicitly sets // this bit to true builder.setDefaultVisibilitySet(packagePb.getDefaultVisibilitySet()); if (packagePb.hasDefaultTestonly()) { builder.setDefaultTestonly(packagePb.getDefaultTestonly()); } if (packagePb.hasDefaultDeprecation()) { builder.setDefaultDeprecation(packagePb.getDefaultDeprecation()); } builder.setDefaultCopts(packagePb.getDefaultCoptList()); if (packagePb.hasDefaultHdrsCheck()) { builder.setDefaultHdrsCheck(packagePb.getDefaultHdrsCheck()); } if (packagePb.hasDefaultLicense()) { builder.setDefaultLicense(deserializeLicense(packagePb.getDefaultLicense())); } builder.setDefaultDistribs(deserializeDistribs(packagePb.getDefaultDistribList())); for (String subinclude : packagePb.getSubincludeLabelList()) { Label label = deserializeLabel(subinclude); builder.addSubinclude(label, null); } ImmutableList.Builder<Label> skylarkFileDependencies = ImmutableList.builder(); for (String skylarkFile : packagePb.getSkylarkLabelList()) { skylarkFileDependencies.add(deserializeLabel(skylarkFile)); } builder.setSkylarkFileDependencies(skylarkFileDependencies.build()); MakeEnvironment.Builder makeEnvBuilder = new MakeEnvironment.Builder(); for (Build.MakeVar makeVar : packagePb.getMakeVariableList()) { for (Build.MakeVarBinding binding : makeVar.getBindingList()) { makeEnvBuilder.update( makeVar.getName(), binding.getValue(), binding.getPlatformSetRegexp()); } } builder.setMakeEnv(makeEnvBuilder); for (Build.Event event : packagePb.getEventList()) { deserializeEvent(eventHandler, event); } if (packagePb.hasContainsErrors() && packagePb.getContainsErrors()) { builder.setContainsErrors(); } builder.setWorkspaceName(packagePb.getWorkspaceName()); deserializeTargets(in, context); }