A fork of mtelver's day10 project

Remove --opam-repository from rerun and cascade commands

Both commands now read opam_repositories (and local_repos) from
build-config.json, which is written by batch. There's no reason to
specify it separately — these commands always operate on a cache
that was set up by a prior batch run.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+49 -41
+49 -41
day10/bin/main.ml
··· 2071 2071 let doc = "Directory containing opam repositories (required, can be specified multiple times)" in 2072 2072 Arg.(non_empty & opt_all string [] & info [ "opam-repository" ] ~docv:"OPAM-REPO" ~doc) 2073 2073 2074 + 2074 2075 let md_term = 2075 2076 let doc = "Output results in markdown format" in 2076 2077 Arg.(value & opt (some string) None & info [ "md" ] ~docv:"FILE" ~doc) ··· 2851 2852 (** Rerun a single build layer: read its layer.json for the original deps/hashes, 2852 2853 delete the layer, and rebuild using exactly the same inputs. No re-solving. 2853 2854 Records the result in history. *) 2854 - let rerun_build_layer ~cache_dir ~os_key ~opam_repositories ~arch ~os ~os_distribution ~os_family ~os_version ~packages_dir ~run_id ~build_hash = 2855 + let rerun_build_layer ~cache_dir ~os_key ~opam_repositories ~local_repos ~arch ~os ~os_distribution ~os_family ~os_version ~packages_dir ~run_id ~build_hash = 2855 2856 let layer_dir = Path.(cache_dir / os_key / build_hash) in 2856 2857 let layer_json = Path.(layer_dir / "layer.json") in 2857 2858 if not (Sys.file_exists layer_json) then begin ··· 2886 2887 with_test = false; with_doc = false; with_jtw = false; 2887 2888 doc_tools_repo = ""; doc_tools_branch = ""; 2888 2889 jtw_tools_repo = ""; jtw_tools_branch = ""; 2889 - local_repos = []; html_output = None; jtw_output = None; tag = None; 2890 + local_repos; html_output = None; jtw_output = None; tag = None; 2890 2891 log = false; dry_run = false; fork = None; prune_layers = false; blessed_map = None; 2891 2892 } in 2892 2893 let t = Container.init ~config in ··· 2955 2956 with _ -> () 2956 2957 end 2957 2958 2958 - let run_rerun ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~opam_repositories ~cascade ~target = 2959 + let run_rerun ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~cascade ~target = 2959 2960 let os_key = Printf.sprintf "%s-%s-%s" os_distribution os_version arch in 2960 2961 let packages_dir = Path.(cache_dir / os_key / "packages") in 2962 + (* Read opam_repositories from build-config.json *) 2963 + let build_config_path = Path.(cache_dir / os_key / "build-config.json") in 2964 + let (opam_repositories, local_repos) = 2965 + if Sys.file_exists build_config_path then begin 2966 + try 2967 + let json = Yojson.Safe.from_file build_config_path in 2968 + let open Yojson.Safe.Util in 2969 + let sl key = try json |> member key |> to_list |> List.map to_string with _ -> [] in 2970 + (sl "opam_repositories", sl "local_repos") 2971 + with _ -> 2972 + Printf.eprintf "Error: could not read %s\n%!" build_config_path; 2973 + Stdlib.exit 1 2974 + end else begin 2975 + Printf.eprintf "Error: no build-config.json found at %s (run batch first)\n%!" build_config_path; 2976 + Stdlib.exit 1 2977 + end 2978 + in 2961 2979 let run_id = Printf.sprintf "rerun-%s" (Day10_lib.Run_log.format_time (Unix.gettimeofday ())) in 2962 2980 (* Determine if target is a build hash or package name *) 2963 2981 let is_build_hash = String.length target > 6 && String.sub target 0 6 = "build-" in ··· 3007 3025 let rerun_hashes = List.map snd builds_to_rerun in 3008 3026 (* Rerun: delete layer, rebuild with same deps/hashes *) 3009 3027 let succeeded = List.filter_map (fun (_pkg_name, build_hash) -> 3010 - if rerun_build_layer ~cache_dir ~os_key ~opam_repositories ~arch ~os ~os_distribution ~os_family ~os_version ~packages_dir ~run_id ~build_hash then 3028 + if rerun_build_layer ~cache_dir ~os_key ~opam_repositories ~local_repos ~arch ~os ~os_distribution ~os_family ~os_version ~packages_dir ~run_id ~build_hash then 3011 3029 Some build_hash 3012 3030 else 3013 3031 None ··· 3016 3034 if cascade && succeeded <> [] then begin 3017 3035 let cascade_targets = find_cascade_targets ~packages_dir ~build_hashes:rerun_hashes in 3018 3036 if cascade_targets <> [] then begin 3019 - (* Read build-config.json from last batch run for doc tools etc *) 3020 - let build_config_path = Path.(cache_dir / os_key / "build-config.json") in 3037 + (* Read remaining config from build-config.json *) 3021 3038 let (with_doc, doc_tools_repo, doc_tools_branch, jtw_tools_repo, jtw_tools_branch, 3022 - html_output, jtw_output, local_repos) = 3023 - if Sys.file_exists build_config_path then begin 3024 - try 3025 - let json = Yojson.Safe.from_file build_config_path in 3026 - let open Yojson.Safe.Util in 3027 - let s key default = json |> member key |> to_string_option |> Option.value ~default in 3028 - let b key default = json |> member key |> to_bool_option |> Option.value ~default in 3029 - let so key = json |> member key |> to_string_option in 3030 - let sl key = try json |> member key |> to_list |> List.map to_string with _ -> [] in 3031 - Printf.printf "Using batch config from %s\n%!" build_config_path; 3032 - (b "with_doc" false, 3033 - s "doc_tools_repo" "", s "doc_tools_branch" "", 3034 - s "jtw_tools_repo" "", s "jtw_tools_branch" "", 3035 - so "html_output", so "jtw_output", sl "local_repos") 3036 - with _ -> 3037 - Printf.printf "Warning: could not read %s, cascading without docs\n%!" build_config_path; 3038 - (false, "", "", "", "", None, None, []) 3039 - end else begin 3040 - Printf.printf "Warning: no build-config.json found, cascading without docs\n%!"; 3041 - (false, "", "", "", "", None, None, []) 3042 - end 3039 + html_output, jtw_output) = 3040 + try 3041 + let json = Yojson.Safe.from_file build_config_path in 3042 + let open Yojson.Safe.Util in 3043 + let s key default = json |> member key |> to_string_option |> Option.value ~default in 3044 + let b key default = json |> member key |> to_bool_option |> Option.value ~default in 3045 + let so key = json |> member key |> to_string_option in 3046 + (b "with_doc" false, 3047 + s "doc_tools_repo" "", s "doc_tools_branch" "", 3048 + s "jtw_tools_repo" "", s "jtw_tools_branch" "", 3049 + so "html_output", so "jtw_output") 3050 + with _ -> (false, "", "", "", "", None, None) 3043 3051 in 3044 3052 Printf.printf "Cascading to %d packages with dependency_failure on rerun targets%s:\n%!" 3045 3053 (List.length cascade_targets) (if with_doc then " (with docs)" else ""); ··· 3077 3085 Arg.(value & flag & info [ "cascade" ] ~doc) 3078 3086 in 3079 3087 let rerun_term = 3080 - Term.(const (fun cache_dir format arch os os_distribution os_family os_version opam_repositories cascade target -> 3081 - run_rerun ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~opam_repositories ~cascade ~target) 3082 - $ cache_dir_term $ format_term $ arch_term $ os_term $ os_distribution_term $ os_family_term $ os_version_term $ opam_repository_term $ cascade_term $ target_arg) 3088 + Term.(const (fun cache_dir format arch os os_distribution os_family os_version cascade target -> 3089 + run_rerun ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~cascade ~target) 3090 + $ cache_dir_term $ format_term $ arch_term $ os_term $ os_distribution_term $ os_family_term $ os_version_term $ cascade_term $ target_arg) 3083 3091 in 3084 3092 let rerun_info = Cmd.info "rerun" ~doc:"Retry a failed build" in 3085 3093 Cmd.v rerun_info rerun_term ··· 3184 3192 let notify_info = Cmd.info "notify" ~doc:"Send a notification via configured channel" in 3185 3193 Cmd.v notify_info notify_term 3186 3194 3187 - let run_cascade ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~opam_repositories ~blessed_first ~dry_run ~fork = 3195 + let run_cascade ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~blessed_first ~dry_run ~fork = 3188 3196 let os_key = Printf.sprintf "%s-%s-%s" os_distribution os_version arch in 3189 3197 let os_dir = Path.(cache_dir / os_key) in 3190 3198 let packages_dir = Path.(os_dir / "packages") in ··· 3261 3269 if not dry_run then begin 3262 3270 (* Read build-config.json from last batch run *) 3263 3271 let build_config_path = Path.(cache_dir / os_key / "build-config.json") in 3264 - let (with_doc, doc_tools_repo, doc_tools_branch, jtw_tools_repo, jtw_tools_branch, 3272 + let (opam_repos, with_doc, doc_tools_repo, doc_tools_branch, jtw_tools_repo, jtw_tools_branch, 3265 3273 html_output, jtw_output, local_repos) = 3266 3274 if Sys.file_exists build_config_path then begin 3267 3275 try ··· 3272 3280 let so key = json |> member key |> to_string_option in 3273 3281 let sl key = try json |> member key |> to_list |> List.map to_string with _ -> [] in 3274 3282 Printf.printf "Using batch config from %s\n%!" build_config_path; 3275 - (b "with_doc" false, 3283 + (sl "opam_repositories", b "with_doc" false, 3276 3284 s "doc_tools_repo" "", s "doc_tools_branch" "", 3277 3285 s "jtw_tools_repo" "", s "jtw_tools_branch" "", 3278 3286 so "html_output", so "jtw_output", sl "local_repos") 3279 3287 with _ -> 3280 - Printf.printf "Warning: could not read %s, cascading without docs\n%!" build_config_path; 3281 - (false, "", "", "", "", None, None, []) 3288 + Printf.eprintf "Error: could not read %s\n%!" build_config_path; 3289 + Stdlib.exit 1 3282 3290 end else begin 3283 - Printf.printf "Warning: no build-config.json found, cascading without docs\n%!"; 3284 - (false, "", "", "", "", None, None, []) 3291 + Printf.eprintf "Error: no build-config.json found at %s (run batch first)\n%!" build_config_path; 3292 + Stdlib.exit 1 3285 3293 end 3286 3294 in 3287 3295 if with_doc then Printf.printf "Building with docs enabled\n%!"; 3288 3296 let run_id = Printf.sprintf "cascade-%s" (Day10_lib.Run_log.format_time (Unix.gettimeofday ())) in 3289 3297 let run_one (pkg, (e : Day10_lib.History.entry)) = 3290 3298 Printf.printf "Rerunning %s...\n%!" pkg; 3291 - run_health_check { dir = cache_dir; ocaml_version = None; opam_repositories; 3299 + run_health_check { dir = cache_dir; ocaml_version = None; opam_repositories = opam_repos; 3292 3300 package = pkg; arch; os; os_distribution; os_family; os_version; 3293 3301 directory = None; md = None; json = None; dot = None; 3294 3302 with_test = false; with_doc; with_jtw = false; ··· 3329 3337 Arg.(value & flag & info [ "blessed-first" ] ~doc) 3330 3338 in 3331 3339 let cascade_term = 3332 - Term.(const (fun cache_dir format arch os os_distribution os_family os_version opam_repositories blessed_first dry_run fork -> 3333 - run_cascade ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~opam_repositories ~blessed_first ~dry_run ~fork) 3334 - $ cache_dir_term $ format_term $ arch_term $ os_term $ os_distribution_term $ os_family_term $ os_version_term $ opam_repository_term $ blessed_first_term $ dry_run_term $ fork_term) 3340 + Term.(const (fun cache_dir format arch os os_distribution os_family os_version blessed_first dry_run fork -> 3341 + run_cascade ~cache_dir ~format ~arch ~os ~os_distribution ~os_family ~os_version ~blessed_first ~dry_run ~fork) 3342 + $ cache_dir_term $ format_term $ arch_term $ os_term $ os_distribution_term $ os_family_term $ os_version_term $ blessed_first_term $ dry_run_term $ fork_term) 3335 3343 in 3336 3344 let cascade_info = Cmd.info "cascade" ~doc:"Cascade reruns to reverse dependencies of recently fixed packages" in 3337 3345 Cmd.v cascade_info cascade_term