Avoid long, duplicated directory structures. In the common case, generated
files are going to be beneath the target that generates them. In this case,
don't duplicated the package's path.
RELNOTES: None.
@@ -585,8 +585,16 @@ public class CppHelper {
private static Artifact getIncludesOutput(RuleContext ruleContext, Artifact src) {
Preconditions.checkArgument(!src.isSourceArtifact(), src);
+ PathFragment pkgPath = ruleContext.getLabel().getPackageFragment();
+ PathFragment fileName = src.getRootRelativePath();
+ if (fileName.startsWith(pkgPath)) {
+ // In most cases actions grep the includes of files that they create and that are located
+ // within their own package. In this case, don't duplicate the package path underneath the
+ // actions genfiles directory.
+ fileName = fileName.relativeTo(pkgPath);
+ }
return ruleContext.getGenfilesArtifact(
- src.getRootRelativePath().replaceName(src.getFilename() + GREPPED_INCLUDES_SUFFIX));
+ fileName.replaceName(src.getFilename() + GREPPED_INCLUDES_SUFFIX));
}
/**
