diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-17 14:15:34 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-17 14:15:34 +0000 |
commit | da19703bc3e290f1da7e05c78d91340b9a72dcb4 (patch) | |
tree | 1e4c6df912d86e4b26b36db120bfc23afeb13470 /build | |
parent | 14921cfcfcc57d533748b838afe597d04b1d3ad0 (diff) | |
download | chromium_src-da19703bc3e290f1da7e05c78d91340b9a72dcb4.zip chromium_src-da19703bc3e290f1da7e05c78d91340b9a72dcb4.tar.gz chromium_src-da19703bc3e290f1da7e05c78d91340b9a72dcb4.tar.bz2 |
Adds a way to specify test data files for unittests.
BUG=None
TEST=None
Review URL: https://chromiumcodereview.appspot.com/10790008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146995 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r-- | build/copy_test_data_ios.gypi | 48 | ||||
-rwxr-xr-x | build/copy_test_data_ios.py | 98 |
2 files changed, 146 insertions, 0 deletions
diff --git a/build/copy_test_data_ios.gypi b/build/copy_test_data_ios.gypi new file mode 100644 index 0000000..150df6e --- /dev/null +++ b/build/copy_test_data_ios.gypi @@ -0,0 +1,48 @@ +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This file is meant to be included into an action to copy test data files into +# an iOS app bundle. To use this the following variables need to be defined: +# test_data_files: list: paths to test data files or directories +# test_data_prefix: string: a directory prefix that will be prepended to each +# output path. Generally, this should be the base +# directory of the gypi file containing the unittest +# target (e.g. "base" or "chrome"). +# +# To use this, create a gyp target with the following form: +# { +# 'target_name': 'my_unittests', +# 'conditions': [ +# ['OS == "ios"', { +# 'actions': [ +# { +# 'action_name': 'copy_test_data', +# 'variables': { +# 'test_data_files': [ +# 'path/to/datafile.txt', +# 'path/to/data/directory/', +# ] +# 'test_data_prefix' : 'prefix', +# }, +# 'includes': ['path/to/this/gypi/file'], +# }, +# ], +# }], +# } +# + +{ + 'inputs': [ + '<!@pymod_do_main(copy_test_data_ios --inputs <(test_data_files))', + ], + 'outputs': [ + '<!@pymod_do_main(copy_test_data_ios -o <(PRODUCT_DIR)/<(_target_name).app/<(test_data_prefix) --outputs <(test_data_files))', + ], + 'action': [ + 'python', + '<(DEPTH)/build/copy_test_data_ios.py', + '-o', '<(PRODUCT_DIR)/<(_target_name).app/<(test_data_prefix)', + '<(_inputs)', + ], +} diff --git a/build/copy_test_data_ios.py b/build/copy_test_data_ios.py new file mode 100755 index 0000000..e6c6a38 --- /dev/null +++ b/build/copy_test_data_ios.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Copies test data files or directories into a given output directory.""" + +import optparse +import os +import shutil +import sys + +class WrongNumberOfArgumentsException(Exception): + pass + +def ListFilesForPath(path): + """Returns a list of all the files under a given path.""" + output = [] + # Files get returned without modification. + if not os.path.isdir(path): + output.append(path) + return output + + # Directories get recursively expanded. + contents = os.listdir(path) + for item in contents: + full_path = os.path.join(path, item) + output.extend(ListFilesForPath(full_path)) + return output + +def CalcInputs(inputs): + """Computes the full list of input files for a set of command-line arguments. + """ + # |inputs| is a list of strings, each of which may contain muliple paths + # separated by spaces. + output = [] + for input in inputs: + tokens = input.split() + for token in tokens: + output.extend(ListFilesForPath(token)) + return output + +def CopyFiles(relative_filenames, output_basedir): + """Copies files to the given output directory.""" + for file in relative_filenames: + relative_dirname = os.path.dirname(file) + output_dir = os.path.join(output_basedir, relative_dirname) + output_filename = os.path.join(output_basedir, file) + + # In cases where a directory has turned into a file or vice versa, delete it + # before copying it below. + if os.path.exists(output_dir) and not os.path.isdir(output_dir): + os.remove(output_dir) + if os.path.exists(output_filename) and os.path.isdir(output_filename): + shutil.rmtree(output_filename) + + if not os.path.exists(output_dir): + os.makedirs(output_dir) + shutil.copy(file, output_filename) + +def DoMain(argv): + parser = optparse.OptionParser() + usage = 'Usage: %prog -o <output_dir> [--inputs] [--outputs] <input_files>' + parser.set_usage(usage) + parser.add_option('-o', dest='output_dir') + parser.add_option('--inputs', action='store_true', dest='list_inputs') + parser.add_option('--outputs', action='store_true', dest='list_outputs') + options, arglist = parser.parse_args(argv) + + if len(arglist) == 0: + raise WrongNumberOfArgumentsException('<input_files> required.') + + files_to_copy = CalcInputs(arglist) + if options.list_inputs: + return '\n'.join(files_to_copy) + + if not options.output_dir: + raise WrongNumberOfArgumentsException('-o required.') + + if options.list_outputs: + outputs = [os.path.join(options.output_dir, x) for x in files_to_copy] + return '\n'.join(outputs) + + CopyFiles(files_to_copy, options.output_dir) + return + +def main(argv): + try: + result = DoMain(argv[1:]) + except WrongNumberOfArgumentsException, e: + print >>sys.stderr, e + return 1 + if result: + print result + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) |