rust2rpm: only remove optional target-specific deps from features

This commit is contained in:
Fabio Valentini 2022-10-09 21:24:21 +02:00
parent c026764e94
commit 5bc8840a67
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF

View file

@ -204,30 +204,41 @@ def filter_out_features_re(dropped_features):
def drop_foreign_dependencies(lines): def drop_foreign_dependencies(lines):
dropped_lines = 0 dropped_lines = 0
dropped_features = set() dropped_optional_deps = set()
good_lines = [] good_lines = []
value = True keep = True
feature = None
for line in lines: for line in lines:
if m := TARGET_DEPENDENCY_LINE.match(line): if m := TARGET_DEPENDENCY_LINE.match(line):
expr = m.group("cfg") expr = m.group("cfg")
expr = ast.literal_eval(expr) expr = ast.literal_eval(expr)
try: try:
value = cfg.parse_and_evaluate(expr) keep = cfg.parse_and_evaluate(expr)
except (ValueError, cfg.ParseException): except (ValueError, cfg.ParseException):
log.warn(f"Could not evaluate {expr!r}, treating as true.") log.warn(f"Could not evaluate {expr!r}, treating as true.")
value = True keep = True
if not value: if not keep:
feature = m.group("feature") feature = m.group("feature")
log.info(f"Dropping target-specific dependency on {feature!r}.") log.info(f"Dropping target-specific dependency on {feature!r}.")
dropped_features.add(feature)
elif line == "optional = true\n" and feature:
if not keep:
# dropped feature was optional:
# remove occurrences from feature dependencies
dropped_optional_deps.add(feature)
else:
# optional dependency occurs in multiple targets:
# do not drop from feature dependencies
if feature in dropped_optional_deps:
dropped_optional_deps.remove(feature)
elif line.startswith("["): elif line.startswith("["):
# previous section ended, let's keep printing lines again # previous section ended, let's keep printing lines again
value = True keep = True
if value: if keep:
good_lines += [line] good_lines += [line]
else: else:
dropped_lines += 1 dropped_lines += 1
@ -238,7 +249,7 @@ def drop_foreign_dependencies(lines):
good_lines2 = [] good_lines2 = []
in_features = False in_features = False
filt = filter_out_features_re(dropped_features) filt = filter_out_features_re(dropped_optional_deps)
for line in good_lines: for line in good_lines:
if line.rstrip() == "[features]": if line.rstrip() == "[features]":
in_features = True in_features = True