aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar allevato <allevato@google.com>2017-05-08 15:09:56 -0400
committerGravatar Kristina Chodorow <kchodorow@google.com>2017-05-09 10:52:38 -0400
commit69044c06ff876f62faecef90a37d0b0a0b2eae40 (patch)
tree1ddff571b2a04ae894bd53f7137aedf2c9d7464c /src/test/java
parent1f75476f7a2f1abb449d538ef865f51ac138d013 (diff)
Handle labels with explicit repositories correctly in objc rules.
The `structured_resources` path stemming used by `objc_library` and `objc_bundle_library` no longer breaks if one of these rules tries to reference a label with an explicit repository prefix. Previously, using "@foo//bar:baz" in such a rule would fail because the individual files would retain their "external/foo/" prefix but the owner path against which those files were relativized would not have it because of the use of getPackageFragment() instead of getPackageIdentifier().getSourceRoot(). RELNOTES: None. PiperOrigin-RevId: 155409464
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/objc/ObjcCommonTest.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcCommonTest.java
new file mode 100644
index 0000000000..ce668797f9
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcCommonTest.java
@@ -0,0 +1,67 @@
+// 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 com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
+import com.google.devtools.build.lib.vfs.ModifiedFileSet;
+import com.google.devtools.build.lib.vfs.PathFragment;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** A test for {@link ObjcCommon}. */
+@RunWith(JUnit4.class)
+public class ObjcCommonTest extends BuildViewTestCase {
+
+ @Test
+ public void testObjcLibraryExternalStructuredResourcesNoErrors() throws Exception {
+ FileSystemUtils.appendIsoLatin1(
+ scratch.resolve("WORKSPACE"),
+ "local_repository(",
+ " name = 'pkg',",
+ " path = '/foo')");
+ getSkyframeExecutor()
+ .invalidateFilesUnderPathForTesting(
+ reporter,
+ new ModifiedFileSet.Builder().modify(PathFragment.create("WORKSPACE")).build(),
+ rootDirectory);
+ FileSystemUtils.createDirectoryAndParents(scratch.resolve("/foo/bar/nested"));
+ scratch.file("/foo/bar/nested/file.txt");
+ scratch.file("/foo/WORKSPACE", "workspace(name = 'pkg')");
+ scratch.file(
+ "/foo/bar/BUILD",
+ "objc_library(name = 'lib',",
+ " srcs = ['foo.cc'],",
+ " structured_resources = ['nested/file.txt'])");
+ Label label = Label.parseAbsolute("@pkg//bar:lib");
+ ConfiguredTarget target = view.getConfiguredTargetForTesting(reporter, label, targetConfig);
+ Artifact artifact = getSharedArtifact("external/pkg/bar/nested/file.txt", target);
+
+ // Verify that the xcodeStructuredResourceDirs call doesn't throw an exception and that the
+ // PathFragment it returns has the expected suffix, which includes the repository directory.
+ Iterable<Artifact> artifacts = ImmutableList.of(artifact);
+ Iterable<PathFragment> pathFragments = ObjcCommon.xcodeStructuredResourceDirs(artifacts);
+
+ assertThat(pathFragments.iterator().hasNext()).isTrue();
+ PathFragment fragment = pathFragments.iterator().next();
+ assertThat(fragment.endsWith(PathFragment.create("external/pkg/bar/nested"))).isTrue();
+ }
+}