From f020ffb4e9647d3ebb19ab2d57d43afef6088ce2 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Wed, 22 Apr 2020 20:58:58 -0700 Subject: [PATCH] Enforce license info in src/brave (fixes brave/brave-browser#9408) Related upstream bug: https://bugs.chromium.org/p/chromium/issues/detail?id=39240 --- patches/tools-licenses.py.patch | 14 ++++++++++++-- script/brave_license_helper.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/patches/tools-licenses.py.patch b/patches/tools-licenses.py.patch index cfbb4c3a350..e0f28459bc9 100644 --- a/patches/tools-licenses.py.patch +++ b/patches/tools-licenses.py.patch @@ -1,12 +1,12 @@ diff --git a/tools/licenses.py b/tools/licenses.py -index 6405b31497a425c68b0486a2653071f23e515671..e957c14c924a7a405bf9e20f3c8e2ffc56ea1306 100755 +index 6405b31497a425c68b0486a2653071f23e515671..5402e94334b0ecb6ebcbefb9e4cd93b070eb5cbd 100755 --- a/tools/licenses.py +++ b/tools/licenses.py @@ -35,6 +35,7 @@ else: _REPOSITORY_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) sys.path.insert(0, os.path.join(_REPOSITORY_ROOT, 'build/android/gyp')) from util import build_utils -+from brave_license_helper import AddBraveCredits, BRAVE_THIRD_PARTY_DIRS ++from brave_license_helper import AddBraveCredits, BRAVE_THIRD_PARTY_DIRS, CheckBraveMissingLicense # Paths from the root of the tree to directories to skip. @@ -28,3 +28,13 @@ index 6405b31497a425c68b0486a2653071f23e515671..e957c14c924a7a405bf9e20f3c8e2ffc # Add all subdirectories that are not marked for skipping. for dir in dirs: dirpath = os.path.join(path, dir) +@@ -663,7 +666,8 @@ def GenerateCredits( + for path in third_party_dirs: + try: + metadata = ParseDir(path, _REPOSITORY_ROOT) +- except LicenseError: ++ except LicenseError as e: ++ CheckBraveMissingLicense(target_os, path, e) + # TODO(phajdan.jr): Convert to fatal error (http://crbug.com/39240). + continue + if metadata['License File'] == NOT_SHIPPED: diff --git a/script/brave_license_helper.py b/script/brave_license_helper.py index 88fe1512032..07ed81f5ca4 100644 --- a/script/brave_license_helper.py +++ b/script/brave_license_helper.py @@ -9,6 +9,14 @@ BRAVE_THIRD_PARTY_DIRS = [ 'vendor', ] +ANDROID_ONLY_PATHS = [ + os.path.join('brave', 'components', 'brave_sync', 'extension', 'brave-sync-android'), +] + +DESKTOP_ONLY_PATHS = [ + os.path.join('brave', 'components', 'brave_sync', 'extension', 'brave-sync'), +] + def AddBraveCredits(prune_paths, special_cases, prune_dirs, additional_paths): # Exclude these specific paths from needing a README.chromium file. @@ -149,3 +157,14 @@ def AddBraveCredits(prune_paths, special_cases, prune_dirs, additional_paths): additional_paths = tuple(additional_list) return (prune_dirs, additional_paths) + + +def CheckBraveMissingLicense(target_os, path, error): + if path.startswith('brave'): + if (target_os == 'android'): + if path in DESKTOP_ONLY_PATHS: + return # Desktop failures are not relevant on Android. + else: + if path in ANDROID_ONLY_PATHS: + return # Android failures are not relevant on desktop. + raise error