blob: 33b32d197d0577edfc310fbe5b027e8824ad2d08 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2015 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.
import argparse
import subprocess
import sys
import os
import yaml
SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
SRC_ROOT = os.path.dirname(os.path.dirname(SKY_TOOLS_DIR))
SKY_PACKAGE_DIR = os.path.join(SRC_ROOT, 'sky', 'packages', 'sky')
SKY_PUBSPEC = os.path.join(SKY_PACKAGE_DIR, 'pubspec.yaml')
SKY_PUBSPEC_LOCK = os.path.join(SKY_PACKAGE_DIR, 'pubspec.lock')
WORKBENCH = os.path.join(SRC_ROOT, 'sky', 'packages', 'workbench')
def version_for_pubspec(pubspec_path):
with open(pubspec_path, 'r') as stream:
dependency_spec = yaml.load(stream)
return dependency_spec['version']
def entry_for_dependency(dart_pkg_dir, dependency):
dependency_path = os.path.join(dart_pkg_dir, dependency)
pubspec_path = os.path.join(dependency_path, 'pubspec.yaml')
if not os.path.exists(pubspec_path):
dependency_path = os.path.dirname(os.path.realpath(os.path.join(WORKBENCH, 'packages', dependency)))
pubspec_path = os.path.join(dependency_path, 'pubspec.yaml')
if not os.path.exists(pubspec_path):
return
version = version_for_pubspec(pubspec_path)
return {
'description': {
'path': os.path.relpath(dependency_path, SKY_PACKAGE_DIR),
'relative': True,
},
'source': 'path',
'version': version,
}
def main():
parser = argparse.ArgumentParser(description='Adds files to the source tree to make the dart analyzer happy')
parser.add_argument('build_dir', type=str, help='Path the build directory to use for build artifacts')
args = parser.parse_args()
dart_pkg_dir = os.path.join(args.build_dir, 'gen', 'dart-pkg')
if not os.path.exists(dart_pkg_dir):
print 'Cannot find Dart pacakges at "%s".' % dart_pkg_dir
print 'Did you run `ninja -C %s` ?' % os.path.relpath(args.build_dir, os.getcwd())
return 1
packages = {}
with open(SKY_PUBSPEC, 'r') as stream:
spec = yaml.load(stream)
for dependency in spec['dependencies'].keys():
entry = entry_for_dependency(dart_pkg_dir, dependency)
if not entry:
continue
packages[dependency] = entry
lock = { 'packages': packages }
with open(SKY_PUBSPEC_LOCK, 'w') as stream:
yaml.dump(lock, stream=stream, default_flow_style=False)
if __name__ == '__main__':
sys.exit(main())