From d9b0dac5e78795fa916c163fac385182fc9ceea9 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Wed, 9 Aug 2017 16:43:25 -0400 Subject: Extracting GetBooleanGnArg from coverage_report.py Change-Id: I5475b37aad69361e2e7fae4ce69faf011e3b5c40 Reviewed-on: https://pdfium-review.googlesource.com/10030 Reviewed-by: Ryan Harrison Commit-Queue: Henrique Nakashima --- testing/__init__.py | 0 testing/tools/__init__.py | 0 testing/tools/common.py | 20 +++++++++++--------- testing/tools/coverage/coverage_report.py | 31 ++++++++++++++++--------------- 4 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 testing/__init__.py create mode 100644 testing/tools/__init__.py (limited to 'testing') diff --git a/testing/__init__.py b/testing/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/tools/__init__.py b/testing/tools/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/tools/common.py b/testing/tools/common.py index c3bc2181f4..737169f8d3 100755 --- a/testing/tools/common.py +++ b/testing/tools/common.py @@ -99,12 +99,14 @@ class DirectoryFinder: return result -def GetBooleanGnArg(arg_name, build_dir): - '''Extract the value of a boolean flag in args.gn''' - cwd = os.getcwd() - os.chdir(build_dir) - gn_args_output = subprocess.check_output( - ['gn', 'args', '.', '--list=%s' % arg_name, '--short']) - os.chdir(cwd) - arg_match_output = re.search('%s = (.*)' % arg_name, gn_args_output).group(1) - return arg_match_output == 'true' +def GetBooleanGnArg(arg_name, build_dir, verbose=False): + '''Extract the value of a boolean flag in args.gn''' + cwd = os.getcwd() + os.chdir(build_dir) + gn_args_output = subprocess.check_output( + ['gn', 'args', '.', '--list=%s' % arg_name, '--short']) + os.chdir(cwd) + arg_match_output = re.search('%s = (.*)' % arg_name, gn_args_output).group(1) + if verbose: + print >> sys.stderr, "Found '%s' for value of %s" % (arg_match_output, arg) + return arg_match_output == 'true' diff --git a/testing/tools/coverage/coverage_report.py b/testing/tools/coverage/coverage_report.py index a4222558e4..c12e6cd6c8 100755 --- a/testing/tools/coverage/coverage_report.py +++ b/testing/tools/coverage/coverage_report.py @@ -12,13 +12,25 @@ Requires that 'use_coverage = true' is set in args.gn. import argparse from collections import namedtuple -import pprint import os +import pprint import re import subprocess import sys +# Add src dir to path to avoid having to set PYTHONPATH. +sys.path.append( + os.path.abspath( + os.path.join( + os.path.dirname(__file__), + os.path.pardir, + os.path.pardir, + os.path.pardir))) + +from testing.tools.common import GetBooleanGnArg + + # 'binary' is the file that is to be run for the test. # 'use_test_runner' indicates if 'binary' depends on test_runner.py and thus # requires special handling. @@ -77,12 +89,13 @@ class CoverageExecutor(object): 'No valid tests in set to be run. This is likely due to bad command ' 'line arguments') - if not self.boolean_gn_arg('use_coverage'): + if not GetBooleanGnArg('use_coverage', self.build_directory, self.verbose): parser.error( 'use_coverage does not appear to be set to true for build, but is ' 'needed') - self.use_goma = self.boolean_gn_arg('use_goma') + self.use_goma = GetBooleanGnArg('use_goma', self.build_directory, + self.verbose) self.output_directory = args['output_directory'] if not os.path.exists(self.output_directory): @@ -93,18 +106,6 @@ class CoverageExecutor(object): self.coverage_totals_path = os.path.join(self.output_directory, 'pdfium_totals.info') - def boolean_gn_arg(self, arg): - """Extract the value of a boolean flag in args.gn""" - cwd = os.getcwd() - os.chdir(self.build_directory) - gn_args_output = self.check_output( - ['gn', 'args', '.', '--list=%s' % arg, '--short']) - os.chdir(cwd) - arg_match_output = re.match('%s = (.*)' % arg, gn_args_output).group(1) - if self.verbose: - print "Found '%s' for value of %s" % (arg_match_output, arg) - return arg_match_output == 'true' - def check_output(self, args, dry_run=False, env=None): """Dry run aware wrapper of subprocess.check_output()""" if dry_run: -- cgit v1.2.3