forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-feature-flags
124 lines (92 loc) · 3.8 KB
/
find-feature-flags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
#
# Copyright (C) 2022 Sony Interactive Entertainment
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import argparse
import os
import sys
import webkitpy.featuredefines.search as search
_DESCRIPTION = """
Find feature flags within portions of the source code.
"""
_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))
_CHOICES = [
"definitions",
"platform",
"perl",
"cmake",
"all-code",
"native-code",
"cmake-code",
"idl-code",
]
def _search_with(choice):
mapping = {
"platform": search.FeatureDefinesPlatform,
"perl": search.FeatureDefinesPerl,
"cmake": search.FeatureDefinesCMake,
"native-code": search.FeatureDefinesUsageNativeCode,
"cmake-code": search.FeatureDefinesUsageCMakeCode,
"idl-code": search.FeatureDefinesUsageIdlCode,
}
return mapping[choice]()
def _parse_args(argv):
parser = argparse.ArgumentParser(description=_DESCRIPTION, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("find", help="the code to search", choices=_CHOICES, nargs="*")
parser.add_argument("--diff", choices=_CHOICES, action="append")
parser.add_argument("--macro", choices=["ENABLE", "USE", "HAVE"], default="ENABLE")
return parser.parse_args(argv)
def _choice_set(choices):
choices_set = set(choices)
if "definitions" in choices_set:
choices_set.remove("definitions")
choices_set.update(["platform", "perl", "cmake"])
if "all-code" in choices_set:
choices_set.remove("all-code")
choices_set.update(["native-code", "cmake-code", "idl-code"])
return choices_set
def _search_for(choices, macro):
found = set()
for choice in _choice_set(choices):
search_with = _search_with(choice)
search_with.search(_ROOT, macro)
found.update(search_with.definitions())
return found
def main(argv):
args = _parse_args(argv)
find_defines = _search_for(args.find, args.macro)
if args.diff:
diff_defines = _search_for(args.diff, args.macro)
only_find = find_defines.difference(diff_defines)
print("Only in Source (" + ",".join(args.find) + ")")
for item in sorted(only_find):
print(item)
only_diff = diff_defines.difference(find_defines)
print("Only in Diff (" + ",".join(args.diff) + ")")
for item in sorted(only_diff):
print(item)
else:
for item in sorted(find_defines):
print(item)
if __name__ == "__main__":
main(sys.argv[1:])