blob: 75206b5211b5a0fd7c4213e7c85577169c83457b [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""A tool to facilitate validating the cobalt configuration."""
import argparse
import os
import os.path
import subprocess
import sys
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
COBALT_REPO = 'https://fuchsia.googlesource.com/cobalt'
def get_cobalt_dir(args):
# If a cobalt_checkout has been specified, we assume the user is managing that
# checkout and so we leave it in the state we find it.
if args.cobalt_checkout:
return args.cobalt_checkout
# We checkout cobalt in a subdirectory called 'cobalt'.
cobalt_dir = os.path.join(THIS_DIR, 'cobalt')
# If the 'cobalt' subdirectory exists, we just update it.
if os.path.isdir(cobalt_dir):
savedDir = os.getcwd()
try:
os.chdir(cobalt_dir)
subprocess.check_call(['git', 'pull', 'origin', 'master'])
finally:
os.chdir(savedDir)
return cobalt_dir
# If the 'cobalt' subdirectory did not exist, we clone it.
subprocess.check_call(['git', 'clone', COBALT_REPO, cobalt_dir])
return cobalt_dir
def main():
parser = argparse.ArgumentParser(description='%s will check the cobalt '
'config in this directory. The '
'first run of this tool could '
'take a long time.')
parser.add_argument('--cobalt_checkout',
help='The location of a pre-existing cobalt checkout. If this is not '
'set, a new cobalt checkout will be created in %s/cobalt (or '
'updated if it already exists) and used to build the config_parser.'
% THIS_DIR,
default=None)
args = parser.parse_args()
cobalt_dir = get_cobalt_dir(args)
savedDir = os.getcwd()
try:
os.chdir(cobalt_dir)
subprocess.check_call(['./cobaltb.py', 'setup'])
subprocess.check_call(['./cobaltb.py', 'build'])
subprocess.check_call(['./cobaltb.py', 'check_config', '--config_dir',
THIS_DIR])
finally:
os.chdir(savedDir)
return 0
if __name__ == '__main__':
sys.exit(main())