Allow changes without 9999 ebuild file changes

Currently, if any file within an 9999 ebuild directory is updated and
the ebuild itself isn't updated, the presubmit check fails.

This allows the change even if the ebuild itself isn't touched.
The ebuild will then be rev'd anyway based on the current behavior.

BUG=None
TEST=unit and change affected by this

Change-Id: I96d6d52a64dae84fffe76a779d84e6cd5c274e76
Reviewed-on: https://chromium-review.googlesource.com/671128
Commit-Ready: C Shapiro <shapiroc@google.com>
Tested-by: C Shapiro <shapiroc@google.com>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 2ef303f..3bd6f66 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -698,6 +698,17 @@
                for path in contents if path.endswith('.ebuild')]
     ebuilds_9999 = [path for path in ebuilds if path.endswith('-9999.ebuild')]
 
+    affected_paths_under_9999_ebuilds = set()
+    for affected_path in affected_paths:
+      for ebuild_9999 in ebuilds_9999:
+        ebuild_dir = os.path.dirname(ebuild_9999)
+        if affected_path.startswith(ebuild_dir):
+          affected_paths_under_9999_ebuilds.add(affected_path)
+
+    # If every file changed exists under a 9999 ebuild, then skip
+    if len(affected_paths_under_9999_ebuilds) == len(affected_paths):
+      continue
+
     # If the -9999.ebuild file was touched the bot will uprev for us.
     # ...we'll use a simple intersection here as a heuristic...
     if set(ebuilds_9999) & affected_paths:
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index 6e517d2..f212eac 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -1248,6 +1248,13 @@
     self.assertAccepted([DiffEntry(src_file='c/p/files/f', status='M'),
                          DiffEntry(src_file='c/p/p-9999.ebuild', status='M')])
 
+  def testModifiedFilesIn9999SubDirWithout9999Change(self):
+    """Accept changes in files/ with a parent 9999 ebuild"""
+    ebuild_9999_file = os.path.join(self.tempdir, 'c/p/p-9999.ebuild')
+    os.makedirs(os.path.dirname(ebuild_9999_file))
+    osutils.WriteFile(ebuild_9999_file, 'fake')
+    self.assertAccepted([DiffEntry(src_file='c/p/files/f', status='M')])
+
 
 class DirectMainTest(cros_test_lib.MockTempDirTestCase):
   """Tests for direct_main()"""