Extracting GetBooleanGnArg from coverage_report.py
Change-Id: I5475b37aad69361e2e7fae4ce69faf011e3b5c40
Reviewed-on: https://pdfium-review.googlesource.com/10030
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/testing/__init__.py b/testing/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/testing/__init__.py
diff --git a/testing/tools/__init__.py b/testing/tools/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/testing/tools/__init__.py
diff --git a/testing/tools/common.py b/testing/tools/common.py
index c3bc218..737169f 100755
--- a/testing/tools/common.py
+++ b/testing/tools/common.py
@@ -99,12 +99,14 @@
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 a422255..c12e6cd 100755
--- a/testing/tools/coverage/coverage_report.py
+++ b/testing/tools/coverage/coverage_report.py
@@ -12,13 +12,25 @@
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 @@
'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 @@
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: