[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / tools / perf / fetch_benchmark_deps.py
blobd579214bf284c04298f7dec1bb15223748d63b7f
1 #!/usr/bin/env python
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """This module fetches and prints the dependencies given a benchmark."""
8 import os
9 import sys
11 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'telemetry'))
13 from catapult_base import cloud_storage
14 from telemetry import benchmark_runner
17 def _GetPerfDir(*subdirs):
18 perf_dir = os.path.realpath(os.path.dirname(__file__))
19 return os.path.join(perf_dir, *subdirs)
22 def GetChromiumDir():
23 return _GetPerfDir(os.path.pardir, os.path.pardir, os.path.pardir)
26 def _FetchDependenciesIfNeeded(story_set):
27 """ Download files needed by a user story set. """
28 # Download files in serving_dirs.
29 serving_dirs = story_set.serving_dirs
30 for directory in serving_dirs:
31 cloud_storage.GetFilesInDirectoryIfChanged(directory, story_set.bucket)
33 # Download WPR files.
34 if any(not story.is_local for story in story_set):
35 story_set.wpr_archive_info.DownloadArchivesIfNeeded()
38 def _EnumerateDependencies(story_set):
39 """ Enumerate pathes of files needed by a user story set. """
40 deps = set()
41 # Enumerate WPRs
42 for story in story_set:
43 deps.add(story_set.WprFilePathForStory(story))
45 # Enumerate files in serving_dirs
46 for directory in story_set.serving_dirs:
47 if not os.path.isdir(directory):
48 raise ValueError('Must provide a valid directory.')
49 # Don't allow the root directory to be a serving_dir.
50 if directory == os.path.abspath(os.sep):
51 raise ValueError('Trying to serve root directory from HTTP server.')
52 for dirpath, _, filenames in os.walk(directory):
53 for filename in filenames:
54 path_name, extension = os.path.splitext(
55 os.path.join(dirpath, filename))
56 if extension == '.sha1':
57 deps.add(path_name)
59 # Return relative pathes.
60 prefix_len = len(os.path.realpath(GetChromiumDir())) + 1
61 return [dep[prefix_len:] for dep in deps if dep]
64 def _show_usage():
65 print ('Usage: %s benchmark_name\n'
66 'Fetch the dependencies of benchmark_name.' % sys.argv[0])
69 def main(output=sys.stdout):
70 config = benchmark_runner.ProjectConfig(
71 top_level_dir=_GetPerfDir(),
72 benchmark_dirs=[_GetPerfDir('benchmarks')])
74 name = sys.argv[1]
75 benchmark = benchmark_runner.GetBenchmarkByName(name, config)
76 if not benchmark:
77 raise ValueError('No such benchmark: %s' % name)
79 # Download files according to specified benchmark.
80 story_set = benchmark().CreateStorySet(None)
82 _FetchDependenciesIfNeeded(story_set)
84 # Print files downloaded.
85 deps = _EnumerateDependencies(story_set)
86 for dep in deps:
87 print >> output, dep
90 if __name__ == '__main__':
91 if len(sys.argv) != 2 or sys.argv[1][0] == '-':
92 _show_usage()
93 else:
94 main()