Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] utils/update-rust: use pathlib with relative paths
@ 2024-06-23 20:58 James Hilliard
  2024-07-10 21:06 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 3+ messages in thread
From: James Hilliard @ 2024-06-23 20:58 UTC (permalink / raw)
  To: buildroot; +Cc: James Hilliard

This avoids the requirement of running update-rust from TOPDIR and
is slightly cleaner.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 utils/update-rust | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/utils/update-rust b/utils/update-rust
index 6799324fac..b274beb85b 100755
--- a/utils/update-rust
+++ b/utils/update-rust
@@ -68,11 +68,11 @@ LICENSES = {
 
 
 def update_mk_file(mk_file, new_version):
-    with open(mk_file, "r") as fd:
+    with mk_file.open("r") as fd:
         lines = fd.readlines()
 
     version_var = pathlib.Path(mk_file).stem.upper().replace("-", "_") + "_VERSION"
-    with open(mk_file, "w") as fd:
+    with mk_file.open("w") as fd:
         for line in lines:
             words = line.split()
             if len(words) == 3 and words[0] == version_var and words[1] == "=":
@@ -82,8 +82,8 @@ def update_mk_file(mk_file, new_version):
 
 
 def gen_hash_file_src(hash_file, new_version):
-    with open(hash_file, "w") as fd:
-        fd.write(f"# Generated with {sys.argv[0]}\n# Do not edit manually\n\n")
+    with hash_file.open("w") as fd:
+        fd.write(f"# Generated with utils/update-rust\n# Do not edit manually\n\n")
         f_name = f"rustc-{new_version}-src.tar.xz"
         print(f"\r\033[KUpdating {f_name}", end="")
         h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
@@ -99,8 +99,8 @@ def gen_hash_file_src(hash_file, new_version):
 
 
 def gen_hash_file_bin(hash_file, new_version):
-    with open(hash_file, "w") as fd:
-        fd.write(f"# Generated with {sys.argv[0]}\n# Do not edit manually\n\n")
+    with hash_file.open("w") as fd:
+        fd.write(f"# Generated with utils/update-rust\n# Do not edit manually\n\n")
         for host in RUST_HOSTS:
             f_name = f"rust-{new_version}-{host}.tar.xz"
             print(f"\r\033[KUpdating {f_name}", end="")
@@ -132,13 +132,11 @@ def main():
 
     args = parser.parse_args()
 
-    try:
-        update_mk_file("package/rust/rust.mk", args.version)
-        update_mk_file("package/rust-bin/rust-bin.mk", args.version)
-        gen_hash_file_src("package/rust/rust.hash", args.version)
-        gen_hash_file_bin("package/rust-bin/rust-bin.hash", args.version)
-    except FileNotFoundError as e:
-        print(f"{e.filename}: {e.strerror} ({sys.argv[0]} must be run at the root of the Buildroot tree)")
+    TOPDIR = pathlib.Path(__file__).parent.parent
+    update_mk_file(TOPDIR / "package/rust/rust.mk", args.version)
+    update_mk_file(TOPDIR / "package/rust-bin/rust-bin.mk", args.version)
+    gen_hash_file_src(TOPDIR / "package/rust/rust.hash", args.version)
+    gen_hash_file_bin(TOPDIR / "package/rust-bin/rust-bin.hash", args.version)
 
     print("\r\033[K", end="")
 
-- 
2.34.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-10 21:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-23 20:58 [Buildroot] [PATCH 1/1] utils/update-rust: use pathlib with relative paths James Hilliard
2024-07-10 21:06 ` Thomas Petazzoni via buildroot
2024-07-10 21:17   ` James Hilliard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox