diff options
author | 2015-05-12 20:29:32 +0000 | |
---|---|---|
committer | 2015-05-15 09:40:06 +0000 | |
commit | 71d843f41b0e968dca1d2b2b192265505a3eb7b1 (patch) | |
tree | 9d076e3924f1dfe57c5d9fff8b3b4a77bc198169 /src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSource.java | |
parent | 5e14a92104c8862849d26badc764b5ea2b8f01bb (diff) |
Add a genrule that generates a dummy J2ObjC dead code removal script in tools/objc/BUILD.
--
MOS_MIGRATED_REVID=93447039
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSource.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSource.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSource.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSource.java index 81ba292314..dc7251ee3a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSource.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSource.java @@ -15,9 +15,13 @@ package com.google.devtools.build.lib.rules.objc; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterators; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.AnalysisUtils; +import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.syntax.Label; +import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; /** @@ -67,6 +71,41 @@ public class J2ObjcSource { } /** + * Returns a corresponding {@link J2ObjcSource} with source artifacts replaced by the outputs of + * the J2objC dead code removal script, for use after that action has processed the originals. + * + * <p>The script in question builds a dependency graph with entry classes specified + * transitively on j2objc_library rules as roots. Translated files from this (original) + * {@link J2ObjcSource} which are reachable in the graph from the roots will be copied over to the + * source file paths in the returned pruned {@link J2ObjcSource} with full original contents. + * Unreachable files will not be copied over and the artifacts pointed to by the returned pruned + * {@link J2ObjcSource} will only contain empty files. + * + * @param ruleContext the {@link RuleContext} of the current rule + */ + public J2ObjcSource toPrunedSource(RuleContext ruleContext) { + ImmutableList.Builder<Artifact> prunedSourceArtifacts = ImmutableList.builder(); + + for (Artifact sourceArtifact : getObjcSrcs()) { + PathFragment scopedPath = AnalysisUtils.getUniqueDirectory( + ruleContext.getRule().getLabel(), new PathFragment("_j2objc_pruned")); + PathFragment prunedSourceArtifactPath = FileSystemUtils.appendWithoutExtension( + scopedPath.getRelative(sourceArtifact.getRootRelativePath()), "_pruned"); + + Artifact prunedArtifact = ruleContext.getAnalysisEnvironment().getDerivedArtifact( + prunedSourceArtifactPath, ruleContext.getBinOrGenfilesDirectory()); + prunedSourceArtifacts.add(prunedArtifact); + } + + return new J2ObjcSource( + getTargetLabel(), + prunedSourceArtifacts.build(), + getObjcHdrs(), + getObjcFilePath(), + getSourceType()); + } + + /** * Returns the label of the associated target. */ public Label getTargetLabel() { |