Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move summarization action to Aspects. #2142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.common.io.Resources;
Expand Down Expand Up @@ -67,6 +68,7 @@ class Options {
private File outputFile = new File("tree-shaker-report.txt");
private LibraryInfo summary;
private String summaryOutputFile;
private List<LibraryInfo> summaries = Lists.newArrayList();

// The default source version number if not passed with -source is determined from the system
// properties of the running java version after parsing the argument list.
Expand Down Expand Up @@ -135,11 +137,27 @@ public LibraryInfo getSummary() {
public void setSummary(LibraryInfo summary) {
this.summary = summary;
}


public List<LibraryInfo> getSummaries() {
return summaries;
}

public void setSummaries(List<LibraryInfo> summaries) {
this.summaries = summaries;
}

public void addSummary(LibraryInfo summary) {
this.summaries.add(summary);
}

public String getSummaryOutputFile() {
return summaryOutputFile;
}

public void setSummaryOutputFile(String summaryOutputFile) {
this.summaryOutputFile = summaryOutputFile;
}

private void addManifest(String manifestFile) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(new File(manifestFile)));
try {
Expand Down Expand Up @@ -192,6 +210,16 @@ public static Options parse(String[] args) throws IOException {
return options;
}

private static List<LibraryInfo> readSummaries(List<String> summaries) throws IOException {
List<LibraryInfo> result = Lists.newArrayList();
for (String summary : summaries) {
result.add(
LibraryInfo.parseFrom(
Files.toByteArray(new File(summary)), ExtensionRegistry.getGeneratedRegistry()));
}
return result;
}

private static void processArgsFile(String filename, Options options) throws IOException {
if (filename.isEmpty()) {
usage("no @ file specified");
Expand Down Expand Up @@ -220,6 +248,11 @@ private static void processArgs(String[] args, Options options) throws IOExcepti
usage("-classpath requires an argument");
}
options.classpath = args[nArg];
} else if (arg.equals("-summaries")) {
if (++nArg == args.length) {
usage("--summaries requires an argument");
}
options.setSummaries(readSummaries(ImmutableList.copyOf(args[nArg].split(":"))));
} else if (arg.equals("-summary")) {
if (++nArg == args.length) {
usage("-summary requires an argument");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

package com.google.devtools.treeshaker;

import static com.google.common.collect.ImmutableList.toImmutableList;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.flogger.GoogleLogger;
import com.google.common.io.Files;
import com.google.devtools.j2objc.ast.CompilationUnit;
Expand Down Expand Up @@ -170,6 +173,12 @@ private TypeGraphBuilder createTypeGraphBuilder() throws IOException {
LibraryInfo info = options.getSummary();
LibraryInfo markedInfo = UsedCodeMarker.mark(info, options.getTreeShakerRoots());
return new TypeGraphBuilder(markedInfo);
} else if (!options.getSummaries().isEmpty()) {
ImmutableList<LibraryInfo> markedInfo =
options.getSummaries().stream()
.map(summary -> UsedCodeMarker.mark(summary, options.getTreeShakerRoots()))
.collect(toImmutableList());
return new TypeGraphBuilder(markedInfo);
}
return new TypeGraphBuilder(createLibraryInfo());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -38,6 +39,25 @@ class TypeGraphBuilder {
types = typesByName.values();
}

TypeGraphBuilder(List<LibraryInfo> libraryInfos) {
Map<String, Type> typesByName = new LinkedHashMap<>();
externalTypeReferences = new HashSet<>();
unknownMethodReferences = new HashSet<>();
for (LibraryInfo libraryInfo : libraryInfos) {
for (TypeInfo typeInfo : libraryInfo.getTypeList()) {
Type type = Type.buildFrom(typeInfo, libraryInfo.getTypeMap(typeInfo.getTypeId()));
typesByName.put(type.getName(), type);
}
}

// Build cross-references between types and members
for (LibraryInfo libraryInfo : libraryInfos) {
buildCrossReferences(libraryInfo, typesByName);
}

types = typesByName.values();
}

Collection<Type> getTypes() {
return types;
}
Expand Down
Loading