Bug 1377543 - Fix find-dupes to exclude l10n. r?catlee draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Sun, 09 Jul 2017 16:29:01 -0700
changeset 605872 94d68fc33926da49821caa6b5f943dda77e2baf5
parent 604348 ed438053201937afc04589ca66417bb1644c09a0
child 636609 d735793b2337b2840e0322bde26113d01869ed2e
push id67534
push userbmo:gandalf@aviary.pl
push dateSun, 09 Jul 2017 23:29:14 +0000
reviewerscatlee
bugs1377543
milestone56.0a1
Bug 1377543 - Fix find-dupes to exclude l10n. r?catlee MozReview-Commit-ID: HPpCVcEeQ2s
toolkit/mozapps/installer/find-dupes.py
--- a/toolkit/mozapps/installer/find-dupes.py
+++ b/toolkit/mozapps/installer/find-dupes.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import sys
 import hashlib
 import re
+import os
 from mozbuild.preprocessor import Preprocessor
 from mozbuild.util import DefinesAction
 from mozpack.packager.unpack import UnpackFinder
 from mozpack.files import DeflatedFile
 from collections import OrderedDict
 from StringIO import StringIO
 import argparse
 import buildconfig
@@ -27,39 +28,21 @@ def normalize_osx_path(p):
     >>> normalize_osx_path('Nightly.app/foo/bar/baz')
     'baz'
     '''
     bits = p.split('/')
     if len(bits) > 3 and bits[0].endswith('.app'):
         return '/'.join(bits[3:])
     return p
 
-
-def normalize_l10n_path(p):
-    '''
-    Normalizes localized paths to en-US
-
-    >>> normalize_l10n_path('chrome/es-ES/locale/branding/brand.properties')
-    'chrome/en-US/locale/branding/brand.properties'
-    >>> normalize_l10n_path('chrome/fr/locale/fr/browser/aboutHome.dtd')
-    'chrome/en-US/locale/en-US/browser/aboutHome.dtd'
-    '''
-    # Keep a trailing slash here! e.g. locales like 'br' can transform
-    # 'chrome/br/locale/branding/' into 'chrome/en-US/locale/en-USanding/'
-    p = re.sub(r'chrome/(\S+)/locale/\1/',
-               'chrome/en-US/locale/en-US/',
-               p)
-    p = re.sub(r'chrome/(\S+)/locale/',
-               'chrome/en-US/locale/',
-               p)
-    return p
-
+def is_l10n_file(path):
+    return '/locale/' in path
 
 def normalize_path(p):
-    return normalize_osx_path(normalize_l10n_path(p))
+    return normalize_osx_path(p)
 
 
 def find_dupes(source, allowed_dupes, bail=True):
     allowed_dupes = set(allowed_dupes)
     md5s = OrderedDict()
     for p, f in UnpackFinder(source):
         content = f.open().read()
         m = hashlib.md5(content).digest()
@@ -80,17 +63,19 @@ def find_dupes(source, allowed_dupes, ba
             print 'Duplicates %d bytes%s%s:' % (size,
                   ' (%d compressed)' % compressed if compressed != size else '',
                   ' (%d times)' % (len(paths) - 1) if len(paths) > 2 else '')
             print ''.join('  %s\n' % p for p in paths)
             total += (len(paths) - 1) * size
             total_compressed += (len(paths) - 1) * compressed
             num_dupes += 1
 
-            unexpected_dupes.extend([p for p in paths if normalize_path(p) not in allowed_dupes])
+            for p in paths:
+                if not is_l10n_file(p) and normalize_path(p) not in allowed_dupes:
+                    unexpected_dupes.append(p)
 
     if num_dupes:
         print "WARNING: Found %d duplicated files taking %d bytes (%s)" % \
               (num_dupes, total,
                '%d compressed' % total_compressed if total_compressed != total
                                                   else 'uncompressed')
 
     if unexpected_dupes: