Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: tools/licenses.py

Issue 2802723004: Fix an issue that tools/license.py fails when BUILD.gn is not directly (Closed)
Patch Set: Add //tools/tests/OWNERS. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/tests/OWNERS » ('j') | tools/tests/OWNERS » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Utility for checking and processing licensing information in third_party 6 """Utility for checking and processing licensing information in third_party
7 directories. 7 directories.
8 8
9 Usage: licenses.py <command> 9 Usage: licenses.py <command>
10 10
11 Commands: 11 Commands:
12 scan scan third_party directories, verifying that we have licensing info 12 scan scan third_party directories, verifying that we have licensing info
13 credits generate about:credits on stdout 13 credits generate about:credits on stdout
14 14
15 (You can also import this as a module.) 15 (You can also import this as a module.)
16 """ 16 """
17 17
18 import argparse 18 import argparse
19 import cgi 19 import cgi
20 import os 20 import os
21 import shutil 21 import shutil
22 import re
22 import subprocess 23 import subprocess
23 import sys 24 import sys
24 import tempfile 25 import tempfile
25 26
26 # TODO(agrieve): Move build_utils.WriteDepFile into a non-android directory. 27 # TODO(agrieve): Move build_utils.WriteDepFile into a non-android directory.
27 _REPOSITORY_ROOT = os.path.dirname(os.path.dirname(__file__)) 28 _REPOSITORY_ROOT = os.path.dirname(os.path.dirname(__file__))
28 sys.path.append(os.path.join(_REPOSITORY_ROOT, 'build/android/gyp/util')) 29 sys.path.append(os.path.join(_REPOSITORY_ROOT, 'build/android/gyp/util'))
29 import build_utils 30 import build_utils
30 31
31 32
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 elif sys.platform == 'darwin': 474 elif sys.platform == 'darwin':
474 subdir = 'mac' 475 subdir = 'mac'
475 elif sys.platform == 'win32': 476 elif sys.platform == 'win32':
476 subdir, exe = 'win', 'gn.exe' 477 subdir, exe = 'win', 'gn.exe'
477 else: 478 else:
478 raise RuntimeError("Unsupported platform '%s'." % sys.platform) 479 raise RuntimeError("Unsupported platform '%s'." % sys.platform)
479 480
480 return os.path.join(_REPOSITORY_ROOT, 'buildtools', subdir, exe) 481 return os.path.join(_REPOSITORY_ROOT, 'buildtools', subdir, exe)
481 482
482 483
484 def GetThirdPartyDepsFromGNDepsOutput(gn_deps):
485 """Returns third_party/foo directories given the output of "gn desc deps".
486
487 Note that it always returns the direct sub-directory of third_party
488 where README.chromium and LICENSE files are, so that it can be passed to
489 ParseDir(). e.g.:
490 .../third_party/cld_3/src/src/BUILD.gn -> .../third_party/cld_3
491 """
492 third_party_deps = set()
493 for build_dep in gn_deps.split():
494 m = re.search(r'^(.+/third_party/[^/]+)/(.+/)?BUILD\.gn$', build_dep)
495 if m:
496 third_party_deps.add(m.group(1))
497 return third_party_deps
498
499
483 def FindThirdPartyDeps(gn_out_dir, gn_target): 500 def FindThirdPartyDeps(gn_out_dir, gn_target):
484 if not gn_out_dir: 501 if not gn_out_dir:
485 raise RuntimeError("--gn-out-dir is required if --gn-target is used.") 502 raise RuntimeError("--gn-out-dir is required if --gn-target is used.")
486 503
487 # Generate gn project in temp directory and use it to find dependencies. 504 # Generate gn project in temp directory and use it to find dependencies.
488 # Current gn directory cannot be used when we run this script in a gn action 505 # Current gn directory cannot be used when we run this script in a gn action
489 # rule, because gn doesn't allow recursive invocations due to potential side 506 # rule, because gn doesn't allow recursive invocations due to potential side
490 # effects. 507 # effects.
491 tmp_dir = None 508 tmp_dir = None
492 try: 509 try:
493 tmp_dir = tempfile.mkdtemp(dir = gn_out_dir) 510 tmp_dir = tempfile.mkdtemp(dir = gn_out_dir)
494 shutil.copy(os.path.join(gn_out_dir, "args.gn"), tmp_dir) 511 shutil.copy(os.path.join(gn_out_dir, "args.gn"), tmp_dir)
495 subprocess.check_output([_GnBinary(), "gen", tmp_dir]) 512 subprocess.check_output([_GnBinary(), "gen", tmp_dir])
496 gn_deps = subprocess.check_output([ 513 gn_deps = subprocess.check_output([
497 _GnBinary(), "desc", tmp_dir, gn_target, 514 _GnBinary(), "desc", tmp_dir, gn_target,
498 "deps", "--as=buildfile", "--all"]) 515 "deps", "--as=buildfile", "--all"])
499 finally: 516 finally:
500 if tmp_dir and os.path.exists(tmp_dir): 517 if tmp_dir and os.path.exists(tmp_dir):
501 shutil.rmtree(tmp_dir) 518 shutil.rmtree(tmp_dir)
502 519
503 third_party_deps = set() 520 return GetThirdPartyDepsFromGNDepsOutput(gn_deps)
504 for build_dep in gn_deps.split():
505 if ("third_party" in build_dep and
506 os.path.basename(build_dep) == "BUILD.gn"):
507 third_party_deps.add(os.path.dirname(build_dep))
508 return third_party_deps
509 521
510 522
511 def ScanThirdPartyDirs(root=None): 523 def ScanThirdPartyDirs(root=None):
512 """Scan a list of directories and report on any problems we find.""" 524 """Scan a list of directories and report on any problems we find."""
513 if root is None: 525 if root is None:
514 root = os.getcwd() 526 root = os.getcwd()
515 third_party_dirs = FindThirdPartyDirsWithFiles(root) 527 third_party_dirs = FindThirdPartyDirsWithFiles(root)
516 528
517 errors = [] 529 errors = []
518 for path in sorted(third_party_dirs): 530 for path in sorted(third_party_dirs):
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 if not GenerateLicenseFile( 718 if not GenerateLicenseFile(
707 args.output_file, args.gn_out_dir, args.gn_target): 719 args.output_file, args.gn_out_dir, args.gn_target):
708 return 1 720 return 1
709 else: 721 else:
710 print __doc__ 722 print __doc__
711 return 1 723 return 1
712 724
713 725
714 if __name__ == '__main__': 726 if __name__ == '__main__':
715 sys.exit(main()) 727 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tools/tests/OWNERS » ('j') | tools/tests/OWNERS » ('J')

Powered by Google App Engine
This is Rietveld 408576698