Bug 1686610 [wpt PR 27178] - Update <link> pseudo selector WPTs, a=testonly
[gecko.git] / build / clang-plugin / ThreadAllows.py
blobe45f6292546640629ac5ec77098ecc3b23834340
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
4 import json
6 FIRST_LINE = "// This file was generated by generate_thread_allows.py. DO NOT EDIT."
9 def generate_allows(input_paths):
10 """
11 This script reads in the ThreadAllows.txt and ThreadFileAllows.txt lists
12 and generates a header file containing a two arrays of allowed threads.
13 These can be the following formats:
14 -Files which the checker should ignore
15 These files either contain definitions of NS_NewNamedThread or
16 use args which the plugin can't cast (such as func args).
17 -Thread names which the checker should ignore
18 Specifies which individual thread names to ignore.
19 """
20 file_list = []
21 name_list = []
22 lines = set()
24 for path in input_paths:
25 with open(path) as file:
26 lines.update(file.readlines())
28 for line in sorted(lines):
29 """
30 We are assuming lines ending in .cpp, .h are files. Threads should
31 NOT have names containing filenames. Please don't do that.
32 """
33 line = line.strip()
34 if line.endswith(".cpp") or line.endswith(".h"):
35 file_list.append(line)
36 else:
37 name_list.append(line)
38 file_list_s = ",\n ".join(json.dumps(elem) for elem in file_list)
39 name_list_s = ",\n ".join(json.dumps(elem) for elem in name_list)
40 output_string = (
41 FIRST_LINE
42 + """
44 static const char *allow_thread_files[] = {
48 static const char *allow_thread_names[] = {
52 """
53 % (file_list_s, name_list_s)
55 return output_string
58 def generate_file(output, *input_paths):
59 output.write(generate_allows(input_paths))