blob: a8b1c4c5db96f480c24030fc99a7391a3fbbdfe7 [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001#!/usr/bin/env python
2#
3# Copyright 2017 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8import os
9import subprocess
10import sys
11
12skslc = sys.argv[1]
Ethan Nicholasb9f6afb2017-07-27 16:02:37 -040013clangFormat = sys.argv[2]
John Stiles796e7022020-06-11 19:57:22 -040014fetchClangFormat = sys.argv[3]
15processors = sys.argv[4:]
16
17exeSuffix = '.exe' if sys.platform.startswith('win') else '';
John Stiles3e1b7712020-11-13 15:52:07 -050018skslcArgs = [skslc]
19clangFormatArgs = [clangFormat, "--sort-includes=false", "-i"]
John Stiles796e7022020-06-11 19:57:22 -040020
John Stilesba06e1a2020-11-12 11:04:38 -050021# Fetch clang-format if it's not present already.
22if not os.path.isfile(clangFormat + exeSuffix):
23 subprocess.check_call([sys.executable, fetchClangFormat]);
24
John Stiles3e1b7712020-11-13 15:52:07 -050025# Build argument lists for all the fragment processors that we want to compile.
Ethan Nicholas762466e2017-06-29 10:03:38 -040026for p in processors:
John Stilesba06e1a2020-11-12 11:04:38 -050027 noExt, _ = os.path.splitext(p)
28 head, tail = os.path.split(noExt)
29 targetDir = os.path.join(head, "generated")
30 if not os.path.isdir(targetDir):
31 os.mkdir(targetDir)
32 target = os.path.join(targetDir, tail)
John Stiles3e1b7712020-11-13 15:52:07 -050033 clangFormatArgs.append(target + ".h")
34 clangFormatArgs.append(target + ".cpp")
35 skslcArgs.append("--");
36 skslcArgs.append(p);
37 skslcArgs.append(target + ".h");
38 skslcArgs.append("--");
39 skslcArgs.append(p);
40 skslcArgs.append(target + ".cpp");
John Stiles796e7022020-06-11 19:57:22 -040041
John Stiles3e1b7712020-11-13 15:52:07 -050042# Invoke skslc on every target that needs to be compiled.
John Stilesba06e1a2020-11-12 11:04:38 -050043try:
John Stiles3e1b7712020-11-13 15:52:07 -050044 output = subprocess.check_output(skslcArgs, stderr=subprocess.STDOUT)
John Stilesba06e1a2020-11-12 11:04:38 -050045except subprocess.CalledProcessError as err:
46 print("### skslc error:\n")
47 print("\n".join(err.output.splitlines()))
John Stiles3e1b7712020-11-13 15:52:07 -050048 sys.exit(err.returncode)
John Stilesba06e1a2020-11-12 11:04:38 -050049
50# Invoke clang-format on every generated target.
51try:
John Stiles3e1b7712020-11-13 15:52:07 -050052 output = subprocess.check_output(clangFormatArgs, stderr=subprocess.STDOUT)
John Stilesba06e1a2020-11-12 11:04:38 -050053except subprocess.CalledProcessError as err:
54 print("### clang-format error:\n")
55 print("\n".join(err.output.splitlines()))
John Stiles3e1b7712020-11-13 15:52:07 -050056 sys.exit(err.returncode)