2 # Rust is fairly relaxed in checking the validity of arguments passed to #[cfg].
3 # While it should probably be more strict when checking features, it cannot be
4 # strict when checking loose cfg tags, because those can be anything and are
5 # simply passed to rustc via unconstrained arguments.
7 # Thus, we do it for rustc manually, but scanning all our source and checking
8 # that all our cfg tags match a known cfg tag.
11 def check_feature(feature):
14 elif feature == "no-std":
16 elif feature == "ahash":
18 elif feature == "hashbrown":
20 elif feature == "backtrace":
22 elif feature == "grind_signatures":
24 elif feature == "unsafe_revoked_tx_signing":
26 elif feature == "futures":
28 elif feature == "tokio":
30 elif feature == "rest-client":
32 elif feature == "rpc-client":
34 elif feature == "serde":
36 elif feature == "esplora-blocking":
38 elif feature == "esplora-async":
40 elif feature == "async-interface":
42 elif feature == "electrum":
44 elif feature == "time":
46 elif feature == "_test_utils":
48 elif feature == "_test_vectors":
50 elif feature == "afl":
52 elif feature == "honggfuzz":
54 elif feature == "libfuzzer_fuzz":
56 elif feature == "stdin_fuzz":
58 elif feature == "max_level_off":
60 elif feature == "max_level_error":
62 elif feature == "max_level_warn":
64 elif feature == "max_level_info":
66 elif feature == "max_level_debug":
68 elif feature == "max_level_trace":
71 print("Bad feature: " + feature)
74 def check_target_os(os):
80 def check_cfg_tag(cfg):
85 elif cfg == "debug_assertions":
87 elif cfg == "c_bindings":
89 elif cfg == "ldk_bench":
91 elif cfg == "taproot":
93 elif cfg == "async_signing":
95 elif cfg == "require_route_graph_test":
98 print("Bad cfg tag: " + cfg)
101 def check_cfg_args(cfg):
102 if cfg.startswith("all(") or cfg.startswith("any(") or cfg.startswith("not("):
105 while pos < len(cfg):
108 elif cfg[pos] == ")":
111 check_cfg_args(cfg[4:pos])
112 if pos + 1 != len(cfg):
113 assert cfg[pos + 1] == ","
114 check_cfg_args(cfg[pos + 2:].strip())
118 assert(cfg.endswith(")"))
119 check_cfg_args(cfg[4:len(cfg)-1])
121 parts = [part.strip() for part in cfg.split(",", 1)]
125 elif cfg.startswith("feature") or cfg.startswith("target_os") or cfg.startswith("target_pointer_width"):
127 if cfg.startswith("feature"):
128 arg = arg[7:].strip()
129 elif cfg.startswith("target_os"):
130 arg = arg[9:].strip()
132 arg = arg[20:].strip()
133 assert arg.startswith("=")
134 arg = arg[1:].strip()
135 assert arg.startswith("\"")
136 assert arg.endswith("\"")
137 arg = arg[1:len(arg)-1]
138 assert not "\"" in arg
139 if cfg.startswith("feature"):
141 elif cfg.startswith("target_os"):
144 assert arg == "32" or arg == "64"
146 check_cfg_tag(cfg.strip())
148 cfg_regex = re.compile("#\[cfg\((.*)\)\]")
149 for path in glob.glob(sys.path[0] + "/../**/*.rs", recursive = True):
150 with open(path, "r") as file:
152 line = file.readline()
156 if not line.strip().startswith("//"):
157 cfg_part = cfg_regex.match(line.strip()).group(1)
158 check_cfg_args(cfg_part)