Update package lookup to check for files named BUILD.bazel before files named
BUILD.

Fixes #552.

RELNOTES[NEW]: Packages are defined in BUILD.bazel as well as BUILD files.

--
MOS_MIGRATED_REVID=138828981
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
index c69cddf..0c4c1d4 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
@@ -71,12 +71,13 @@
   private MemoizingEvaluator evaluator;
   private SequentialBuildDriver driver;
   private RecordingDifferencer differencer;
+  private Path emptyPackagePath;
 
   protected abstract CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy();
 
   @Before
   public final void setUp() throws Exception {
-    Path emptyPackagePath = rootDirectory.getRelative("somewhere/else");
+    emptyPackagePath = rootDirectory.getRelative("somewhere/else");
     scratch.file("parentpackage/BUILD");
 
     AnalysisMock analysisMock = AnalysisMock.get();
@@ -92,7 +93,10 @@
     Map<SkyFunctionName, SkyFunction> skyFunctions = new HashMap<>();
     skyFunctions.put(
         SkyFunctions.PACKAGE_LOOKUP,
-        new PackageLookupFunction(deletedPackages, crossRepositoryLabelViolationStrategy()));
+        new PackageLookupFunction(
+            deletedPackages,
+            crossRepositoryLabelViolationStrategy(),
+            ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD)));
     skyFunctions.put(
         SkyFunctions.PACKAGE,
         new PackageFunction(null, null, null, null, null, null, null));
@@ -238,7 +242,7 @@
   }
 
   @Test
-  public void testEverythingIsGood() throws Exception {
+  public void testEverythingIsGood_BUILD() throws Exception {
     scratch.file("parentpackage/everythinggood/BUILD");
     PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood");
     assertTrue(packageLookupValue.packageExists());
@@ -247,6 +251,37 @@
   }
 
   @Test
+  public void testEverythingIsGood_BUILD_bazel() throws Exception {
+    scratch.file("parentpackage/everythinggood/BUILD.bazel");
+    PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood");
+    assertTrue(packageLookupValue.packageExists());
+    assertEquals(rootDirectory, packageLookupValue.getRoot());
+    assertEquals(BuildFileName.BUILD_DOT_BAZEL, packageLookupValue.getBuildFileName());
+  }
+
+  @Test
+  public void testEverythingIsGood_both() throws Exception {
+    scratch.file("parentpackage/everythinggood/BUILD");
+    scratch.file("parentpackage/everythinggood/BUILD.bazel");
+    PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood");
+    assertTrue(packageLookupValue.packageExists());
+    assertEquals(rootDirectory, packageLookupValue.getRoot());
+    assertEquals(BuildFileName.BUILD_DOT_BAZEL, packageLookupValue.getBuildFileName());
+  }
+
+  @Test
+  public void testBuildFilesInMultiplePackagePaths() throws Exception {
+    scratch.file(emptyPackagePath.getPathString() + "/foo/BUILD");
+    scratch.file("foo/BUILD.bazel");
+
+    // BUILD file in the first package path should be preferred to BUILD.bazel in the second.
+    PackageLookupValue packageLookupValue = lookupPackage("foo");
+    assertTrue(packageLookupValue.packageExists());
+    assertEquals(emptyPackagePath, packageLookupValue.getRoot());
+    assertEquals(BuildFileName.BUILD, packageLookupValue.getBuildFileName());
+  }
+
+  @Test
   public void testEmptyPackageName() throws Exception {
     scratch.file("BUILD");
     PackageLookupValue packageLookupValue = lookupPackage("");