| ... | ... | @@ -0,0 +1,61 @@ |
| 1 | //! This script updates the .c, .h, .s, and .S files that make up the start |
| 2 | //! files such as crt1.o. |
| 3 | //! |
| 4 | //! Example usage: |
| 5 | //! `zig run tools/update_openbsd_libc.zig -- ~/Downloads/openbsd-src .` |
| 6 | |
| 7 | const std = @import("std"); |
| 8 | const Io = std.Io; |
| 9 | |
| 10 | const exempt_files = [_][]const u8{ |
| 11 | // This file is maintained by a separate project and does not come from OpenBSD. |
| 12 | "abilists", |
| 13 | }; |
| 14 | |
| 15 | pub fn main(init: std.process.Init) !void { |
| 16 | const arena = init.arena.allocator(); |
| 17 | const io = init.io; |
| 18 | const args = try init.minimal.args.toSlice(arena); |
| 19 | |
| 20 | const openbsd_src_path = args[1]; |
| 21 | const zig_src_path = args[2]; |
| 22 | |
| 23 | const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/openbsd", .{zig_src_path}); |
| 24 | |
| 25 | var dest_dir = Io.Dir.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| { |
| 26 | std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err }); |
| 27 | std.process.exit(1); |
| 28 | }; |
| 29 | defer dest_dir.close(io); |
| 30 | |
| 31 | var openbsd_src_dir = try Io.Dir.cwd().openDir(io, openbsd_src_path, .{}); |
| 32 | defer openbsd_src_dir.close(io); |
| 33 | |
| 34 | // Copy updated files from upstream. |
| 35 | { |
| 36 | var walker = try dest_dir.walk(arena); |
| 37 | defer walker.deinit(); |
| 38 | |
| 39 | walk: while (try walker.next(io)) |entry| { |
| 40 | if (entry.kind != .file) continue; |
| 41 | if (std.mem.startsWith(u8, entry.basename, ".")) continue; |
| 42 | for (exempt_files) |p| { |
| 43 | if (std.mem.eql(u8, entry.path, p)) continue :walk; |
| 44 | } |
| 45 | |
| 46 | std.log.info("updating '{s}/{s}' from '{s}/{s}'", .{ |
| 47 | dest_dir_path, entry.path, |
| 48 | openbsd_src_path, entry.path, |
| 49 | }); |
| 50 | |
| 51 | openbsd_src_dir.copyFile(entry.path, dest_dir, entry.path, io, .{}) catch |err| { |
| 52 | std.log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{ |
| 53 | openbsd_src_path, entry.path, dest_dir_path, entry.path, err, |
| 54 | }); |
| 55 | if (err == error.FileNotFound) { |
| 56 | try dest_dir.deleteFile(io, entry.path); |
| 57 | } |
| 58 | }; |
| 59 | } |
| 60 | } |
| 61 | } |