Commit 97a63f0a authored by Tyler Ouyang's avatar Tyler Ouyang Committed by Commit Bot

Updated licenses.py to be back slash ('\') friendly for better

compatibility.

A few places in licenses.py only consider '/' as the path separator,
like the regular expression in GetThirdPartyDepsFromGNDepsOutput, so the
gn mode does not work properly on Windows which uses '\'. This CL updated
those places to be compatible with Windows.

outputs are complete and match each other.

Bug: 955105
Test: Run tools/tests/licenses_test.py on different platforms. Check if
Change-Id: I435ff18e4a78988692497b9b490964b2a4d07ec0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1584175
Commit-Queue: Hiroshi Ichikawa <ichikawa@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657094}
parent e1f9086b
......@@ -534,14 +534,15 @@ def GetThirdPartyDepsFromGNDepsOutput(gn_deps, target_os):
relative_build_dep = os.path.relpath(
absolute_build_dep, _REPOSITORY_ROOT)
m = re.search(
r'^((.+/)?third_party/[^/]+/)(.+/)?BUILD\.gn$', relative_build_dep)
r'^((.+[/\\])?third_party[/\\][^/\\]+[/\\])(.+[/\\])?BUILD\.gn$',
relative_build_dep)
if not m:
continue
third_party_path = m.group(1)
if any(third_party_path.startswith(p + '/') for p in PRUNE_PATHS):
if any(third_party_path.startswith(p + os.sep) for p in PRUNE_PATHS):
continue
if (target_os == 'ios' and
any(third_party_path.startswith(p + '/')
any(third_party_path.startswith(p + os.sep)
for p in KNOWN_NON_IOS_LIBRARIES)):
# Skip over files that are known not to be used on iOS.
continue
......@@ -736,7 +737,7 @@ def GenerateLicenseFile(output_file, gn_out_dir, gn_target, target_os):
metadata = ParseDir(
directory, _REPOSITORY_ROOT, require_license_file=True)
content.append('-' * 20)
content.append(directory.split('/')[-1])
content.append(directory.split(os.sep)[-1])
content.append('-' * 20)
license_file = metadata['License File']
if license_file and license_file != NOT_SHIPPED:
......
......@@ -20,20 +20,28 @@ import licenses
class LicensesTest(unittest.TestCase):
def test_get_third_party_deps_from_gn_deps_output(self):
def construct_absolute_path(path):
return os.path.join(REPOSITORY_ROOT, *path.split('/')).replace(
os.sep, '/')
prune_path = next(iter(licenses.PRUNE_PATHS))
gn_deps = [
construct_absolute_path('net/BUILD.gn'),
construct_absolute_path('third_party/zlib/BUILD.gn'),
construct_absolute_path('third_party/cld_3/src/src/BUILD.gn'),
construct_absolute_path(prune_path + '/BUILD.gn'),
]
third_party_deps = licenses.GetThirdPartyDepsFromGNDepsOutput(
'/home/example/src/net/BUILD.gn\n'
'/home/example/src/third_party/zlib/BUILD.gn\n'
'/home/example/src/third_party/cld_3/src/src/BUILD.gn\n')
'\n'.join(gn_deps), None)
# '/home/example/src/net' is not in the output because it's not a
# third_party dependency.
# 'net' is not in the output because it's not a third_party dependency.
#
# It must return the direct sub-directory of "third_party". So it should
# return '/home/example/src/third_party/cld_3', not
# '/home/example/src/third_party/cld_3/src/src'.
# return 'third_party/cld_3', not 'third_party/cld_3/src/src'.
assert third_party_deps == set([
'/home/example/src/third_party/zlib',
'/home/example/src/third_party/cld_3',
os.path.join('third_party', 'zlib'),
os.path.join('third_party', 'cld_3'),
])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment