aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Peter Schmitt <schmitt@google.com>2015-03-11 15:46:06 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-03-11 18:40:18 +0000
commit56dd176d948ed1f090fd7a0a73ecb62416b2646e (patch)
tree812fbe3acc6438c465163303a6ebadff6e0449fc /src/main/java
parent05b35d974c8407851af8f3474d6842cbf1be0957 (diff)
structured_resources allows directories in .app.
RELNOTES: objc_* rules can use structured_resources -- MOS_MIGRATED_REVID=88337360
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/BundleableFile.java47
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompiledResourceFile.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcActionsBuilder.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java14
6 files changed, 63 insertions, 15 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleableFile.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleableFile.java
index eea7bf06a0..c95f2e5702 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleableFile.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleableFile.java
@@ -50,10 +50,10 @@ public final class BundleableFile extends Value<BundleableFile> {
/**
* @param bundled the {@link Artifact} whose data is placed in the bundle
* @param bundlePath the path of the file in the bundle
- * @param the external file attribute of the file in the central directory of the bundle (zip
- * file). The lower 16 bits contain the MS-DOS file attributes. The upper 16 bits contain the
- * Unix file attributes, for instance 0100755 (octal) for a regular file with permissions
- * {@code rwxr-xr-x}.
+ * @param zipExternalFileAttribute external file attribute of the file in the central directory of
+ * the bundle (zip file). The lower 16 bits contain the MS-DOS file attributes. The upper 16
+ * bits contain the Unix file attributes, for instance 0100755 (octal) for a regular file with
+ * permissions {@code rwxr-xr-x}.
*/
BundleableFile(Artifact bundled, String bundlePath, int zipExternalFileAttribute) {
super(new ImmutableMap.Builder<String, Object>()
@@ -66,28 +66,55 @@ public final class BundleableFile extends Value<BundleableFile> {
this.zipExternalFileAttribute = zipExternalFileAttribute;
}
- static String bundlePath(PathFragment path) {
+ static String flatBundlePath(PathFragment path) {
String containingDir = path.getParentDirectory().getBaseName();
return (containingDir.endsWith(".lproj") ? (containingDir + "/") : "") + path.getBaseName();
}
/**
* Given a sequence of non-compiled resource files, returns a sequence of the same length of
- * instances of this class. Non-compiled resource files are resources which are not processed
- * before placing them in the final bundle. This is different from (for example) {@code .strings}
- * and {@code .xib} files, which must be converted to binary plist form or compiled.
+ * instances of this class with the resource paths flattened (resources are put in the bundle
+ * root) or, if the source file is in a directory ending in {@code .lproj}, in a directory of that
+ * name directly under the bundle root.
+ *
+ * <p>Non-compiled resource files are resources which are not processed before placing them in the
+ * final bundle. This is different from (for example) {@code .strings} and {@code .xib} files,
+ * which must be converted to binary plist form or compiled.
*
* @param files a sequence of artifacts corresponding to non-compiled resource files
*/
- public static Iterable<BundleableFile> nonCompiledResourceFiles(Iterable<Artifact> files) {
+ public static Iterable<BundleableFile> flattenedRawResourceFiles(Iterable<Artifact> files) {
ImmutableList.Builder<BundleableFile> result = new ImmutableList.Builder<>();
for (Artifact file : files) {
- result.add(new BundleableFile(file, bundlePath(file.getExecPath())));
+ result.add(new BundleableFile(file, flatBundlePath(file.getExecPath())));
}
return result.build();
}
/**
+ * Given a sequence of non-compiled resource files, returns a sequence of the same length of
+ * instances of this class with the resource paths copied as-is into the bundle root.
+ *
+ * <p>Non-compiled resource files are resources which are not processed before placing them in the
+ * final bundle. This is different from (for example) {@code .strings} and {@code .xib} files,
+ * which must be converted to binary plist form or compiled.
+ *
+ * @param files a sequence of artifacts corresponding to non-compiled resource files
+ */
+ public static Iterable<BundleableFile> structuredRawResourceFiles(Iterable<Artifact> files) {
+ ImmutableList.Builder<BundleableFile> result = new ImmutableList.Builder<>();
+ for (Artifact file : files) {
+ result.add(new BundleableFile(file, ownerBundlePath(file)));
+ }
+ return result.build();
+ }
+
+ private static String ownerBundlePath(Artifact file) {
+ PathFragment packageFragment = file.getArtifactOwner().getLabel().getPackageFragment();
+ return file.getRootRelativePath().relativeTo(packageFragment).toString();
+ }
+
+ /**
* Returns an instance for every file in a bundle directory.
* <p>
* This uses the parent-most container matching {@code *.bundle} as the bundle root.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompiledResourceFile.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompiledResourceFile.java
index cd84710c70..df0d09b9f4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompiledResourceFile.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompiledResourceFile.java
@@ -62,7 +62,8 @@ public class CompiledResourceFile {
Artifact binaryFile = intermediateArtifacts.convertedStringsFile(originalFile);
result.add(new CompiledResourceFile(
originalFile,
- new BundleableFile(binaryFile, BundleableFile.bundlePath(originalFile.getExecPath()))));
+ new BundleableFile(
+ binaryFile, BundleableFile.flatBundlePath(originalFile.getExecPath()))));
}
return result.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
index 20eda210eb..d852bb49cd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
@@ -203,7 +203,7 @@ final class IntermediateArtifacts {
* into the final bundle under the {@code .app} or {@code .bundle} directory root.
*/
public Artifact compiledStoryboardZip(Artifact input) {
- return appendExtension("/" + BundleableFile.bundlePath(input.getExecPath()) + ".zip");
+ return appendExtension("/" + BundleableFile.flatBundlePath(input.getExecPath()) + ".zip");
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcActionsBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcActionsBuilder.java
index ace406a2fc..30eaabd189 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcActionsBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcActionsBuilder.java
@@ -325,7 +325,7 @@ final class ObjcActionsBuilder {
ImmutableList.Builder<Action> result = new ImmutableList.Builder<>();
for (Artifact original : xibFiles) {
Artifact zipOutput = intermediateArtifacts.compiledXibFileZip(original);
- String archiveRoot = BundleableFile.bundlePath(
+ String archiveRoot = BundleableFile.flatBundlePath(
FileSystemUtils.replaceExtension(original.getExecPath(), ".nib"));
result.add(ibtoolzipAction(baseTools, "XibCompile", original, zipOutput, archiveRoot));
}
@@ -406,7 +406,7 @@ final class ObjcActionsBuilder {
}
void registerIbtoolzipAction(ObjcRuleClasses.Tools tools, Artifact input, Artifact outputZip) {
- String archiveRoot = BundleableFile.bundlePath(input.getExecPath()) + "c";
+ String archiveRoot = BundleableFile.flatBundlePath(input.getExecPath()) + "c";
register(ibtoolzipAction(tools, "StoryboardCompile", input, outputZip, archiveRoot));
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
index 89d86186aa..398efa0b15 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
@@ -179,6 +179,10 @@ public final class ObjcCommon {
return ruleContext.getPrerequisiteArtifacts("resources", Mode.TARGET).list();
}
+ ImmutableList<Artifact> structuredResources() {
+ return ruleContext.getPrerequisiteArtifacts("structured_resources", Mode.TARGET).list();
+ }
+
ImmutableList<Artifact> datamodels() {
return ruleContext.getPrerequisiteArtifacts("datamodels", Mode.TARGET).list();
}
@@ -367,7 +371,9 @@ public final class ObjcCommon {
.addAll(GENERAL_RESOURCE_FILE, attributes.resources())
.addAll(GENERAL_RESOURCE_FILE, attributes.strings())
.addAll(GENERAL_RESOURCE_FILE, attributes.xibs())
- .addAll(BUNDLE_FILE, BundleableFile.nonCompiledResourceFiles(attributes.resources()))
+ .addAll(BUNDLE_FILE, BundleableFile.flattenedRawResourceFiles(attributes.resources()))
+ .addAll(BUNDLE_FILE,
+ BundleableFile.structuredRawResourceFiles(attributes.structuredResources()))
.addAll(BUNDLE_FILE,
Iterables.transform(compiledResources, CompiledResourceFile.TO_BUNDLED))
.addAll(XCASSETS_DIR,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
index 4614afd920..5e28bfb414 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
@@ -342,6 +342,20 @@ public class ObjcRuleClasses {
same name in the app bundle.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("resources", LABEL_LIST).legacyAllowAnyFileType().direct_compile_time_input())
+ /* <!-- #BLAZE_RULE($objc_resources_rule).ATTRIBUTE(structured_resources) -->
+ Files to include in the final application bundle.
+ ${SYNOPSIS}
+
+ They are not processed or compiled in any way besides the processing
+ done by the rules that actually generate them. In differences to
+ <code>resources</code> these files are placed in the bundle root in
+ the same structure passed to this argument, so
+ <code>["res/foo.png"]</code> will end up in
+ <code>Payload/foo.app/res/foo.png</code>.
+ <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
+ .add(attr("structured_resources", LABEL_LIST)
+ .legacyAllowAnyFileType()
+ .direct_compile_time_input())
/* <!-- #BLAZE_RULE($objc_resources_rule).ATTRIBUTE(datamodels) -->
Files that comprise the data models of the final linked binary.
${SYNOPSIS}