aboutsummaryrefslogtreecommitdiff
path: root/tools_webrtc/libs
diff options
context:
space:
mode:
Diffstat (limited to 'tools_webrtc/libs')
-rwxr-xr-xtools_webrtc/libs/generate_licenses.py15
-rwxr-xr-xtools_webrtc/libs/generate_licenses_test.py39
2 files changed, 32 insertions, 22 deletions
diff --git a/tools_webrtc/libs/generate_licenses.py b/tools_webrtc/libs/generate_licenses.py
index 6ed4e37147..cbb1514d3c 100755
--- a/tools_webrtc/libs/generate_licenses.py
+++ b/tools_webrtc/libs/generate_licenses.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Copyright 2016 The WebRTC project authors. All Rights Reserved.
#
@@ -23,12 +23,16 @@ Libraries are mapped to licenses via LIB_TO_LICENSES_DICT dictionary.
import sys
import argparse
-import cgi
import json
import logging
import os
import re
import subprocess
+try:
+ # python 3.2+
+ from html import escape
+except ImportError:
+ from cgi import escape
# Third_party library to licences mapping. Keys are names of the libraries
# (right after the `third_party/` prefix)
@@ -42,6 +46,7 @@ LIB_TO_LICENSES_DICT = {
],
'bazel': ['third_party/bazel/LICENSE'],
'boringssl': ['third_party/boringssl/src/LICENSE'],
+ 'crc32c': ['third_party/crc32c/src/LICENSE'],
'errorprone': [
'third_party/android_deps/libs/'
'com_google_errorprone_error_prone_core/LICENSE'
@@ -181,7 +186,7 @@ class LicenseBuilder(object):
target,
]
logging.debug('Running: %r', cmd)
- output_json = subprocess.check_output(cmd, cwd=WEBRTC_ROOT)
+ output_json = subprocess.check_output(cmd, cwd=WEBRTC_ROOT).decode('UTF-8')
logging.debug('Output: %s', output_json)
return output_json
@@ -208,7 +213,7 @@ class LicenseBuilder(object):
self.common_licenses_dict.keys())
if missing_licenses:
error_msg = 'Missing licenses for following third_party targets: %s' % \
- ', '.join(missing_licenses)
+ ', '.join(sorted(missing_licenses))
logging.error(error_msg)
raise Exception(error_msg)
@@ -233,7 +238,7 @@ class LicenseBuilder(object):
for path in self.common_licenses_dict[license_lib]:
license_path = os.path.join(WEBRTC_ROOT, path)
with open(license_path, 'r') as license_file:
- license_text = cgi.escape(license_file.read(), quote=True)
+ license_text = escape(license_file.read(), quote=True)
output_license_file.write(license_text)
output_license_file.write('\n')
output_license_file.write('```\n\n')
diff --git a/tools_webrtc/libs/generate_licenses_test.py b/tools_webrtc/libs/generate_licenses_test.py
index 51acb89881..ebef78e132 100755
--- a/tools_webrtc/libs/generate_licenses_test.py
+++ b/tools_webrtc/libs/generate_licenses_test.py
@@ -10,7 +10,12 @@
# be found in the AUTHORS file in the root of the source tree.
import unittest
-import mock
+try:
+ # python 3.3+
+ from unittest.mock import patch
+except ImportError:
+ # From site-package
+ from mock import patch
from generate_licenses import LicenseBuilder
@@ -32,21 +37,21 @@ class TestLicenseBuilder(unittest.TestCase):
"""
def testParseLibraryName(self):
- self.assertEquals(
+ self.assertEqual(
LicenseBuilder._ParseLibraryName('//a/b/third_party/libname1:c'),
'libname1')
- self.assertEquals(
+ self.assertEqual(
LicenseBuilder._ParseLibraryName(
'//a/b/third_party/libname2:c(d)'), 'libname2')
- self.assertEquals(
+ self.assertEqual(
LicenseBuilder._ParseLibraryName(
'//a/b/third_party/libname3/c:d(e)'), 'libname3')
- self.assertEquals(
+ self.assertEqual(
LicenseBuilder._ParseLibraryName('//a/b/not_third_party/c'), None)
def testParseLibrarySimpleMatch(self):
builder = LicenseBuilder([], [], {}, {})
- self.assertEquals(builder._ParseLibrary('//a/b/third_party/libname:c'),
+ self.assertEqual(builder._ParseLibrary('//a/b/third_party/libname:c'),
'libname')
def testParseLibraryRegExNoMatchFallbacksToDefaultLibname(self):
@@ -54,7 +59,7 @@ class TestLicenseBuilder(unittest.TestCase):
'libname:foo.*': ['path/to/LICENSE'],
}
builder = LicenseBuilder([], [], lib_dict, {})
- self.assertEquals(
+ self.assertEqual(
builder._ParseLibrary('//a/b/third_party/libname:bar_java'),
'libname')
@@ -63,7 +68,7 @@ class TestLicenseBuilder(unittest.TestCase):
'libname:foo.*': ['path/to/LICENSE'],
}
builder = LicenseBuilder([], [], {}, lib_regex_dict)
- self.assertEquals(
+ self.assertEqual(
builder._ParseLibrary('//a/b/third_party/libname:foo_bar_java'),
'libname:foo.*')
@@ -72,7 +77,7 @@ class TestLicenseBuilder(unittest.TestCase):
'libname/foo:bar.*': ['path/to/LICENSE'],
}
builder = LicenseBuilder([], [], {}, lib_regex_dict)
- self.assertEquals(
+ self.assertEqual(
builder._ParseLibrary('//a/b/third_party/libname/foo:bar_java'),
'libname/foo:bar.*')
@@ -81,29 +86,29 @@ class TestLicenseBuilder(unittest.TestCase):
'libname/foo.*bar.*': ['path/to/LICENSE'],
}
builder = LicenseBuilder([], [], {}, lib_regex_dict)
- self.assertEquals(
+ self.assertEqual(
builder._ParseLibrary(
'//a/b/third_party/libname/fooHAHA:bar_java'),
'libname/foo.*bar.*')
- @mock.patch('generate_licenses.LicenseBuilder._RunGN', _FakeRunGN)
+ @patch('generate_licenses.LicenseBuilder._RunGN', _FakeRunGN)
def testGetThirdPartyLibrariesWithoutRegex(self):
builder = LicenseBuilder([], [], {}, {})
- self.assertEquals(
+ self.assertEqual(
builder._GetThirdPartyLibraries('out/arm', 'target1'),
set(['libname1', 'libname2', 'libname3']))
- @mock.patch('generate_licenses.LicenseBuilder._RunGN', _FakeRunGN)
+ @patch('generate_licenses.LicenseBuilder._RunGN', _FakeRunGN)
def testGetThirdPartyLibrariesWithRegex(self):
lib_regex_dict = {
'libname2:c.*': ['path/to/LICENSE'],
}
builder = LicenseBuilder([], [], {}, lib_regex_dict)
- self.assertEquals(
+ self.assertEqual(
builder._GetThirdPartyLibraries('out/arm', 'target1'),
set(['libname1', 'libname2:c.*', 'libname3']))
- @mock.patch('generate_licenses.LicenseBuilder._RunGN', _FakeRunGN)
+ @patch('generate_licenses.LicenseBuilder._RunGN', _FakeRunGN)
def testGenerateLicenseTextFailIfUnknownLibrary(self):
lib_dict = {
'simple_library': ['path/to/LICENSE'],
@@ -113,8 +118,8 @@ class TestLicenseBuilder(unittest.TestCase):
with self.assertRaises(Exception) as context:
builder.GenerateLicenseText('dummy/dir')
- self.assertEquals(
- context.exception.message,
+ self.assertEqual(
+ context.exception.args[0],
'Missing licenses for following third_party targets: '
'libname1, libname2, libname3')