diff --git a/ci/check_gn_format.py b/ci/check_gn_format.py new file mode 100755 index 0000000000000000000000000000000000000000..528287452cd6691e9598b490d8d31348fb989695 --- /dev/null +++ b/ci/check_gn_format.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# +# Copyright 2013 The Flutter 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 sys +import subprocess +import os +import argparse +import errno +import shutil + +def GetGNFiles(directory): + directory = os.path.abspath(directory) + gn_files = [] + assert os.path.exists(directory), "Directory must exist %s" % directory + for root, dirs, files in os.walk(directory): + for file in files: + if file.endswith(".gn") or file.endswith(".gni"): + gn_files.append(os.path.join(root, file)) + return gn_files + +def main(): + parser = argparse.ArgumentParser(); + + parser.add_argument('--gn-binary', dest='gn_binary', required=True, type=str) + parser.add_argument('--dry-run', dest='dry_run', required=True, type=bool) + parser.add_argument('--root-directory', dest='root_directory', required=True, type=str) + + args = parser.parse_args() + + gn_binary = os.path.abspath(args.gn_binary) + assert os.path.exists(gn_binary), "GN Binary must exist %s" % gn_binary + + gn_command = [ gn_binary, 'format'] + + if args.dry_run: + gn_command.append('--dry-run') + + + for gn_file in GetGNFiles(args.root_directory): + if subprocess.call(gn_command + [ gn_file ]) != 0: + print "ERROR: '%s' is incorrectly formatted." % os.path.relpath(gn_file, args.root_directory) + print "Format the same with 'gn format' using the 'gn' binary in //buildtools." + print "Or, run ./ci/check_gn_format.py with '--dry-run false'" + return -1 + + return 0 + +if __name__ == '__main__': + sys.exit(main()) diff --git a/ci/format.sh b/ci/format.sh index 93f0be6c47618e78985a65bc54ceb4f05bc47270..e3c8533afd55c6d32f1a1e66ac2adb93f2e74731 100755 --- a/ci/format.sh +++ b/ci/format.sh @@ -73,3 +73,6 @@ if [[ ! -z "$TRAILING_SPACES" ]]; then echo "ERROR: Some files have trailing spaces. To fix, try something like \`find . -name "*.dart" -exec sed -i -e 's/\s\+$//' {} \;\`." exit 1 fi + +# Check GN format consistency +./ci/check_gn_format.py --dry-run true --root-directory . --gn-binary "../buildtools/$OS/gn"