Ensure both generated and manual patches affect spec generation

Previous to this change, if there were no manual changes, the automatically
generated patch would not affect the calculated metadata, and result in
broken .spec files.
This commit is contained in:
Fabio Valentini 2022-07-26 12:13:47 +02:00
parent f0d04b09e8
commit 55998b3bd2
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF
2 changed files with 21 additions and 9 deletions

View file

@ -272,21 +272,32 @@ def make_patches(args, version, toml):
diff1 = diff2 = None diff1 = diff2 = None
toml_path = f"{args.crate}-{version}/Cargo.toml" toml_path = f"{args.crate}-{version}/Cargo.toml"
# We always do the automatic part before asking the user for more edits. # patching Cargo.toml involves multiple steps:
if toml_after := args.patch_foreign and drop_foreign_dependencies(toml_before): #
diff1 = make_diff(toml_path, toml_before, mtime_before, toml_after, mtime_before) # 1) attempt to automatically drop "foreign" dependencies
else: # If this succeeded, remove the original Cargo.toml file, write the
toml_after = toml_before # changed contents back to disk, and generate a diff.
# 2) if requested, open Cargo.toml in an editor for further, manual changes
#
# The changes from *both* steps must be reflected in the Cargo.toml file
# that ends up on disk after this function returns. Otherwise, the
# calculated metadata and generated spec file will not reflect the patches
# to Cargo.toml that were generated here.
if args.patch: if toml_after := args.patch_foreign and drop_foreign_dependencies(toml_before):
# remove original Cargo.toml file # remove original Cargo.toml file
os.remove(toml) os.remove(toml)
# write auto-patched Cargo.toml to disk # write auto-patched Cargo.toml to disk
with open(toml, "w") as file: with open(toml, "w") as file:
file.writelines(toml_after) file.writelines(toml_after)
file.flush()
diff1 = make_diff(toml_path, toml_before, mtime_before, toml_after, mtime_before)
else:
toml_after = toml_before
if args.patch:
# open editor for Cargo.toml
editor = util.detect_editor() editor = util.detect_editor()
subprocess.check_call([editor, toml]) subprocess.check_call([editor, toml])

View file

@ -116,8 +116,9 @@ def evaluate_atom(name: str) -> bool:
return False return False
case _: case _:
log.warn( log.warn(
f"Ignoring invalid atom {name!r} in cfg-expression. " f"Ignoring unknown identifier {name!r} in cfg-expression. "
+ 'Only "unix" and "windows" are valid names for atoms.' + 'Only "unix" and "windows" are standard identifiers, '
+ 'any non-standard "--cfg" flags are not supported.'
) )
return False return False