From 9a005f730518fc2b818ce995cac6db9f9d0bdff3 Mon Sep 17 00:00:00 2001 From: kaipi Date: Wed, 8 May 2019 09:16:50 -0700 Subject: [PATCH] Delete resource fields from ObjcProvider and related code. RELNOTES[INC]: --incompatible_disable_objc_provider_resources no longer has effect. Use of deprecated resource fields on the Objc provider is now disallowed regardless of this flag. PiperOrigin-RevId: 247225773 --- .../packages/StarlarkSemanticsOptions.java | 2 +- .../lib/rules/objc/AppleSkylarkCommon.java | 5 - .../lib/rules/objc/AppleStaticLibrary.java | 15 +- .../rules/objc/BundleMergeControlBytes.java | 111 --- .../build/lib/rules/objc/BundleableFile.java | 190 ------ .../build/lib/rules/objc/Bundling.java | 630 ------------------ .../lib/rules/objc/IntermediateArtifacts.java | 126 ---- .../build/lib/rules/objc/ObjcProvider.java | 127 +--- .../objc/ObjcProviderSkylarkConverters.java | 53 -- .../build/lib/rules/objc/ObjcRuleClasses.java | 11 - .../lib/rules/objc/PlMergeControlBytes.java | 155 ----- .../lib/rules/objc/TargetDeviceFamily.java | 126 ---- .../build/lib/rules/objc/Xcdatamodel.java | 100 --- .../build/lib/rules/objc/Xcdatamodels.java | 79 --- .../apple/ObjcProviderApi.java | 65 -- .../fakebuildapi/apple/FakeObjcProvider.java | 40 -- .../build/lib/rules/objc/ObjcSkylarkTest.java | 132 ---- .../rules/objc/TargetDeviceFamilyTest.java | 86 --- 18 files changed, 5 insertions(+), 2048 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/BundleableFile.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamily.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodel.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodels.java delete mode 100644 src/test/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamilyTest.java diff --git a/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java index c039f87b17d6c6..298e14facb14e4 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java +++ b/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java @@ -219,7 +219,7 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl OptionMetadataTag.INCOMPATIBLE_CHANGE, OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES }, - help = "If set to true, disallow use of deprecated resource fields on the Objc provider.") + help = "Unused. Will be removed in future versions of Bazel.") public boolean incompatibleDisableObjcProviderResources; // For Bazel, this flag is a no-op. Bazel doesn't support built-in third party license checking diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java index 6b5411b84bf084..ea014b2ce3f56c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java @@ -185,8 +185,6 @@ public ObjcProvider newObjcProvider( Boolean usesSwift, SkylarkDict kwargs, Environment environment) { - boolean disableObjcResourceKeys = - environment.getSemantics().incompatibleDisableObjcProviderResources(); ObjcProvider.Builder resultBuilder = new ObjcProvider.Builder(environment.getSemantics()); if (usesSwift) { resultBuilder.add(ObjcProvider.FLAG, ObjcProvider.Flag.USES_SWIFT); @@ -194,9 +192,6 @@ public ObjcProvider newObjcProvider( for (Map.Entry entry : kwargs.entrySet()) { Key key = ObjcProvider.getSkylarkKeyForString((String) entry.getKey()); if (key != null) { - if (disableObjcResourceKeys && ObjcProvider.isDeprecatedResourceKey(key)) { - throw new IllegalArgumentException(String.format(BAD_KEY_ERROR, entry.getKey())); - } resultBuilder.addElementsFromSkylark(key, entry.getValue()); } else if (entry.getKey().equals("providers")) { resultBuilder.addProvidersFromSkylark(entry.getValue()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java index a98c9bb17afbe6..5bdc511e9f8a2f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java @@ -49,21 +49,12 @@ public class AppleStaticLibrary implements RuleConfiguredTargetFactory { /** - * Set of {@link ObjcProvider} values which are propagated from dependencies to dependers by - * this rule. + * Set of {@link ObjcProvider} values which are propagated from dependencies to dependers by this + * rule. */ private static final ImmutableSet> PROPAGATE_KEYS = ImmutableSet.>of( - ObjcProvider.ASSET_CATALOG, - ObjcProvider.BUNDLE_FILE, - ObjcProvider.SDK_DYLIB, - ObjcProvider.SDK_FRAMEWORK, - ObjcProvider.STORYBOARD, - ObjcProvider.STRINGS, - ObjcProvider.WEAK_SDK_FRAMEWORK, - ObjcProvider.XCDATAMODEL, - ObjcProvider.XIB, - ObjcProvider.XCASSETS_DIR); + ObjcProvider.SDK_DYLIB, ObjcProvider.SDK_FRAMEWORK, ObjcProvider.WEAK_SDK_FRAMEWORK); @VisibleForTesting static final String UNSUPPORTED_PLATFORM_TYPE_ERROR_FORMAT = diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java deleted file mode 100644 index 9203224c007aa4..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleMergeControlBytes.java +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.common.base.Preconditions; -import com.google.common.io.ByteSource; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.rules.apple.ApplePlatform; -import com.google.devtools.build.lib.rules.apple.DottedVersion; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.Control; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.MergeZip; -import java.io.InputStream; - -/** - * A byte source that can be used to generate a control file for the tool bundlemerge . - * Note that this generates the control proto and bytes on-the-fly rather than eagerly. - * This is to prevent a copy of the bundle files and .xcdatamodels from being stored for - * each {@code objc_binary} (or any bundle) being built. - */ -// TODO(bazel-team): Move the logic in this class to Bundling (as a .toControl method). -final class BundleMergeControlBytes extends ByteSource { - private final Bundling rootBundling; - private final Artifact mergedIpa; - private final DottedVersion iosSdkVersion; - private final ApplePlatform platform; - - public BundleMergeControlBytes( - Bundling rootBundling, Artifact mergedIpa, DottedVersion iosSdkVersion, - ApplePlatform platform) { - this.rootBundling = Preconditions.checkNotNull(rootBundling); - this.mergedIpa = Preconditions.checkNotNull(mergedIpa); - this.iosSdkVersion = iosSdkVersion; - this.platform = platform; - } - - @Override - public InputStream openStream() { - return control("", rootBundling).toByteString().newInput(); - } - - private Control control(String mergeZipPrefix, Bundling bundling) { - mergeZipPrefix += bundling.getBundleDir() + "/"; - - BundleMergeProtos.Control.Builder control = - BundleMergeProtos.Control.newBuilder() - .addAllBundleFile(BundleableFile.toBundleFiles(bundling.getBundleFiles())) - // TODO(bazel-team): Add rule attribute for specifying targeted device family - .setMinimumOsVersion(bundling.getMinimumOsVersion().toString()) - .setSdkVersion(iosSdkVersion.toString()) - .setPlatform(platform.name()) - .setBundleRoot(bundling.getBundleDir()); - - if (bundling.getBundleInfoplist().isPresent()) { - control.setBundleInfoPlistFile(bundling.getBundleInfoplist().get().getExecPathString()); - } - - for (Artifact mergeZip : bundling.getMergeZips()) { - control.addMergeZip(MergeZip.newBuilder() - .setEntryNamePrefix(mergeZipPrefix) - .setSourcePath(mergeZip.getExecPathString()) - .build()); - } - - for (Artifact rootMergeZip : bundling.getRootMergeZips()) { - control.addMergeZip(MergeZip.newBuilder() - .setEntryNamePrefix("") - .setSourcePath(rootMergeZip.getExecPathString()) - .build()); - } - - control.setOutFile(mergedIpa.getExecPathString()); - - for (Artifact linkedBinary : bundling.getCombinedArchitectureBinary().asSet()) { - control.addBundleFile( - BundleMergeProtos.BundleFile.newBuilder() - .setSourceFile(linkedBinary.getExecPathString()) - .setBundlePath(bundling.getName()) - .setExternalFileAttribute(BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE) - .build()); - } - - for (Bundling nestedBundling : bundling.getNestedBundlings()) { - if (nestedBundling.getArchitecture().equals(bundling.getArchitecture())) { - control.addNestedBundle(control(mergeZipPrefix, nestedBundling)); - } - } - - if (bundling.getPrimaryBundleId() != null) { - control.setPrimaryBundleIdentifier(bundling.getPrimaryBundleId()); - } - - if (bundling.getFallbackBundleId() != null) { - control.setFallbackBundleIdentifier(bundling.getFallbackBundleId()); - } - - return control.build(); - } -} 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 deleted file mode 100644 index 21436a543a8b67..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleableFile.java +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.rules.objc.ArtifactListAttribute.BUNDLE_IMPORTS; -import static com.google.devtools.build.lib.rules.objc.ObjcCommon.BUNDLE_CONTAINER_TYPE; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.vfs.PathFragment; -import com.google.devtools.build.xcode.bundlemerge.proto.BundleMergeProtos.BundleFile; - -/** - * Represents a file which is processed to another file and bundled. It contains the - * {@code Artifact} corresponding to the original file as well as the {@code Artifact} for the file - * converted to its bundled form. Examples of files that fit this pattern are .strings and .xib - * files. - */ -public final class BundleableFile extends Value { - - static final int EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE = 0100755 << 16; - static final int DEFAULT_EXTERNAL_FILE_ATTRIBUTE = 0100644 << 16; - - /** The field in the Skylark struct that holds the {@code bundled} artifact. */ - static final String BUNDLED_FIELD = "file"; - - /** The field in the Skylark struct that holds the {@code bundlePath} string. */ - static final String BUNDLE_PATH_FIELD = "bundle_path"; - - private final Artifact bundled; - private final String bundlePath; - private final int zipExternalFileAttribute; - - /** - * Creates an instance whose {@code zipExternalFileAttribute} value is - * {@link #DEFAULT_EXTERNAL_FILE_ATTRIBUTE}. - */ - BundleableFile(Artifact bundled, String bundlePath) { - this(bundled, bundlePath, DEFAULT_EXTERNAL_FILE_ATTRIBUTE); - } - - /** - * @param bundled the {@link Artifact} whose data is placed in the bundle - * @param bundlePath the path of the file in the bundle - * @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() - .put("bundled", bundled) - .put("bundlePath", bundlePath) - .put("zipExternalFileAttribute", zipExternalFileAttribute) - .build()); - this.bundled = bundled; - this.bundlePath = bundlePath; - this.zipExternalFileAttribute = zipExternalFileAttribute; - } - - 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 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. - * - *

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 flattenedRawResourceFiles(Iterable files) { - ImmutableList.Builder result = new ImmutableList.Builder<>(); - for (Artifact file : files) { - 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. - * - *

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 structuredRawResourceFiles(Iterable files) { - ImmutableList.Builder 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().getPackageIdentifier().getSourceRoot(); - return file.getRootRelativePath().relativeTo(packageFragment).toString(); - } - - /** - * Returns an instance for every file in a bundle directory. - *

- * This uses the parent-most container matching {@code *.bundle} as the bundle root. - * TODO(bazel-team): add something like an import_root attribute to specify this explicitly, which - * will be helpful if a bundle that appears to be nested needs to be imported alone. - */ - public static Iterable bundleImportsFromRule(RuleContext context) { - ImmutableList.Builder result = new ImmutableList.Builder<>(); - for (Artifact artifact : BUNDLE_IMPORTS.get(context)) { - for (PathFragment container : - ObjcCommon.farthestContainerMatching(BUNDLE_CONTAINER_TYPE, artifact).asSet()) { - // TODO(bazel-team): Figure out if we need to remove symbols of architectures we aren't - // building for from the binary in the bundle. - result.add(new BundleableFile( - artifact, - // The path from the artifact's container (including the container), to the artifact - // itself. For instance, if artifact is foo/bar.bundle/baz, then this value - // is bar.bundle/baz. - artifact.getExecPath().relativeTo(container.getParentDirectory()).getSafePathString())); - } - } - return result.build(); - } - - /** - * Returns the location into which this file should be put in, relative to the bundle root. - */ - public String getBundlePath() { - return bundlePath; - } - - /** - * Returns the artifact representing the source for this bundleable file. - */ - public Artifact getBundled() { - return bundled; - } - - /** - * Returns bundle files for each given strings file. These are used to merge the strings files to - * the final application bundle. - */ - public static Iterable toBundleFiles(Iterable files) { - ImmutableList.Builder result = new ImmutableList.Builder<>(); - for (BundleableFile file : files) { - result.add(BundleFile.newBuilder() - .setBundlePath(file.bundlePath) - .setSourceFile(file.bundled.getExecPathString()) - .setExternalFileAttribute(file.zipExternalFileAttribute) - .build()); - } - return result.build(); - } - - /** - * Returns the artifacts for the bundled files. These can be used, for instance, as the input - * files to add to the bundlemerge action for a bundle that contains all the given files. - */ - public static Iterable toArtifacts(Iterable files) { - ImmutableList.Builder result = new ImmutableList.Builder<>(); - for (BundleableFile file : files) { - result.add(file.bundled); - } - return result.build(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java deleted file mode 100644 index 538e8e4ddd8cc9..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java +++ /dev/null @@ -1,630 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.ASSET_CATALOG; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.DYNAMIC_FRAMEWORK_FILE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag.USES_SWIFT; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.IMPORTED_LIBRARY; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LIBRARY; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.MERGE_ZIP; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.MULTI_ARCH_LINKED_BINARIES; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.NESTED_BUNDLE; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.ROOT_MERGE_ZIP; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STORYBOARD; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STRINGS; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCDATAMODEL; -import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XIB; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.DottedVersion; -import com.google.devtools.build.lib.vfs.PathFragment; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import javax.annotation.Nullable; - -/** - * Contains information regarding the creation of an iOS bundle. - */ -@Immutable -final class Bundling { - - /** - * Names of top-level directories in dynamic frameworks (i.e. directly under the - * {@code *.framework} directory) that should not be copied into the final bundle. - */ - private static final ImmutableSet STRIP_FRAMEWORK_DIRS = - ImmutableSet.of("Headers", "PrivateHeaders", "Modules"); - - static final class Builder { - private String name; - private String bundleDirFormat; - private ImmutableList.Builder bundleFilesBuilder = ImmutableList.builder(); - private ObjcProvider objcProvider; - private NestedSetBuilder infoplistInputs = NestedSetBuilder.stableOrder(); - private Artifact automaticEntriesInfoplistInput; - private IntermediateArtifacts intermediateArtifacts; - private String primaryBundleId; - private String fallbackBundleId; - private String architecture; - private DottedVersion minimumOsVersion; - private ImmutableSet families; - private String artifactPrefix; - @Nullable private String executableName; - - public Builder setName(String name) { - this.name = name; - return this; - } - - /** Sets the name of the bundle's executable. */ - public Builder setExecutableName(String executableName) { - this.executableName = executableName; - return this; - } - - /** - * Sets the CPU architecture this bundling was constructed for. Legal value are any that may be - * set on {@link AppleConfiguration#getIosCpu()}. - */ - public Builder setArchitecture(String architecture) { - this.architecture = architecture; - return this; - } - - public Builder setBundleDirFormat(String bundleDirFormat) { - this.bundleDirFormat = bundleDirFormat; - return this; - } - - public Builder addExtraBundleFiles(ImmutableList extraBundleFiles) { - this.bundleFilesBuilder.addAll(extraBundleFiles); - return this; - } - - public Builder setObjcProvider(ObjcProvider objcProvider) { - this.objcProvider = objcProvider; - return this; - } - - /** - * Adds an artifact representing an {@code Info.plist} as an input to this bundle's - * {@code Info.plist} (which is merged from any such added plists plus the generated - * automatic entries plist). - */ - public Builder addInfoplistInput(Artifact infoplist) { - this.infoplistInputs.add(infoplist); - return this; - } - - /** - * Adds the given list of artifacts representing {@code Info.plist}s that are to be merged into - * this bundle's {@code Info.plist}. - */ - public Builder addInfoplistInputs(Iterable infoplists) { - this.infoplistInputs.addAll(infoplists); - return this; - } - - /** - * Adds an artifact representing an {@code Info.plist} that contains automatic entries - * generated by xcode. - */ - public Builder setAutomaticEntriesInfoplistInput(Artifact automaticEntriesInfoplist) { - this.automaticEntriesInfoplistInput = automaticEntriesInfoplist; - return this; - } - - public Builder setIntermediateArtifacts(IntermediateArtifacts intermediateArtifacts) { - this.intermediateArtifacts = intermediateArtifacts; - return this; - } - - public Builder setPrimaryBundleId(String primaryId) { - this.primaryBundleId = primaryId; - return this; - } - - public Builder setFallbackBundleId(String fallbackId) { - this.fallbackBundleId = fallbackId; - return this; - } - - /** - * Sets the minimum OS version for this bundle which will be used when constructing the bundle's - * plist. - */ - public Builder setMinimumOsVersion(DottedVersion minimumOsVersion) { - this.minimumOsVersion = minimumOsVersion; - return this; - } - - public Builder setTargetDeviceFamilies(ImmutableSet families) { - this.families = families; - return this; - } - - public Builder setArtifactPrefix(String artifactPrefix) { - this.artifactPrefix = artifactPrefix; - return this; - } - - private static NestedSet nestedBundleContentArtifacts(Iterable bundles) { - NestedSetBuilder artifacts = NestedSetBuilder.stableOrder(); - for (Bundling bundle : bundles) { - artifacts.addTransitive(bundle.getBundleContentArtifacts()); - } - return artifacts.build(); - } - - private NestedSet mergeZips(Optional actoolzipOutput) { - NestedSetBuilder mergeZipBuilder = - NestedSetBuilder.stableOrder() - .addAll(actoolzipOutput.asSet()) - .addAll( - Xcdatamodel.outputZips( - Xcdatamodels.xcdatamodels( - intermediateArtifacts, objcProvider.get(XCDATAMODEL)))) - .addTransitive(objcProvider.get(MERGE_ZIP)); - for (Artifact xibFile : objcProvider.get(XIB)) { - mergeZipBuilder.add(intermediateArtifacts.compiledXibFileZip(xibFile)); - } - for (Artifact storyboard : objcProvider.get(STORYBOARD)) { - mergeZipBuilder.add(intermediateArtifacts.compiledStoryboardZip(storyboard)); - } - - if (objcProvider.is(USES_SWIFT)) { - mergeZipBuilder.add(intermediateArtifacts.swiftFrameworksFileZip()); - } - - return mergeZipBuilder.build(); - } - - private NestedSet rootMergeZips() { - NestedSetBuilder rootMergeZipsBuilder = - NestedSetBuilder.stableOrder().addTransitive(objcProvider.get(ROOT_MERGE_ZIP)); - - if (objcProvider.is(USES_SWIFT)) { - rootMergeZipsBuilder.add(intermediateArtifacts.swiftSupportZip()); - } - - return rootMergeZipsBuilder.build(); - } - - private NestedSet bundleInfoplistInputs() { - if (objcProvider.hasAssetCatalogs()) { - infoplistInputs.add(intermediateArtifacts.actoolPartialInfoplist()); - } - return infoplistInputs.build(); - } - - private Optional bundleInfoplist(NestedSet bundleInfoplistInputs) { - if (bundleInfoplistInputs.isEmpty()) { - return Optional.absent(); - } - if (needsToMerge(bundleInfoplistInputs, primaryBundleId, fallbackBundleId)) { - return Optional.of(intermediateArtifacts.mergedInfoplist()); - } - return Optional.of(Iterables.getOnlyElement(bundleInfoplistInputs)); - } - - private Optional combinedArchitectureBinary() { - if (!Iterables.isEmpty(objcProvider.get(MULTI_ARCH_LINKED_BINARIES))) { - return Optional.of(Iterables.getOnlyElement(objcProvider.get(MULTI_ARCH_LINKED_BINARIES))); - } else if (!Iterables.isEmpty(objcProvider.get(LIBRARY)) - || !Iterables.isEmpty(objcProvider.get(IMPORTED_LIBRARY))) { - return Optional.of(intermediateArtifacts.combinedArchitectureBinary()); - } - return Optional.absent(); - } - - private Optional actoolzipOutput() { - Optional actoolzipOutput = Optional.absent(); - if (!Iterables.isEmpty(objcProvider.get(ASSET_CATALOG))) { - actoolzipOutput = Optional.of(intermediateArtifacts.actoolzipOutput()); - } - return actoolzipOutput; - } - - private NestedSet binaryStringsFiles() { - NestedSetBuilder binaryStringsBuilder = NestedSetBuilder.stableOrder(); - for (Artifact stringsFile : objcProvider.get(STRINGS)) { - BundleableFile bundleFile = - new BundleableFile( - intermediateArtifacts.convertedStringsFile(stringsFile), - BundleableFile.flatBundlePath(stringsFile.getExecPath())); - binaryStringsBuilder.add(bundleFile); - } - return binaryStringsBuilder.build(); - } - - private NestedSet dynamicFrameworkFiles() { - NestedSetBuilder frameworkFilesBuilder = NestedSetBuilder.stableOrder(); - for (Artifact frameworkFile : objcProvider.get(DYNAMIC_FRAMEWORK_FILE)) { - PathFragment frameworkDir = - ObjcCommon.nearestContainerMatching(ObjcCommon.FRAMEWORK_CONTAINER_TYPE, frameworkFile) - .get(); - String frameworkName = frameworkDir.getBaseName(); - PathFragment inFrameworkPath = frameworkFile.getExecPath().relativeTo(frameworkDir); - if (inFrameworkPath.getFirstSegment(STRIP_FRAMEWORK_DIRS) == 0) { - continue; - } - // If this is a top-level file in the framework set the executable bit (to make sure we set - // the bit on the actual dylib binary - other files may also get it but we have no way to - // distinguish them). - int permissions = - inFrameworkPath.segmentCount() == 1 - ? BundleableFile.EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE - : BundleableFile.DEFAULT_EXTERNAL_FILE_ATTRIBUTE; - BundleableFile bundleFile = - new BundleableFile( - frameworkFile, - "Frameworks/" + frameworkName + "/" + inFrameworkPath.getPathString(), - permissions); - frameworkFilesBuilder.add(bundleFile); - } - return frameworkFilesBuilder.build(); - } - - /** - * Filters files that would map to the same location in the bundle, adding only one copy to the - * set of files returned. - * - *

Files can have the same bundle path for various illegal reasons and errors are raised for - * that separately. There are situations though where the same file exists multiple times (for - * example in multi-architecture builds) and would conflict when creating the bundle. In all - * these cases it shouldn't matter which one is included and this class will select the first - * one. - */ - ImmutableList deduplicateByBundlePaths( - ImmutableList bundleFiles) { - ImmutableList.Builder deduplicated = ImmutableList.builder(); - Set bundlePaths = new HashSet<>(); - for (BundleableFile bundleFile : bundleFiles) { - if (bundlePaths.add(bundleFile.getBundlePath())) { - deduplicated.add(bundleFile); - } - } - return deduplicated.build(); - } - - public Bundling build() { - Preconditions.checkNotNull(intermediateArtifacts, "intermediateArtifacts should not be null"); - Preconditions.checkNotNull(families, "families should not be null"); - NestedSet bundleInfoplistInputs = bundleInfoplistInputs(); - Optional bundleInfoplist = bundleInfoplist(bundleInfoplistInputs); - Optional actoolzipOutput = actoolzipOutput(); - Optional combinedArchitectureBinary = combinedArchitectureBinary(); - NestedSet binaryStringsFiles = binaryStringsFiles(); - NestedSet dynamicFrameworks = dynamicFrameworkFiles(); - NestedSet mergeZips = mergeZips(actoolzipOutput); - NestedSet rootMergeZips = rootMergeZips(); - - bundleFilesBuilder - .addAll(binaryStringsFiles) - .addAll(dynamicFrameworks) - .addAll(objcProvider.get(BUNDLE_FILE)); - ImmutableList bundleFiles = - deduplicateByBundlePaths(bundleFilesBuilder.build()); - - NestedSetBuilder bundleContentArtifactsBuilder = - NestedSetBuilder.stableOrder() - .addTransitive(nestedBundleContentArtifacts(objcProvider.get(NESTED_BUNDLE))) - .addAll(combinedArchitectureBinary.asSet()) - .addAll(bundleInfoplist.asSet()) - .addTransitive(mergeZips) - .addTransitive(rootMergeZips) - .addAll(BundleableFile.toArtifacts(bundleFiles)); - - return new Bundling( - name, - executableName, - bundleDirFormat, - combinedArchitectureBinary, - bundleFiles, - bundleInfoplist, - actoolzipOutput, - bundleContentArtifactsBuilder.build(), - mergeZips, - rootMergeZips, - primaryBundleId, - fallbackBundleId, - architecture, - minimumOsVersion, - bundleInfoplistInputs, - automaticEntriesInfoplistInput, - objcProvider.get(NESTED_BUNDLE), - families, - intermediateArtifacts, - artifactPrefix); - } - } - - private static boolean needsToMerge( - NestedSet bundleInfoplistInputs, String primaryBundleId, String fallbackBundleId) { - return primaryBundleId != null || fallbackBundleId != null - || Iterables.size(bundleInfoplistInputs) > 1; - } - - private final String name; - @Nullable private final String executableName; - private final String architecture; - private final String bundleDirFormat; - private final Optional combinedArchitectureBinary; - private final ImmutableList bundleFiles; - private final Optional bundleInfoplist; - private final Optional actoolzipOutput; - private final NestedSet bundleContentArtifacts; - private final NestedSet mergeZips; - private final NestedSet rootMergeZips; - private final String primaryBundleId; - private final String fallbackBundleId; - private final DottedVersion minimumOsVersion; - private final NestedSet infoplistInputs; - private final NestedSet nestedBundlings; - private Artifact automaticEntriesInfoplistInput; - private final ImmutableSet families; - private final IntermediateArtifacts intermediateArtifacts; - private final String artifactPrefix; - - private Bundling( - String name, - String executableName, - String bundleDirFormat, - Optional combinedArchitectureBinary, - ImmutableList bundleFiles, - Optional bundleInfoplist, - Optional actoolzipOutput, - NestedSet bundleContentArtifacts, - NestedSet mergeZips, - NestedSet rootMergeZips, - String primaryBundleId, - String fallbackBundleId, - String architecture, - DottedVersion minimumOsVersion, - NestedSet infoplistInputs, - Artifact automaticEntriesInfoplistInput, - NestedSet nestedBundlings, - ImmutableSet families, - IntermediateArtifacts intermediateArtifacts, - String artifactPrefix) { - this.nestedBundlings = Preconditions.checkNotNull(nestedBundlings); - this.name = Preconditions.checkNotNull(name); - this.executableName = executableName; - this.bundleDirFormat = Preconditions.checkNotNull(bundleDirFormat); - this.combinedArchitectureBinary = Preconditions.checkNotNull(combinedArchitectureBinary); - this.bundleFiles = Preconditions.checkNotNull(bundleFiles); - this.bundleInfoplist = Preconditions.checkNotNull(bundleInfoplist); - this.actoolzipOutput = Preconditions.checkNotNull(actoolzipOutput); - this.bundleContentArtifacts = Preconditions.checkNotNull(bundleContentArtifacts); - this.mergeZips = Preconditions.checkNotNull(mergeZips); - this.rootMergeZips = Preconditions.checkNotNull(rootMergeZips); - this.fallbackBundleId = fallbackBundleId; - this.primaryBundleId = primaryBundleId; - this.architecture = Preconditions.checkNotNull(architecture); - this.minimumOsVersion = Preconditions.checkNotNull(minimumOsVersion); - this.infoplistInputs = Preconditions.checkNotNull(infoplistInputs); - this.automaticEntriesInfoplistInput = automaticEntriesInfoplistInput; - this.families = Preconditions.checkNotNull(families); - this.intermediateArtifacts = intermediateArtifacts; - this.artifactPrefix = artifactPrefix; - } - - /** - * The bundle directory. For apps, this would be {@code "Payload/TARGET_NAME.app"}, which is where - * in the bundle zip archive every file is found, including the linked binary, nested bundles, and - * everything returned by {@link #getBundleFiles()}. - */ - public String getBundleDir() { - return String.format(bundleDirFormat, name); - } - - /** - * The name of the bundle, from which the bundle root and the path of the linked binary in the - * bundle archive are derived. - */ - public String getName() { - return name; - } - - /** The name of the bundle's executable, or null if the bundle has no executable. */ - @Nullable public String getExecutableName() { - return executableName; - } - - /** - * An {@link Optional} with the linked binary artifact, or {@link Optional#absent()} if it is - * empty and should not be included in the bundle. - */ - public Optional getCombinedArchitectureBinary() { - return combinedArchitectureBinary; - } - - /** - * Bundle files to include in the bundle. These files are placed under the bundle root (possibly - * nested, of course, depending on the bundle path of the files). - */ - public ImmutableList getBundleFiles() { - return bundleFiles; - } - - /** - * Returns any bundles nested in this one. - */ - public NestedSet getNestedBundlings() { - return nestedBundlings; - } - - /** - * Returns an artifact representing this bundle's {@code Info.plist} or {@link Optional#absent()} - * if this bundle has no info plist inputs. - */ - public Optional getBundleInfoplist() { - return bundleInfoplist; - } - - /** - * Returns all info plists that need to be merged into this bundle's {@link #getBundleInfoplist() - * info plist}, other than that plist that contains blaze-generated automatic entires. - */ - public NestedSet getBundleInfoplistInputs() { - return infoplistInputs; - } - - /** - * Returns an artifact representing a plist containing automatic entries generated by bazel. - */ - public Artifact getAutomaticInfoPlist() { - return automaticEntriesInfoplistInput; - } - - /** - * Returns all artifacts that are required as input to the merging of the final plist. - */ - public NestedSet getMergingContentArtifacts() { - NestedSetBuilder result = NestedSetBuilder.stableOrder(); - result.addTransitive(infoplistInputs); - if (automaticEntriesInfoplistInput != null) { - result.add(automaticEntriesInfoplistInput); - } - return result.build(); - } - - /** - * Returns {@code true} if this bundle requires merging of its {@link #getBundleInfoplist() info - * plist}. - */ - public boolean needsToMergeInfoplist() { - return needsToMerge(infoplistInputs, primaryBundleId, fallbackBundleId); - } - - /** - * The location of the actoolzip output for this bundle. This is non-absent only included in the - * bundle if there is at least one asset catalog artifact supplied by - * {@link ObjcProvider#ASSET_CATALOG}. - */ - public Optional getActoolzipOutput() { - return actoolzipOutput; - } - - /** - * Returns all zip files whose contents should be merged into this bundle under the main bundle - * directory. For instance, if a merge zip contains files a/b and c/d, then the resulting bundling - * would have additional files at: - *

    - *
  • {bundleDir}/a/b - *
  • {bundleDir}/c/d - *
- */ - public NestedSet getMergeZips() { - return mergeZips; - } - - /** - * Returns all zip files whose contents should be merged into final ipa and outside the - * main bundle. For instance, if a merge zip contains files dir1/file1, then the resulting - * bundling would have additional files at: - *
    - *
  • dir1/file1 - *
  • {bundleDir}/other_files - *
- */ - public NestedSet getRootMergeZips() { - return rootMergeZips; - } - - /** - * Returns the variable substitutions that should be used when merging the plist info file of - * this bundle. - */ - public Map variableSubstitutions() { - return ImmutableMap.of( - "EXECUTABLE_NAME", Strings.nullToEmpty(executableName), - "BUNDLE_NAME", PathFragment.create(getBundleDir()).getBaseName(), - "PRODUCT_NAME", name); - } - - /** - * Returns the artifacts that are required to generate this bundle. - */ - public NestedSet getBundleContentArtifacts() { - return bundleContentArtifacts; - } - - /** - * Returns primary bundle ID to use, can be null. - */ - public String getPrimaryBundleId() { - return primaryBundleId; - } - - /** - * Returns fallback bundle ID to use when primary isn't set. - */ - public String getFallbackBundleId() { - return fallbackBundleId; - } - - /** - * Returns the iOS CPU architecture this bundle was constructed for. - */ - public String getArchitecture() { - return architecture; - } - - /** - * Returns the minimum iOS version this bundle's plist and resources should be generated for - * (does not affect the minimum OS version its binary is compiled with). - */ - public DottedVersion getMinimumOsVersion() { - return minimumOsVersion; - } - - /** - * Returns the list of {@link TargetDeviceFamily} values this bundle is targeting. If empty, the - * default values specified by "families" will be used. - */ - public ImmutableSet getTargetDeviceFamilies() { - return families; - } - - /** - * Returns {@link IntermediateArtifacts} required to create this bundle. - */ - public IntermediateArtifacts getIntermediateArtifacts() { - return intermediateArtifacts; - } - - /** - * Returns the prefix to be added to all generated artifact names, can be null. This is useful to - * disambiguate artifacts for multiple bundles created with different names within same rule. - */ - public String getArtifactPrefix() { - return artifactPrefix; - } -} 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 85eaf75eaa3d81..41f9bd0e3ccaf9 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 @@ -73,22 +73,6 @@ public final class IntermediateArtifacts { this.umbrellaHeaderStrategy = umbrellaHeaderStrategy; } - /** - * Returns a derived artifact in the bin directory obtained by appending some extension to the - * main label name; the result artifact is placed in a unique "entitlements" directory. - * For example, if this artifact is for a target Foo with extension ".extension", the result - * artifact will be located at {target_base_path}/entitlements/Foo.extension. - */ - public Artifact appendExtensionForEntitlementArtifact(String extension) { - PathFragment entitlementsDirectory = ruleContext.getUniqueDirectory("entitlements"); - Artifact artifact = - ruleContext.getDerivedArtifact( - entitlementsDirectory.replaceName( - addOutputPrefix(entitlementsDirectory.getBaseName(), extension)), - buildConfiguration.getBinDirectory(ruleContext.getRule().getRepository())); - return artifact; - } - /** * Returns the archive file name suffix. */ @@ -96,31 +80,6 @@ public String archiveFileNameSuffix() { return archiveFileNameSuffix; } - /** - * Returns the location of this target's generated entitlements file. - */ - public Artifact entitlements() { - return appendExtensionForEntitlementArtifact(".entitlements"); - } - - /** - * Returns the location of this target's extension plist which contains entries required by all - * watch extensions (for final merging into the bundle plist). - */ - public Artifact watchExtensionAutomaticPlist() { - return ruleContext.getRelatedArtifact( - ruleContext.getUniqueDirectory("plists"), "-automatic-watchExtensionInfo.plist"); - } - - /** - * Returns a derived artifact in the bin directory obtained by appending some extension to the end - * of the given {@link PathFragment}. - */ - private Artifact appendExtension(PathFragment original, String extension) { - return scopedArtifact(FileSystemUtils.appendExtension(original, - addOutputPrefix("", extension))); - } - /** * Returns a derived artifact in the bin directory obtained by appending some extension to the end * of the {@link PathFragment} corresponding to the owner {@link Label}. @@ -140,31 +99,6 @@ private Artifact appendExtensionInGenfiles(String extension) { name.replaceName(addOutputPrefix(name.getBaseName(), extension)), /* inGenfiles = */ true); } - /** - * The output of using {@code actoolzip} to run {@code actool} for a given bundle which is - * merged under the {@code .app} or {@code .bundle} directory root. - */ - public Artifact actoolzipOutput() { - return appendExtension(".actool.zip"); - } - - /** - * Output of the partial infoplist generated by {@code actool} when given the - * {@code --output-partial-info-plist [path]} flag. - */ - public Artifact actoolPartialInfoplist() { - return appendExtension(".actool-PartialInfo.plist"); - } - - /** - * The Info.plist file for a bundle which is comprised of more than one originating plist file. - * This is not needed for a bundle which has no source Info.plist files, or only one Info.plist - * file, since no merging occurs in that case. - */ - public Artifact mergedInfoplist() { - return appendExtension("-MergedInfo.plist"); - } - /** * The .objlist file, which contains a list of paths of object files to archive and is read by * clang (via -filelist flag) in the link action (for binary creation). @@ -262,59 +196,6 @@ public Artifact headersListFile(Artifact objectFile) { return ruleContext.getRelatedArtifact(objectFile.getRootRelativePath(), ".headers_list"); } - /** - * The artifact which contains the zipped-up results of compiling the storyboard. This is merged - * into the final bundle under the {@code .app} or {@code .bundle} directory root. - */ - public Artifact compiledStoryboardZip(Artifact input) { - return appendExtension("/" + BundleableFile.flatBundlePath(input.getExecPath()) + ".zip"); - } - - /** - * Returns the artifact which is the output of building an entire xcdatamodel[d] made of artifacts - * specified by a single rule. - * - * @param containerDir the containing *.xcdatamodeld or *.xcdatamodel directory - * @return the artifact for the zipped up compilation results. - */ - public Artifact compiledMomZipArtifact(PathFragment containerDir) { - return appendExtension( - "/" + FileSystemUtils.replaceExtension(containerDir, ".zip").getBaseName()); - } - - /** - * Returns the compiled (i.e. converted to binary plist format) artifact corresponding to the - * given {@code .strings} file. - */ - public Artifact convertedStringsFile(Artifact originalFile) { - return appendExtension(originalFile.getExecPath(), ".binary"); - } - - /** - * Returns the artifact corresponding to the zipped-up compiled form of the given {@code .xib} - * file. - */ - public Artifact compiledXibFileZip(Artifact originalFile) { - return appendExtension( - "/" + FileSystemUtils.replaceExtension(originalFile.getExecPath(), ".nib.zip")); - } - - /** - * Returns the artifact which is the output of running swift-stdlib-tool and copying resulting - * dylibs. - */ - public Artifact swiftFrameworksFileZip() { - return appendExtension(".swiftstdlib.zip"); - } - - /** - * Same as {@link #swiftFrameworksFileZip()} but used to put Swift dylibs at a different location - * in SwiftSupport directory at the top of the IPA. - */ - public Artifact swiftSupportZip() { - return appendExtension(".swiftsupport.zip"); - } - /** * Debug symbol file generated for a stripped linked binary. * @@ -414,13 +295,6 @@ public Artifact j2objcPrunedArchive(Artifact unprunedArchive) { buildConfiguration.getBinDirectory(ruleContext.getRule().getRepository())); } - /** - * Returns the location of this target's merged but not post-processed or signed IPA. - */ - public Artifact unprocessedIpa() { - return appendExtension(".unprocessed.ipa"); - } - /** * Returns artifact name prefixed with an output prefix if specified. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java index 05a7856f54b331..a5a8d928c6edc2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java @@ -196,25 +196,11 @@ public Class getType() { */ public static final Key DEFINE = new Key<>(STABLE_ORDER, "define", String.class); - public static final Key ASSET_CATALOG = - new Key<>(STABLE_ORDER, "asset_catalog", Artifact.class); - - /** - * Files that are plopped into the final bundle at some arbitrary bundle path. Do not include - * information about where the file originated from. - */ - public static final Key BUNDLE_FILE = - new Key<>(STABLE_ORDER, "bundle_file", BundleableFile.class); - - public static final Key XCASSETS_DIR = - new Key<>(STABLE_ORDER, "xcassets_dir", PathFragment.class); public static final Key SDK_DYLIB = new Key<>(STABLE_ORDER, "sdk_dylib", String.class); public static final Key SDK_FRAMEWORK = new Key<>(STABLE_ORDER, "sdk_framework", SdkFramework.class); public static final Key WEAK_SDK_FRAMEWORK = new Key<>(STABLE_ORDER, "weak_sdk_framework", SdkFramework.class); - public static final Key XCDATAMODEL = - new Key<>(STABLE_ORDER, "xcdatamodel", Artifact.class); public static final Key FLAG = new Key<>(STABLE_ORDER, "flag", Flag.class); /** @@ -247,17 +233,6 @@ public Class getType() { public static final Key MERGE_ZIP = new Key<>(STABLE_ORDER, "merge_zip", Artifact.class); - /** - * Merge zips to include in the ipa and outside the bundle root. - * - * e.g. For a bundle Test.ipa, unzipped content will be in: - * Test.ipa/ - * Test.ipa/Payload - * Test.ipa/Payload/Test.app - */ - public static final Key ROOT_MERGE_ZIP = - new Key<>(STABLE_ORDER, "root_merge_zip", Artifact.class); - /** * Exec paths of {@code .framework} directories corresponding to frameworks to include in search * paths, but not to link. These cause -F arguments (framework search paths) to be added to @@ -284,12 +259,6 @@ public Class getType() { public static final Key DYNAMIC_FRAMEWORK_FILE = new Key<>(STABLE_ORDER, "dynamic_framework_file", Artifact.class); - /** - * Bundles which should be linked in as a nested bundle to the final application. - */ - public static final Key NESTED_BUNDLE = - new Key<>(STABLE_ORDER, "nested_bundle", Bundling.class); - /** * Debug artifacts that should be exported by the top-level target. */ @@ -302,22 +271,6 @@ public Class getType() { public static final Key LINKMAP_FILE = new Key<>(STABLE_ORDER, "linkmap_file", Artifact.class); - /** - * Artifacts for storyboard sources. - */ - public static final Key STORYBOARD = - new Key<>(STABLE_ORDER, "storyboard", Artifact.class); - - /** - * Artifacts for .xib file sources. - */ - public static final Key XIB = new Key<>(STABLE_ORDER, "xib", Artifact.class); - - /** - * Artifacts for strings source files. - */ - public static final Key STRINGS = new Key<>(STABLE_ORDER, "strings", Artifact.class); - /** Linking information from cc dependencies. */ public static final Key CC_LIBRARY = new Key<>(LINK_ORDER, "cc_library", LibraryToLink.class); @@ -396,8 +349,6 @@ public enum Flag { /** All keys in ObjcProvider that will be passed in the corresponding Skylark provider. */ static final ImmutableList> KEYS_FOR_SKYLARK = ImmutableList.>of( - ASSET_CATALOG, - BUNDLE_FILE, DEFINE, DYNAMIC_FRAMEWORK_DIR, DYNAMIC_FRAMEWORK_FILE, @@ -421,32 +372,12 @@ public enum Flag { MULTI_ARCH_DYNAMIC_LIBRARIES, MULTI_ARCH_LINKED_ARCHIVES, MULTI_ARCH_LINKED_BINARIES, - ROOT_MERGE_ZIP, SDK_DYLIB, SDK_FRAMEWORK, SOURCE, STATIC_FRAMEWORK_FILE, - STORYBOARD, - STRINGS, UMBRELLA_HEADER, - WEAK_SDK_FRAMEWORK, - XCASSETS_DIR, - XCDATAMODEL, - XIB); - - /** Deprecated keys in ObjcProvider pertaining to resource files. */ - static final ImmutableList> DEPRECATED_RESOURCE_KEYS = - ImmutableList.>of( - ASSET_CATALOG, - BUNDLE_FILE, - // TODO(kaipi): Add this back once we have migrated usages of merge_zip from custom rules. - // MERGE_ZIP, - ROOT_MERGE_ZIP, - STORYBOARD, - STRINGS, - XCASSETS_DIR, - XCDATAMODEL, - XIB); + WEAK_SDK_FRAMEWORK); /** * Keys that should be kept as directItems. This is limited to a few keys that have larger @@ -464,17 +395,6 @@ public enum Flag { static final ImmutableSet> KEYS_FOR_DIRECT = ImmutableSet.>of(HEADER, MODULE_MAP, SOURCE); - @Override - public NestedSet assetCatalog() { - return get(ASSET_CATALOG); - } - - @Override - public SkylarkNestedSet bundleFile() { - return (SkylarkNestedSet) ObjcProviderSkylarkConverters.convertToSkylark( - BUNDLE_FILE, get(BUNDLE_FILE)); - } - @Override public NestedSet define() { return get(DEFINE); @@ -601,11 +521,6 @@ public NestedSet multiArchLinkedBinaries() { return get(MULTI_ARCH_LINKED_BINARIES); } - @Override - public NestedSet rootMergeZip() { - return get(ROOT_MERGE_ZIP); - } - @Override public NestedSet sdkDylib() { return get(SDK_DYLIB); @@ -632,16 +547,6 @@ public NestedSet staticFrameworkFile() { return get(STATIC_FRAMEWORK_FILE); } - @Override - public NestedSet storyboard() { - return get(STORYBOARD); - } - - @Override - public NestedSet strings() { - return get(STRINGS); - } - @Override public NestedSet umbrellaHeader() { return get(UMBRELLA_HEADER); @@ -653,21 +558,6 @@ public SkylarkNestedSet weakSdkFramework() { get(WEAK_SDK_FRAMEWORK)); } - @Override - public SkylarkNestedSet xcassetsDir() { - return ObjcProviderSkylarkConverters.convertPathFragmentsToSkylark(get(XCASSETS_DIR)); - } - - @Override - public NestedSet xcdatamodel() { - return get(XCDATAMODEL); - } - - @Override - public NestedSet xib() { - return get(XIB); - } - /** * All keys in ObjcProvider that are explicitly not exposed to skylark. This is used for * testing and verification purposes to ensure that a conscious decision is made for all keys; @@ -680,8 +570,6 @@ public NestedSet xib() { CC_LIBRARY, // Flag enum is not exposed to skylark. FLAG, - // Bundle not exposed to skylark. - NESTED_BUNDLE, // CppModuleMap is not exposed to skylark. TOP_LEVEL_MODULE_MAP); @@ -701,7 +589,6 @@ public NestedSet xib() { DYNAMIC_FRAMEWORK_FILE, FLAG, MERGE_ZIP, - ROOT_MERGE_ZIP, FRAMEWORK_SEARCH_PATH_ONLY, HEADER, INCLUDE, @@ -726,10 +613,6 @@ static Key getSkylarkKeyForString(String keyName) { return null; } - static boolean isDeprecatedResourceKey(Key key) { - return DEPRECATED_RESOURCE_KEYS.contains(key); - } - /** Skylark constructor and identifier for ObjcProvider. */ public static final BuiltinProvider SKYLARK_CONSTRUCTOR = new Constructor(); @@ -808,14 +691,6 @@ public boolean is(Flag flag) { return Iterables.contains(get(FLAG), flag); } - /** - * Indicates whether this provider has any asset catalogs. This is true whenever some target in - * its transitive dependency tree specifies a non-empty {@code asset_catalogs} attribute. - */ - public boolean hasAssetCatalogs() { - return !get(XCASSETS_DIR).isEmpty(); - } - /** Returns the list of .a files required for linking that arise from objc libraries. */ ImmutableList getObjcLibraries() { // JRE libraries must be ordered after all regular objc libraries. diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java index 7f49e5e4bcbe68..ef745d601778ae 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java @@ -15,19 +15,13 @@ package com.google.devtools.build.lib.rules.objc; import static com.google.devtools.build.lib.rules.objc.AppleSkylarkCommon.BAD_SET_TYPE_ERROR; -import static com.google.devtools.build.lib.rules.objc.AppleSkylarkCommon.MISSING_KEY_ERROR; import static com.google.devtools.build.lib.rules.objc.AppleSkylarkCommon.NOT_SET_ERROR; -import static com.google.devtools.build.lib.rules.objc.BundleableFile.BUNDLED_FIELD; -import static com.google.devtools.build.lib.rules.objc.BundleableFile.BUNDLE_PATH_FIELD; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.packages.StructImpl; -import com.google.devtools.build.lib.packages.StructProvider; import com.google.devtools.build.lib.rules.objc.ObjcProvider.Key; -import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.EvalUtils; import com.google.devtools.build.lib.syntax.SkylarkNestedSet; import com.google.devtools.build.lib.syntax.SkylarkType; @@ -48,7 +42,6 @@ public class ObjcProviderSkylarkConverters { .put(String.class, new DirectConverter()) .put(PathFragment.class, new PathFragmentToStringConverter()) .put(SdkFramework.class, new SdkFrameworkToStringConverter()) - .put(BundleableFile.class, new BundleableFileToStructConverter()) .build(); /** @@ -160,52 +153,6 @@ public Iterable valueForJava(Key javaKey, Object skylarkValue) { } } - /** - * A converter that that translates between a java BundleableFile and a skylark struct. - */ - private static class BundleableFileToStructConverter implements Converter { - - @SuppressWarnings("unchecked") - @Override - public Object valueForSkylark(Key javaKey, NestedSet javaValue) { - NestedSetBuilder result = NestedSetBuilder.stableOrder(); - for (BundleableFile bundleableFile : (Iterable) javaValue) { - result.add( - StructProvider.STRUCT.create( - ImmutableMap.of( - BUNDLED_FIELD, bundleableFile.getBundled(), - BUNDLE_PATH_FIELD, bundleableFile.getBundlePath()), - "No such attribute '%s'")); - } - return SkylarkNestedSet.of(StructImpl.class, result.build()); - } - - @SuppressWarnings("unchecked") - @Override - public Iterable valueForJava(Key javaKey, Object skylarkValue) { - validateTypes(skylarkValue, StructImpl.class, javaKey.getSkylarkKeyName()); - NestedSetBuilder result = NestedSetBuilder.stableOrder(); - for (StructImpl struct : ((SkylarkNestedSet) skylarkValue).toCollection(StructImpl.class)) { - Artifact artifact; - String path; - try { - artifact = struct.getValue(BUNDLED_FIELD, Artifact.class); - path = struct.getValue(BUNDLE_PATH_FIELD, String.class); - } catch (EvalException e) { - throw new IllegalArgumentException(e.getMessage()); - } - if (artifact == null) { - throw new IllegalArgumentException(String.format(MISSING_KEY_ERROR, BUNDLED_FIELD)); - } - if (path == null) { - throw new IllegalArgumentException(String.format(MISSING_KEY_ERROR, BUNDLE_PATH_FIELD)); - } - result.add(new BundleableFile(artifact, path)); - } - return result.build(); - } - } - /** * Throws an error if the given object is not a nested set of the given type. */ 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 0f0260bef52c0a..c30cf086241fd8 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 @@ -330,20 +330,9 @@ public Metadata getMetadata() { static final FileTypeSet NON_ARC_SRCS_TYPE = FileTypeSet.of(FileType.of(".m", ".mm")); - static final FileTypeSet PLIST_TYPE = FileTypeSet.of(FileType.of(".plist")); - - static final FileType STORYBOARD_TYPE = FileType.of(".storyboard"); - - static final FileType XIB_TYPE = FileType.of(".xib"); - // TODO(bazel-team): Restrict this to actual header files only. static final FileTypeSet HDRS_TYPE = FileTypeSet.ANY_FILE; - static final FileTypeSet ENTITLEMENTS_TYPE = - FileTypeSet.of(FileType.of(".entitlements", ".plist")); - - static final FileTypeSet STRINGS_TYPE = FileTypeSet.of(FileType.of(".strings")); - /** * Coverage note files which contain information to reconstruct the basic block graphs and assign * source line numbers to blocks. diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java b/src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java deleted file mode 100644 index 80eecdf3db679f..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/PlMergeControlBytes.java +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteSource; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.collect.nestedset.Order; -import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos; -import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import javax.annotation.Nullable; - -/** - * A byte source that can be used the generate a control file for the tool plmerge. - */ -public final class PlMergeControlBytes extends ByteSource { - - private final NestedSet inputPlists; - private final NestedSet immutableInputPlists; - @Nullable private final String primaryBundleId; - @Nullable private final String fallbackBundleId; - @Nullable private final Map variableSubstitutions; - @Nullable private final String executableName; - private final Artifact mergedPlist; - private final OutputFormat outputFormat; - - /** - * Creates a control based on the passed bundling's plists and values. - * - * @param bundling bundle for which to create a merged plist - * @param mergedPlist the plist that should be created as an output - */ - static PlMergeControlBytes fromBundling(Bundling bundling, Artifact mergedPlist) { - - NestedSetBuilder immutableInputPlists = NestedSetBuilder.stableOrder(); - if (bundling.getAutomaticInfoPlist() != null) { - immutableInputPlists.add(bundling.getAutomaticInfoPlist()); - } - - return new PlMergeControlBytes( - NestedSetBuilder.stableOrder() - .addTransitive(bundling.getBundleInfoplistInputs()) - .build(), - immutableInputPlists.build(), - bundling.getPrimaryBundleId(), - bundling.getFallbackBundleId(), - bundling.variableSubstitutions(), - bundling.getExecutableName(), - mergedPlist, - OutputFormat.BINARY); - } - - /** - * Creates a control that merges the given plists into the merged plist. - */ - static PlMergeControlBytes fromPlists( - NestedSet inputPlists, - Artifact mergedPlist, - OutputFormat outputFormat) { - return new PlMergeControlBytes( - inputPlists, - NestedSetBuilder.emptySet(Order.STABLE_ORDER), - null, - null, - ImmutableMap.of(), - null, - mergedPlist, - outputFormat); - } - - private PlMergeControlBytes( - NestedSet inputPlists, - NestedSet immutableInputPlists, - @Nullable String primaryBundleId, - @Nullable String fallbackBundleId, - @Nullable Map variableSubstitutions, - @Nullable String executableName, - Artifact mergedPlist, - OutputFormat outputFormat) { - this.inputPlists = inputPlists; - this.immutableInputPlists = immutableInputPlists; - this.primaryBundleId = primaryBundleId; - this.fallbackBundleId = fallbackBundleId; - this.variableSubstitutions = variableSubstitutions; - this.executableName = executableName; - this.mergedPlist = mergedPlist; - this.outputFormat = Preconditions.checkNotNull(outputFormat); - } - - @Override - public InputStream openStream() throws IOException { - return control().toByteString().newInput(); - } - - private Control control() { - PlMergeProtos.Control.Builder control = - PlMergeProtos.Control.newBuilder() - .addAllSourceFile(Artifact.toExecPaths(inputPlists)) - .addAllImmutableSourceFile(Artifact.toExecPaths(immutableInputPlists)) - .putAllVariableSubstitutionMap(variableSubstitutions) - .setOutFile(mergedPlist.getExecPathString()); - - if (primaryBundleId != null) { - control.setPrimaryBundleId(primaryBundleId); - } - - if (fallbackBundleId != null) { - control.setFallbackBundleId(fallbackBundleId); - } - - if (executableName != null) { - control.setExecutableName(executableName); - } - - control.setOutputFormat(outputFormat.getProtoOutputFormat()); - - return control.build(); - } - - /** - * Plist output formats. - */ - public enum OutputFormat { - BINARY(Control.OutputFormat.BINARY), - XML(Control.OutputFormat.XML); - - private final Control.OutputFormat protoOutputFormat; - - private OutputFormat(Control.OutputFormat protoOutputFormat) { - this.protoOutputFormat = protoOutputFormat; - } - - Control.OutputFormat getProtoOutputFormat() { - return protoOutputFormat; - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamily.java b/src/main/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamily.java deleted file mode 100644 index a9ea744f5e0966..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamily.java +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - -/** - * Possible values in the {@code TARGETED_DEVICE_FAMILY} build setting. - */ -public enum TargetDeviceFamily { - IPAD, IPHONE, WATCH; - - /** - * An exception that indicates the name of a device family was not recognized or is somehow - * invalid. - */ - public static class InvalidFamilyNameException extends IllegalArgumentException { - public InvalidFamilyNameException(String message) { - super(message); - } - } - - /** - * An exception that indicates a family name appeared twice in a sequence when only one is - * expected. - */ - public static class RepeatedFamilyNameException extends IllegalArgumentException { - public RepeatedFamilyNameException(String message) { - super(message); - } - } - - /** - * Contains the values of the UIDeviceFamily plist info setting for each valid set of - * TargetDeviceFamilies. - */ - public static final ImmutableMap, List> UI_DEVICE_FAMILY_VALUES = - ImmutableMap., List>builder() - .put(ImmutableSet.of(TargetDeviceFamily.IPHONE), ImmutableList.of(1)) - .put(ImmutableSet.of(TargetDeviceFamily.IPAD), ImmutableList.of(2)) - .put(ImmutableSet.of(TargetDeviceFamily.WATCH), ImmutableList.of(4)) - .put( - ImmutableSet.of(TargetDeviceFamily.IPHONE, TargetDeviceFamily.IPAD), - ImmutableList.of(1, 2)) - .put( - ImmutableSet.of(TargetDeviceFamily.IPHONE, TargetDeviceFamily.WATCH), - ImmutableList.of(1, 4)) - .build(); - - /** - * Returns the name of the family as it appears in build rules. - */ - public String getNameInRule() { - return BY_NAME_IN_RULE.get(this); - } - - private static final ImmutableBiMap BY_NAME_IN_RULE = - ImmutableBiMap.of(IPAD, "ipad", IPHONE, "iphone", WATCH, "watch"); - - /** - * Converts a sequence containing the strings returned by {@link #getNameInRule()} to a set of - * instances of this enum. - * - *

If there are multiple items in the returned set, they are in enumeration order. - * - * @param names the names of the families - * @throws InvalidFamilyNameException if some family name in the sequence was not recognized - * @throws RepeatedFamilyNameException if some family name appeared in the sequence twice - */ - public static Set fromNamesInRule(Iterable names) { - Set families = EnumSet.noneOf(TargetDeviceFamily.class); - for (String name : names) { - TargetDeviceFamily family = BY_NAME_IN_RULE.inverse().get(name); - if (family == null) { - throw new InvalidFamilyNameException(name); - } - if (!families.add(family)) { - throw new RepeatedFamilyNameException(name); - } - } - return families; - } - - /** - * Converts the {@code TARGETED_DEVICE_FAMILY} setting in build settings to a set of - * {@code TargetedDevice}s. - */ - public static Set fromBuildSetting(String targetedDevice) { - ImmutableSet.Builder result = ImmutableSet.builder(); - for (String numericSetting : Splitter.on(',').split(targetedDevice)) { - numericSetting = numericSetting.trim(); - switch (numericSetting) { - case "1": - result.add(IPHONE); - break; - case "2": - result.add(IPAD); - break; - default: - throw new IllegalArgumentException( - "Expect comma-separated list containing only '1' and/or '2' for " - + "TARGETED_DEVICE_FAMILY: " + targetedDevice); - } - } - return result.build(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodel.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodel.java deleted file mode 100644 index e4b13c7409a7c6..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodel.java +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.vfs.PathFragment; - -/** - * Represents an .xcdatamodel[d] directory - knowing all {@code Artifact}s contained therein - and - * the .zip file that it is compiled to which should be merged with the final application bundle. - *

- * An .xcdatamodel (here and below note that lack or presence of a d) directory contains the schema - * for a managed object, or a managed object model. It typically has two files: {@code layout} and - * {@code contents}, although this detail isn't addressed in Bazel code. Directories of this - * sort are compiled into a single .mom file. If the .xcdatamodel directory is inside a - * .xcdatamodeld directory, then the .mom file is placed inside a .momd directory. The .momd - * directory or .mom file is placed in the bundle root of the final bundle. - *

- * An .xcdatamodeld directory contains several .xcdatamodel directories, each corresponding to a - * different version. In addition the .xcdatamodeld directory contains a {@code .xccurrentversion} - * file which identifies the current version. (this file is also not handled explicitly by Bazel - * code). - *

- * When processing artifacts referenced by a {@code datamodels} attribute, we must determine if it - * is in a .xcdatamodeld directory or only a .xcdatamodel directory. We also must group the - * artifacts by their container, the container being an .xcdatamodeld directory if possible, and a - * .xcdatamodel directory otherwise. Every container is compiled with a single invocation of the - * Managed Object Model Compiler (momc) and corresponds to exactly one instance of this class. We - * invoke momc indirectly through the momczip tool (part of Bazel) which runs momc and zips the - * output. The files in this zip are placed in the bundle root of the final application, not unlike - * the zips generated by {@code actoolzip} or {@code ibtoolzip}. - */ -class Xcdatamodel extends Value { - private final Artifact outputZip; - private final ImmutableSet inputs; - private final PathFragment container; - - Xcdatamodel(Artifact outputZip, ImmutableSet inputs, PathFragment container) { - super(ImmutableMap.of( - "outputZip", outputZip, - "inputs", inputs, - "container", container)); - this.outputZip = outputZip; - this.inputs = inputs; - this.container = container; - } - - public Artifact getOutputZip() { - return outputZip; - } - - /** - * Returns every known file in the container. This is every input file that is processed by momc. - */ - public ImmutableSet getInputs() { - return inputs; - } - - public PathFragment getContainer() { - return container; - } - - /** - * The ARCHIVE_ROOT passed to momczip. The archive root is the name of the .mom file - * unversioned object models, and the name of the .momd directory for versioned object models. - */ - public String archiveRootForMomczip() { - return name() + (container.getBaseName().endsWith(".xcdatamodeld") ? ".momd" : ".mom"); - } - - /** - * The name of the data model. This is the name of the container without the extension. For - * instance, if the container is "foo/Information.xcdatamodel" or "bar/Information.xcdatamodeld", - * then the name is "Information". - */ - public String name() { - String baseContainerName = container.getBaseName(); - int lastDot = baseContainerName.lastIndexOf('.'); - return baseContainerName.substring(0, lastDot); - } - - public static Iterable outputZips(Iterable models) { - return Iterables.transform(models, Xcdatamodel::getOutputZip); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodels.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodels.java deleted file mode 100644 index a5138e8ac16c7f..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/Xcdatamodels.java +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.Multimap; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.util.FileType; -import com.google.devtools.build.lib.vfs.PathFragment; - -import java.util.Collection; -import java.util.Map; - -/** - * Utility code for getting information specific to xcdatamodels for a single rule. - */ -class Xcdatamodels { - private Xcdatamodels() {} - - static final ImmutableList CONTAINER_TYPES = - ImmutableList.of(FileType.of(".xcdatamodeld"), FileType.of(".xcdatamodel")); - - static Iterable datamodelDirs(Iterable xcdatamodels) { - ImmutableSet.Builder result = new ImmutableSet.Builder<>(); - for (Collection artifacts : byContainer(xcdatamodels).asMap().values()) { - result.addAll(ObjcCommon.uniqueContainers(artifacts, FileType.of(".xcdatamodel"))); - } - return result.build(); - } - - static Iterable xcdatamodels( - IntermediateArtifacts intermediateArtifacts, Iterable xcdatamodels) { - ImmutableSet.Builder result = new ImmutableSet.Builder<>(); - Multimap artifactsByContainer = byContainer(xcdatamodels); - - for (Map.Entry> modelDirEntry : - artifactsByContainer.asMap().entrySet()) { - PathFragment container = modelDirEntry.getKey(); - Artifact outputZip = intermediateArtifacts.compiledMomZipArtifact(container); - result.add( - new Xcdatamodel(outputZip, ImmutableSet.copyOf(modelDirEntry.getValue()), container)); - } - - return result.build(); - } - - - /** - * Arrange a sequence of artifacts into entries of a multimap by their nearest container - * directory, preferring {@code .xcdatamodeld} over {@code .xcdatamodel}. - * If an artifact is not inside any containing directory, then it is not present in the returned - * map. - */ - static Multimap byContainer(Iterable artifacts) { - ImmutableSetMultimap.Builder result = - new ImmutableSetMultimap.Builder<>(); - for (Artifact artifact : artifacts) { - for (PathFragment modelDir : - ObjcCommon.nearestContainerMatching(CONTAINER_TYPES, artifact).asSet()) { - result.put(modelDir, artifact); - } - } - return result.build(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java index 55540050e21093..dcfc6c3621d1ff 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/ObjcProviderApi.java @@ -35,22 +35,6 @@ ) public interface ObjcProviderApi extends SkylarkValue { - @SkylarkCallable( - name = "asset_catalog", - structField = true, - doc = - "Asset catalog resource files.", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public NestedSet assetCatalog(); - - @SkylarkCallable( - name = "bundle_file", - structField = true, - doc = - "Files that are plopped into the final bundle at some arbitrary bundle path.", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public SkylarkNestedSet bundleFile(); - @SkylarkCallable(name = "define", structField = true, doc = "A set of strings from 'defines' attributes. These are to be passed as '-D' flags to " @@ -218,14 +202,6 @@ public interface ObjcProviderApi extends SkylarkValue ) public NestedSet multiArchLinkedBinaries(); - @SkylarkCallable( - name = "root_merge_zip", - structField = true, - doc = - "Merge zips to include in the ipa and outside the bundle root.", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public NestedSet rootMergeZip(); - @SkylarkCallable(name = "sdk_dylib", structField = true, doc = "Names of SDK .dylib libraries to link with. For instance, 'libz' or 'libarchive'." @@ -256,22 +232,6 @@ public interface ObjcProviderApi extends SkylarkValue doc = "The library files in .framework directories that should be statically linked.") public NestedSet staticFrameworkFile(); - @SkylarkCallable( - name = "storyboard", - structField = true, - doc = - "Files for storyboard sources.", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public NestedSet storyboard(); - - @SkylarkCallable( - name = "strings", - structField = true, - doc = - "Files for strings source files.", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public NestedSet strings(); - @SkylarkCallable(name = "umbrella_header", structField = true, doc = "Clang umbrella header. Public headers are #included in umbrella headers to be " @@ -288,31 +248,6 @@ public interface ObjcProviderApi extends SkylarkValue + "frameworks do not cause an error if they are not present at runtime.") public SkylarkNestedSet weakSdkFramework(); - @SkylarkCallable( - name = "xcassets_dir", - structField = true, - doc = - "The set of all unique asset catalog directories (*.xcassets) containing files " - + "in 'asset_catalogs'.", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public SkylarkNestedSet xcassetsDir(); - - @SkylarkCallable( - name = "xcdatamodel", - structField = true, - doc = - "Files that comprise the data models of the final linked binary.", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public NestedSet xcdatamodel(); - - @SkylarkCallable( - name = "xib", - structField = true, - doc = - ".xib resource files", - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) - public NestedSet xib(); - @SkylarkCallable( name = "framework_dir", structField = true, diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/apple/FakeObjcProvider.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/apple/FakeObjcProvider.java index 03c3ace91a2553..f58f7a0f45ef9a 100644 --- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/apple/FakeObjcProvider.java +++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/apple/FakeObjcProvider.java @@ -26,16 +26,6 @@ */ public class FakeObjcProvider implements ObjcProviderApi { - @Override - public NestedSet assetCatalog() { - return null; - } - - @Override - public SkylarkNestedSet bundleFile() { - return null; - } - @Override public NestedSet define() { return null; @@ -161,11 +151,6 @@ public NestedSet multiArchLinkedBinaries() { return null; } - @Override - public NestedSet rootMergeZip() { - return null; - } - @Override public NestedSet sdkDylib() { return null; @@ -191,16 +176,6 @@ public NestedSet staticFrameworkFile() { return null; } - @Override - public NestedSet storyboard() { - return null; - } - - @Override - public NestedSet strings() { - return null; - } - @Override public NestedSet umbrellaHeader() { return null; @@ -211,21 +186,6 @@ public SkylarkNestedSet weakSdkFramework() { return null; } - @Override - public SkylarkNestedSet xcassetsDir() { - return null; - } - - @Override - public NestedSet xcdatamodel() { - return null; - } - - @Override - public NestedSet xib() { - return null; - } - @Override public SkylarkNestedSet getStaticFrameworkDirsForSkylark() { return null; diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java index 468bfdf057f7e2..b6d291002cc522 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java @@ -1353,138 +1353,6 @@ public void testMultiArchSplitTransition() throws Exception { .contains("ios_arm64"); } - @Test - public void testDisableObjcProviderResourcesWrite() throws Exception { - scratch.file("examples/rule/BUILD"); - scratch.file( - "examples/rule/apple_rules.bzl", - "def my_rule_impl(ctx):", - " file = ctx.actions.declare_file('foo.ast')", - " ctx.actions.run_shell(outputs=[file], command='echo')", - " objc_provider = apple_common.new_objc_provider(xib=depset([file]))", - " return objc_provider", - "my_rule = rule(implementation = my_rule_impl,", - " attrs = {})"); - - scratch.file( - "examples/apple_skylark/BUILD", - "package(default_visibility = ['//visibility:public'])", - "load('//examples/rule:apple_rules.bzl', 'my_rule')", - "my_rule(", - " name='my_target',", - ")"); - - try { - setSkylarkSemanticsOptions("--incompatible_disable_objc_provider_resources=true"); - getConfiguredTarget("//examples/apple_skylark:my_target"); - } catch (AssertionError e) { - assertThat(e) - .hasMessageThat() - .contains("Argument xib not a recognized key"); - } - } - - @Test - public void testEnabledObjcProviderResourcesWrite() throws Exception { - scratch.file("examples/rule/BUILD"); - scratch.file( - "examples/rule/apple_rules.bzl", - "def my_rule_impl(ctx):", - " file = ctx.actions.declare_file('foo.ast')", - " ctx.actions.run_shell(outputs=[file], command='echo')", - " objc_provider = apple_common.new_objc_provider(xib=depset([file]))", - " return objc_provider", - "my_rule = rule(implementation = my_rule_impl,", - " attrs = {})"); - - scratch.file( - "examples/apple_skylark/BUILD", - "package(default_visibility = ['//visibility:public'])", - "load('//examples/rule:apple_rules.bzl', 'my_rule')", - "my_rule(", - " name='my_target',", - ")"); - - setSkylarkSemanticsOptions("--incompatible_disable_objc_provider_resources=false"); - ConfiguredTarget binaryTarget = getConfiguredTarget("//examples/apple_skylark:my_target"); - - ObjcProvider objcProvider = binaryTarget.get(ObjcProvider.SKYLARK_CONSTRUCTOR); - - assertThat(objcProvider.get(ObjcProvider.XIB)).isNotNull(); - } - - @Test - public void testDisableObjcProviderResourcesRead() throws Exception { - reporter.removeHandler(failFastHandler); - scratch.file("examples/rule/BUILD"); - scratch.file( - "examples/rule/apple_rules.bzl", - "load('//myinfo:myinfo.bzl', 'MyInfo')", - "def my_rule_impl(ctx):", - " dep = ctx.attr.deps[0]", - " objc_provider = dep[apple_common.Objc]", - " return MyInfo(strings=str(objc_provider.strings))", - "my_rule = rule(implementation = my_rule_impl,", - " attrs = {", - " 'deps': attr.label_list(providers = ['objc'])})"); - - scratch.file("examples/apple_skylark/foo.strings"); - scratch.file("examples/apple_skylark/bar.a"); - scratch.file( - "examples/apple_skylark/BUILD", - "package(default_visibility = ['//visibility:public'])", - "load('//examples/rule:apple_rules.bzl', 'my_rule')", - "my_rule(", - " name='my_target',", - " deps=[':bundle_lib'],", - ")", - "objc_import(", - " name='bundle_lib',", - " archives = ['bar.a'],", - ")"); - - setSkylarkSemanticsOptions("--incompatible_disable_objc_provider_resources=true"); - - getConfiguredTarget("//examples/apple_skylark:my_target"); - - assertContainsEvent("object of type 'ObjcProvider' has no field 'strings'"); - } - - @Test - public void testEnabledObjcProviderResourcesRead() throws Exception { - scratch.file("examples/rule/BUILD"); - scratch.file( - "examples/rule/apple_rules.bzl", - "load('//myinfo:myinfo.bzl', 'MyInfo')", - "def my_rule_impl(ctx):", - " dep = ctx.attr.deps[0]", - " objc_provider = dep[apple_common.Objc]", - " return MyInfo(strings=str(objc_provider.strings))", - "my_rule = rule(implementation = my_rule_impl,", - " attrs = {", - " 'deps': attr.label_list(providers = ['objc'])})"); - - scratch.file("examples/apple_skylark/foo.strings"); - scratch.file("examples/apple_skylark/bar.a"); - scratch.file( - "examples/apple_skylark/BUILD", - "package(default_visibility = ['//visibility:public'])", - "load('//examples/rule:apple_rules.bzl', 'my_rule')", - "my_rule(", - " name='my_target',", - " deps=[':bundle_lib'],", - ")", - "objc_import(", - " name='bundle_lib',", - " archives = ['bar.a'],", - ")"); - - setSkylarkSemanticsOptions("--incompatible_disable_objc_provider_resources=false"); - ConfiguredTarget skylarkTarget = getConfiguredTarget("//examples/apple_skylark:my_target"); - - assertThat(getMyInfoFromTarget(skylarkTarget).getValue("strings")).isEqualTo("depset([])"); - } - private void checkSkylarkRunMemleaksWithExpectedValue(boolean expectedValue) throws Exception { scratch.file("examples/rule/BUILD"); scratch.file( diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamilyTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamilyTest.java deleted file mode 100644 index 363e31ec32ee13..00000000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/TargetDeviceFamilyTest.java +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.objc; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.InvalidFamilyNameException; -import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.RepeatedFamilyNameException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Unit tests for {@link TargetDeviceFamily}. - */ -@RunWith(JUnit4.class) -public class TargetDeviceFamilyTest { - @Test - public void uiDeviceFamilyValuesUndefinedForEmpty() { - assertThat(TargetDeviceFamily.UI_DEVICE_FAMILY_VALUES.keySet()) - .doesNotContain(ImmutableSet.of()); - } - - @Test - public void fromBuildSettings() { - assertThat(TargetDeviceFamily.fromBuildSetting("1,2")) - .isEqualTo(ImmutableSet.of(TargetDeviceFamily.IPAD, TargetDeviceFamily.IPHONE)); - assertThat(TargetDeviceFamily.fromBuildSetting(" 1, 2")) - .isEqualTo(ImmutableSet.of(TargetDeviceFamily.IPAD, TargetDeviceFamily.IPHONE)); - assertThat(TargetDeviceFamily.fromBuildSetting("1,2\n")) - .isEqualTo(ImmutableSet.of(TargetDeviceFamily.IPAD, TargetDeviceFamily.IPHONE)); - assertThat(TargetDeviceFamily.fromBuildSetting("1")) - .isEqualTo(ImmutableSet.of(TargetDeviceFamily.IPHONE)); - assertThat(TargetDeviceFamily.fromBuildSetting("2")) - .isEqualTo(ImmutableSet.of(TargetDeviceFamily.IPAD)); - } - - private void checkFromNamesInRuleThrows( - Class expectedClass, String... names) { - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> TargetDeviceFamily.fromNamesInRule(ImmutableList.copyOf(names))); - assertThat(expected.getClass()).isEqualTo(expectedClass); - } - - @Test - public void fromNamesInRule_errors() { - checkFromNamesInRuleThrows(InvalidFamilyNameException.class, "foo"); - checkFromNamesInRuleThrows(InvalidFamilyNameException.class, "foo", "bar"); - checkFromNamesInRuleThrows(InvalidFamilyNameException.class, "iphone", "ipad", "bar"); - checkFromNamesInRuleThrows(RepeatedFamilyNameException.class, "iphone", "iphone"); - checkFromNamesInRuleThrows(RepeatedFamilyNameException.class, "ipad", "ipad"); - } - - @Test - public void fromNamesInRule() { - assertThat(TargetDeviceFamily.fromNamesInRule(ImmutableList.of())) - .isEmpty(); - assertThat(TargetDeviceFamily.fromNamesInRule(ImmutableList.of("iphone", "ipad"))) - .containsExactly(TargetDeviceFamily.IPAD, TargetDeviceFamily.IPHONE) - .inOrder(); - assertThat(TargetDeviceFamily.fromNamesInRule(ImmutableList.of("ipad", "iphone"))) - .containsExactly(TargetDeviceFamily.IPAD, TargetDeviceFamily.IPHONE) - .inOrder(); - assertThat(TargetDeviceFamily.fromNamesInRule(ImmutableList.of("iphone"))) - .containsExactly(TargetDeviceFamily.IPHONE); - assertThat(TargetDeviceFamily.fromNamesInRule(ImmutableList.of("ipad"))) - .containsExactly(TargetDeviceFamily.IPAD); - } -}