Skip to content

Commit

Permalink
Enforce presence of licensing info for npm modules (fixes brave/brave…
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarier committed May 15, 2020
1 parent 6515d34 commit 11a5c27
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ components/brave_wayback_machine @simonhong

# Licensing of third-party components
common/licenses/ @fmarier
components/third_party/ @fmarier
script/brave_license_helper.py @fmarier
script/check_npm_licenses.py @fmarier
script/generate_licenses.py @fmarier

# Crypto Wallets
Expand Down
12 changes: 12 additions & 0 deletions components/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ grit("strings") {
output_dir = "$root_gen_dir/components"
resource_ids = "//brave/browser/resources/resource_ids"
}

action("about_credits") {
script = "//brave/script/check_npm_licenses.py"

inputs = [ "//brave/package.json" ]

outputs = [ "$root_gen_dir/npm_licenses.checked" ]

args = [
rebase_path("$root_gen_dir/npm_licenses.checked")
]
}
12 changes: 12 additions & 0 deletions patches/components-resources-BUILD.gn.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/components/resources/BUILD.gn b/components/resources/BUILD.gn
index d1645a13a358b64cefb80cfe1c8f0691a68e3204..8e07af1390e9d1a5999aa543e6537f5daa8b096b 100644
--- a/components/resources/BUILD.gn
+++ b/components/resources/BUILD.gn
@@ -73,6 +73,7 @@ grit("components_scaled_resources") {
}

action("about_credits") {
+ deps = [ "//brave/components/resources:about_credits" ]
script = "//tools/licenses.py"
depfile = "$target_gen_dir/$target_name.d"

57 changes: 57 additions & 0 deletions script/check_npm_licenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# Copyright (c) 2020 The Brave Authors. All rights reserved.
# 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 https://mozilla.org/MPL/2.0/. */

import argparse
import json
import os
import sys

from lib.config import SOURCE_ROOT


EXCLUSIONS = [
# Already covered by brave/third_party/npm-types
'@types/jszip',
'@types/parse-torrent',
'@types/webtorrent',
]


def check_dependency(module_name):
if module_name in EXCLUSIONS:
return True

third_party_dir = os.path.join(os.path.dirname(SOURCE_ROOT), 'brave', 'third_party')
readme_path = os.path.join(third_party_dir, 'npm_%s' % module_name, 'README.chromium')
if not os.path.isfile(readme_path):
print('npm module %s needs licensing information in %s' % (module_name, readme_path))
return False

return True


def main():
parser = argparse.ArgumentParser()
parser.add_argument('output_file', nargs='?')
args = parser.parse_args()

return_code = 0
package_json = os.path.join(os.path.dirname(SOURCE_ROOT), 'brave', 'package.json')
with open(package_json) as file_handle:
dependencies = json.loads(file_handle.read())["dependencies"]
for module_name in dependencies:
if not check_dependency(module_name):
return_code = 1

if args.output_file:
with open(args.output_file, 'wt') as file_handle:
file_handle.write('')

return return_code


if __name__ == '__main__':
sys.exit(main())

0 comments on commit 11a5c27

Please sign in to comment.