mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
7a43c648c3
Calling out to python from GN to process gypi files is relatively
expensive with a 20-45ms fixed overhead for setup/teardown regardless
of what the script does. This makes runtime/vm/BUILD.gn take 1-1.5s
(per toolchain) to run as the template for libraries expands
out to 25 calls to gypi_to_gn.py, even though the actual time spent
processing the gypi files is negligible.
This replaces those repeated calls to gypi_to_gn.py with a call to a
custom script that process all of the gypi files needed for runtime/vm
and places the results into a single scope which can then be read from
in the template and replaces a few other scattered calls to
gypi_to_gn.py with a smaller number of calls that process multiple
gypi files and place the results into a single scope.
The end result is processing all of dart's GN files in a fuchsia build
takes ~250ms instead of >3 seconds.
R=zra@google.com
Review URL: https://codereview.chromium.org/2472813002 .
Committed: ad86d6ed26
69 lines
2.4 KiB
Python
Executable file
69 lines
2.4 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# Copyright 2016, the Dart project authors. Please see the AUTHORS file
|
|
# for details. All rights reserved. Use of this source code is governed by a
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
import gn_helpers
|
|
import os.path
|
|
import sys
|
|
|
|
# Given a list of dart package names read in the set of runtime and sdk library
|
|
# sources into variables in a gn scope.
|
|
|
|
|
|
def LoadPythonDictionary(path):
|
|
file_string = open(path).read()
|
|
try:
|
|
file_data = eval(file_string, {'__builtins__': None}, None)
|
|
except SyntaxError, e:
|
|
e.filename = path
|
|
raise
|
|
except Exception, e:
|
|
raise Exception('Unexpected error while reading %s: %s' %
|
|
(path, str(e)))
|
|
|
|
assert isinstance(
|
|
file_data, dict), '%s does not eval to a dictionary' % path
|
|
return file_data
|
|
|
|
|
|
def main():
|
|
dart_root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
runtime_dir = os.path.join(dart_root_dir, 'runtime')
|
|
runtime_lib_dir = os.path.join(runtime_dir, 'lib')
|
|
sdk_lib_dir = os.path.join(dart_root_dir, 'sdk', 'lib')
|
|
libs = sys.argv[1:]
|
|
data = {}
|
|
data['allsources'] = []
|
|
|
|
for lib in libs:
|
|
runtime_path = os.path.join(runtime_lib_dir, lib + '_sources.gypi')
|
|
sdk_path = os.path.join(sdk_lib_dir, lib, lib + '_sources.gypi')
|
|
runtime_dict = LoadPythonDictionary(runtime_path)
|
|
for source in runtime_dict['sources']:
|
|
data['allsources'].append(source)
|
|
data[lib + '_runtime_sources'] = runtime_dict['sources']
|
|
sdk_dict = LoadPythonDictionary(sdk_path)
|
|
data[lib + '_sdk_sources'] = sdk_dict['sources']
|
|
|
|
vm_sources_path = os.path.join(runtime_dir, 'vm', 'vm_sources.gypi')
|
|
vm_sources_dict = LoadPythonDictionary(vm_sources_path)
|
|
data['vm_sources'] = vm_sources_dict['sources']
|
|
|
|
platform_sources_base = os.path.join(runtime_dir, 'platform', 'platform_')
|
|
platform_headers_dict = LoadPythonDictionary(
|
|
platform_sources_base + 'headers.gypi')
|
|
platform_sources_dict = LoadPythonDictionary(
|
|
platform_sources_base + 'sources.gypi')
|
|
data['platform_sources'] = platform_headers_dict[
|
|
'sources'] + platform_sources_dict['sources']
|
|
|
|
bin_io_sources_path = os.path.join(runtime_dir, 'bin', 'io_sources.gypi')
|
|
bin_io_sources_dict = LoadPythonDictionary(bin_io_sources_path)
|
|
data['bin_io_sources'] = bin_io_sources_dict['sources']
|
|
|
|
print gn_helpers.ToGNString(data)
|
|
return 0
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|