Skip to content

Commit

Permalink
Description redacted.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=137669164
  • Loading branch information
Googler authored and laszlocsomor committed Oct 31, 2016
1 parent db7b04c commit 9b61b0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

/**
* Wrapper class for managing dependencies on top of
Expand Down Expand Up @@ -81,6 +82,7 @@ public boolean isEnabled() {
Set<String> requiredClasspath;
private final FixMessage fixMessage;
private final Set<String> exemptGenerators;
private final Set<String> packages;

DependencyModule(
StrictJavaDeps strictJavaDeps,
Expand All @@ -106,6 +108,7 @@ public boolean isEnabled() {
this.usedClasspath = new HashSet<>();
this.fixMessage = fixMessage;
this.exemptGenerators = exemptGenerators;
this.packages = new TreeSet<>();
}

/**
Expand All @@ -118,9 +121,8 @@ public BlazeJavaCompilerPlugin getPlugin() {
/**
* Writes dependency information to the deps file in proto format, if specified.
*
* This is a replacement for {@link #emitUsedClasspath} above, which only outputs the used
* classpath. We collect more precise dependency information to allow Blaze to analyze both
* strict and unused dependencies based on the new deps.proto.
* <p>We collect precise dependency information to allow Blaze to analyze both strict and unused
* dependencies, as well as packages contained by the output jar.
*/
public void emitDependencyInformation(String classpath, boolean successful) throws IOException {
if (outputDepsProtoFile == null) {
Expand All @@ -142,6 +144,7 @@ Deps.Dependencies buildDependenciesProto(String classpath, boolean successful) {
deps.setRuleLabel(targetLabel);
}
deps.setSuccess(successful);
deps.addAllContainedPackage(packages);
// Filter using the original classpath, to preserve ordering.
for (String entry : classpath.split(":")) {
if (explicitDependenciesMap.containsKey(entry)) {
Expand Down Expand Up @@ -197,6 +200,11 @@ public Map<String, Deps.Dependency> getImplicitDependenciesMap() {
return implicitDependenciesMap;
}

/** Adds a package to the set of packages built by this target. */
public boolean addPackage(String packge) {
return packages.add(packge);
}

/**
* Returns the type (rule kind) of the originating target.
*/
Expand Down
Expand Up @@ -73,7 +73,6 @@ public final class StrictJavaDepsPlugin extends BlazeJavaCompilerPlugin {
private final Set<JCTree.JCCompilationUnit> toplevels;
/** Marks seen ASTs */
private final Set<JCTree> trees;

/** Computed missing dependencies */
private final Set<JarOwner> missingTargets;

Expand Down Expand Up @@ -107,7 +106,7 @@ public StrictJavaDepsPlugin(DependencyModule dependencyModule) {
public void init(Context context, Log log, JavaCompiler compiler) {
super.init(context, log, compiler);
errWriter = log.getWriter(WriterKind.ERROR);
this.fileManager = context.get(JavaFileManager.class);
fileManager = context.get(JavaFileManager.class);
implicitDependencyExtractor = new ImplicitDependencyExtractor(
dependencyModule.getUsedClasspath(), dependencyModule.getImplicitDependenciesMap(),
fileManager);
Expand Down Expand Up @@ -151,6 +150,7 @@ public void postAttribute(Env<AttrContext> env) {
}
if (toplevels.add(env.toplevel)) {
checkingTreeScanner.scan(env.toplevel.getImports());
dependencyModule.addPackage(env.toplevel.packge.toString());
}
log.useSource(prev);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/protobuf/deps.proto
Expand Up @@ -60,4 +60,7 @@ message Dependencies {
// Whether the action was successful; even when compilation fails, partial
// dependency information can be useful.
optional bool success = 3;

// Packages contained in the output jar, sorted alphabetically.
repeated string contained_package = 4;
}

0 comments on commit 9b61b0f

Please sign in to comment.