blob: 88504aad41e6727d9ac21173f0e014321bcec996 [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
Brian Osman7b239052020-11-18 17:04:33 +000011import tempfile
Ethan Nicholas762466e2017-06-29 10:03:38 -040012
13skslc = sys.argv[1]
Ethan Nicholasb9f6afb2017-07-27 16:02:37 -040014clangFormat = sys.argv[2]
John Stiles796e7022020-06-11 19:57:22 -040015fetchClangFormat = sys.argv[3]
16processors = sys.argv[4:]
17
18exeSuffix = '.exe' if sys.platform.startswith('win') else '';
Brian Osman7b239052020-11-18 17:04:33 +000019targets = []
John Stiles57adba02020-11-18 13:58:19 -050020worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False)
John Stiles796e7022020-06-11 19:57:22 -040021
John Stilesba06e1a2020-11-12 11:04:38 -050022# Fetch clang-format if it's not present already.
23if not os.path.isfile(clangFormat + exeSuffix):
24 subprocess.check_call([sys.executable, fetchClangFormat]);
25
Brian Osman7b239052020-11-18 17:04:33 +000026# Build a worklist of all the fragment processors that we want to compile.
Ethan Nicholas762466e2017-06-29 10:03:38 -040027for p in processors:
John Stilesba06e1a2020-11-12 11:04:38 -050028 noExt, _ = os.path.splitext(p)
29 head, tail = os.path.split(noExt)
30 targetDir = os.path.join(head, "generated")
31 if not os.path.isdir(targetDir):
32 os.mkdir(targetDir)
33 target = os.path.join(targetDir, tail)
Brian Osman7b239052020-11-18 17:04:33 +000034 targets.append(target + ".h")
35 targets.append(target + ".cpp")
John Stiles796e7022020-06-11 19:57:22 -040036
Brian Osman7b239052020-11-18 17:04:33 +000037 worklist.write(p + "\n")
38 worklist.write(target + ".h\n\n")
39 worklist.write(p + "\n")
40 worklist.write(target + ".cpp\n\n")
41
42# Invoke skslc, passing in the worklist.
43worklist.close()
John Stilesba06e1a2020-11-12 11:04:38 -050044try:
Brian Osman7b239052020-11-18 17:04:33 +000045 output = subprocess.check_output([skslc, worklist.name], stderr=subprocess.STDOUT)
John Stilesba06e1a2020-11-12 11:04:38 -050046except subprocess.CalledProcessError as err:
47 print("### skslc error:\n")
48 print("\n".join(err.output.splitlines()))
49
John Stiles57adba02020-11-18 13:58:19 -050050os.remove(worklist.name)
51
John Stilesba06e1a2020-11-12 11:04:38 -050052# Invoke clang-format on every generated target.
53try:
Brian Osman7b239052020-11-18 17:04:33 +000054 output = subprocess.check_output([clangFormat, "--sort-includes=false", "-i"] + targets,
55 stderr=subprocess.STDOUT)
John Stilesba06e1a2020-11-12 11:04:38 -050056except subprocess.CalledProcessError as err:
57 print("### clang-format error:\n")
58 print("\n".join(err.output.splitlines()))