From d1322d74f98d3370b5a3b46c8b6be93f4f1cfba7 Mon Sep 17 00:00:00 2001 From: Fabrice Le Fessant Date: Thu, 27 Apr 2023 16:19:04 +0200 Subject: [PATCH 1/2] Bump to 0.9.2~dev3, fix on create --- .drom | 14 ++++++------- drom.toml | 2 +- dune-project | 2 +- opam/drom.opam | 2 +- opam/drom_lib.opam | 2 +- opam/drom_toml.opam | 2 +- src/drom_lib/commandNew.ml | 8 +++++--- src/drom_lib/commandTree.ml | 6 ++++-- src/drom_lib/ezPrintTree.ml | 38 +++++++++++++++++++----------------- src/drom_lib/ezPrintTree.mli | 2 +- src/drom_lib/skeleton.ml | 24 ++++++++++++++--------- src/drom_lib/update.ml | 10 ++++++---- src/drom_lib/version.mlt | 2 +- src/toml.7.1.0/version.mlt | 2 +- 14 files changed, 65 insertions(+), 51 deletions(-) diff --git a/.drom b/.drom index 42940a29..736fa3c9 100644 --- a/.drom +++ b/.drom @@ -5,7 +5,7 @@ version:0.9.0 # hash of toml configuration files # used for generation of all files -6f93b9b249b9706a653351f9bf7f2764:. +27968ad2d0e5e4bf2de6882737668c66:. # end context for . # begin context for .github/workflows/workflow.yml @@ -100,22 +100,22 @@ e850a13c004f963e9f5a568eac93c217:dune # begin context for dune-project # file dune-project -ef11813030a7a485db7aeac417925033:dune-project +f8f5311a3752d34fcd492d98660840ad:dune-project # end context for dune-project # begin context for opam/drom.opam # file opam/drom.opam -26ed2b90335a3336f17264c5159f73c8:opam/drom.opam +2de609a6a5c806247b3bdd82f913a109:opam/drom.opam # end context for opam/drom.opam # begin context for opam/drom_lib.opam # file opam/drom_lib.opam -aebe634fcda0c9b568e4becec97db6e7:opam/drom_lib.opam +38acddee945b9967310158787939ea09:opam/drom_lib.opam # end context for opam/drom_lib.opam # begin context for opam/drom_toml.opam # file opam/drom_toml.opam -7b1dd39dd0f5668232a6f436c20d27a8:opam/drom_toml.opam +0414e4eed49fb8e24683f51dfd27d7d3:opam/drom_toml.opam # end context for opam/drom_toml.opam # begin context for scripts/after.sh @@ -210,7 +210,7 @@ e7ddb8c3da7d7b47c8100964303ba50a:src/drom_lib/dune # begin context for src/drom_lib/version.mlt # file src/drom_lib/version.mlt -abcd112b76fdd31f509bb6e3402f1a11:src/drom_lib/version.mlt +9749ccfb897b43e7f10913c8ee636af5:src/drom_lib/version.mlt # end context for src/drom_lib/version.mlt # begin context for src/toml.7.1.0/dune @@ -235,7 +235,7 @@ d1b05207fce876a1b44a8b268bcaf226:src/toml.7.1.0/index.mld # begin context for src/toml.7.1.0/version.mlt # file src/toml.7.1.0/version.mlt -abcd112b76fdd31f509bb6e3402f1a11:src/toml.7.1.0/version.mlt +9749ccfb897b43e7f10913c8ee636af5:src/toml.7.1.0/version.mlt # end context for src/toml.7.1.0/version.mlt # begin context for test/expect-tests/dune diff --git a/drom.toml b/drom.toml index 87bde23d..3c66425f 100644 --- a/drom.toml +++ b/drom.toml @@ -15,7 +15,7 @@ min-edition = "4.07.0" name = "drom" skeleton = "program" synopsis = "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience" -version = "0.9.2~dev2" +version = "0.9.2~dev3" # keys that you could also define: # odoc-target = "...odoc-target..." diff --git a/dune-project b/dune-project index f5df2606..19ba757f 100644 --- a/dune-project +++ b/dune-project @@ -5,7 +5,7 @@ (name drom) (allow_approximate_merlin) (generate_opam_files false) -(version 0.9.2~dev2) +(version 0.9.2~dev3) (formatting (enabled_for ocaml reason)) (using menhir 2.0) diff --git a/opam/drom.opam b/opam/drom.opam index d6d4efaa..fe14cdb3 100644 --- a/opam/drom.opam +++ b/opam/drom.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "drom" -version: "0.9.2~dev2" +version: "0.9.2~dev3" license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" synopsis: "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience" diff --git a/opam/drom_lib.opam b/opam/drom_lib.opam index f8fcecd5..8a80e69b 100644 --- a/opam/drom_lib.opam +++ b/opam/drom_lib.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "drom_lib" -version: "0.9.2~dev2" +version: "0.9.2~dev3" license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" synopsis: "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience" diff --git a/opam/drom_toml.opam b/opam/drom_toml.opam index 5ee2a10b..9920073a 100644 --- a/opam/drom_toml.opam +++ b/opam/drom_toml.opam @@ -2,7 +2,7 @@ # Do not modify, or add to the `skip` field of `drom.toml`. opam-version: "2.0" name: "drom_toml" -version: "0.9.2~dev2" +version: "0.9.2~dev3" license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" synopsis: "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience" diff --git a/src/drom_lib/commandNew.ml b/src/drom_lib/commandNew.ml index cd296f35..191342c9 100644 --- a/src/drom_lib/commandNew.ml +++ b/src/drom_lib/commandNew.ml @@ -145,7 +145,7 @@ let create_project ~config ~name ~skeleton ~dir ~inplace ~args = } in package.project <- p; - + Printf.eprintf "(0.1) project_create = %b\n%!" p.project_create ; if not inplace then ( if Sys.file_exists name then Error.raise "A directory %s already exists" name; @@ -167,7 +167,7 @@ let create_project ~config ~name ~skeleton ~dir ~inplace ~args = (p, Some content) ) in let p, p_content = iter_skeleton skeleton.skeleton_toml in - + Printf.eprintf "(0.2) project_create = %b\n%!" p.project_create ; (* second, resolve package skeletons *) let rec iter_skeleton package list = match list with @@ -212,12 +212,14 @@ let create_project ~config ~name ~skeleton ~dir ~inplace ~args = (* Set fields that are not in templates *) let p = { p with + project_create = true ; project_share_repo = Some ( Share.share_repo_default () ); project_share_version = Some share.share_version ; } in Update.update_files share ~warning:false ~twice:true ~git:true ~args p; - print_dir (name ^ "/") "."; + let tree = print_dir (name ^ "/") "." in + Printf.eprintf "%s%!" tree ; Update.display_create_warning p (* lookup for "drom.toml" and update it *) diff --git a/src/drom_lib/commandTree.ml b/src/drom_lib/commandTree.ml index c2a0b8a0..8b98c4c5 100644 --- a/src/drom_lib/commandTree.ml +++ b/src/drom_lib/commandTree.ml @@ -108,8 +108,10 @@ let action () = in print_deps "dependencies" p.dependencies; print_deps "tools" p.tools; - EzPrintTree.print_tree (Branch ("File drom.toml", List.rev !branches)); - () + let tree = + EzPrintTree.print_tree (Branch ("File drom.toml", List.rev !branches)) + in + Printf.printf "%s%!" tree let cmd = EZCMD.sub cmd_name action ~doc:"Display a tree of dependencies" diff --git a/src/drom_lib/ezPrintTree.ml b/src/drom_lib/ezPrintTree.ml index 2a1dd2db..9e5df5b2 100644 --- a/src/drom_lib/ezPrintTree.ml +++ b/src/drom_lib/ezPrintTree.ml @@ -20,31 +20,33 @@ let up_right_down = "├──" let up_right = "└──" -let print_tree indent tree = +let print_tree b indent tree = let rec iter indent ~last = function | Branch (s, branches) -> - Printf.printf "%s%s %s\n" indent - ( if last then - up_right - else - up_right_down ) - s; - iter_branches - ( indent - ^ - if last then - " " - else - up_down ) - branches + Printf.bprintf b "%s%s %s\n" indent + ( if last then + up_right + else + up_right_down ) + s; + iter_branches + ( indent + ^ + if last then + " " + else + up_down ) + branches and iter_branches indent = function | [] -> () | [ branch ] -> iter (indent ^ " ") ~last:true branch | branch :: branches -> - iter (indent ^ " ") ~last:false branch; - iter_branches indent branches + iter (indent ^ " ") ~last:false branch; + iter_branches indent branches in iter indent ~last:true tree let print_tree ?(indent = "") tree = - print_tree indent tree + let b = Buffer.create 10_000 in + print_tree b indent tree ; + Buffer.contents b diff --git a/src/drom_lib/ezPrintTree.mli b/src/drom_lib/ezPrintTree.mli index 1c5939cb..1afee1a1 100644 --- a/src/drom_lib/ezPrintTree.mli +++ b/src/drom_lib/ezPrintTree.mli @@ -14,4 +14,4 @@ module TYPES : sig end -val print_tree : ?indent:string -> TYPES.tree -> unit +val print_tree : ?indent:string -> TYPES.tree -> string diff --git a/src/drom_lib/skeleton.ml b/src/drom_lib/skeleton.ml index f37d2f6d..3382a0e1 100644 --- a/src/drom_lib/skeleton.ml +++ b/src/drom_lib/skeleton.ml @@ -186,15 +186,16 @@ let load_skeleton ~version ~drom ~dir ~toml ~kind = skeleton_version = version; } ) -let load_dir_skeletons ~version ~drom kind dir = - let map = ref StringMap.empty in +let load_dir_skeletons ?(map=StringMap.empty) ~version ~drom kind dir = + let map = ref map in if Sys.file_exists dir then begin EzFile.iter_dir dir ~f:(fun file -> let dir = dir // file in let toml = dir // "skeleton.toml" in if Sys.file_exists toml then try - let name, skeleton = load_skeleton ~version ~drom ~dir ~toml ~kind in + let name, skeleton = load_skeleton ~version ~drom ~dir ~toml ~kind + in if !Globals.verbosity > 0 && StringMap.mem name !map then Printf.eprintf "Warning: %s skeleton %S overwritten in %s\n%!" kind name dir; @@ -208,15 +209,20 @@ let load_dir_skeletons ~version ~drom kind dir = end else !map -let kind_dir ~kind = ("skeletons" // kind) ^ "s" - -(* TODO: the project should be able to specify its own URL for the skeleton repo *) +(* TODO: the project should be able to specify its own URL for the + skeleton repo *) let load_skeletons share kind = let dir = share.share_dir in let version = share.share_version in - let global_skeletons_dir = dir // kind_dir ~kind in - load_dir_skeletons ~version ~drom:true kind global_skeletons_dir - + let subdir = kind ^ "s" in + List.fold_left (fun map dir -> + load_dir_skeletons ~map ~version ~drom:true kind dir + ) + StringMap.empty + [ + dir // "skeletons" // subdir ; + dir // subdir ; + ] let rec inherit_files self_files super_files = match (self_files, super_files) with diff --git a/src/drom_lib/update.ml b/src/drom_lib/update.ml index 9e5c0493..e08f17de 100644 --- a/src/drom_lib/update.ml +++ b/src/drom_lib/update.ml @@ -145,6 +145,7 @@ let update_files share ?args ?(git = false) p = | Some edition -> ({ p with edition }, true) in + Printf.eprintf "(1.1) project_create = %b\n%!" p.project_create ; let p, changed = match args.arg_create with | None -> (p, changed) @@ -154,6 +155,7 @@ let update_files share ?args ?(git = false) p = else ({ p with project_create = bool }, true) in + Printf.eprintf "(1.2) project_create = %b\n%!" p.project_create ; let p, changed = match args.arg_min_edition with @@ -188,7 +190,7 @@ let update_files share ?args ?(git = false) p = else (p, changed) in - let create = p.project_create in + let create_phase = p.project_create in let can_skip = ref [] in @@ -281,6 +283,7 @@ let update_files share ?args ?(git = false) p = filename content = try + if create && not create_phase then raise Skip; if skip then raise Skip; if force then ( Printf.eprintf "Forced Update of file %s\n%!" filename; @@ -297,8 +300,7 @@ let update_files share ?args ?(git = false) p = if Globals.verbose 2 then Printf.eprintf "Creating file %s\n%!" filename; write_file hashes filename content ~perm - ) else if create then - raise Skip + ) else if can_update ~filename ~perm hashes content then ( Printf.eprintf "Updating file %s\n%!" filename; write_file hashes filename content ~perm @@ -347,7 +349,7 @@ let update_files share ?args ?(git = false) p = | None -> () end; - if create then + if create_phase then if git && not (Sys.file_exists ".git") then ( Git.call "init" [ "-q" ]; match config.config_github_organization with diff --git a/src/drom_lib/version.mlt b/src/drom_lib/version.mlt index b7864b1a..c62bcc63 100644 --- a/src/drom_lib/version.mlt +++ b/src/drom_lib/version.mlt @@ -13,7 +13,7 @@ let query cmd = let commit_hash = query "git show -s --pretty=format:%H" let commit_date = query "git show -s --pretty=format:%ci" -let version = "0.9.2~dev2" +let version = "0.9.2~dev3" let string_option = function | None -> "None" diff --git a/src/toml.7.1.0/version.mlt b/src/toml.7.1.0/version.mlt index b7864b1a..c62bcc63 100644 --- a/src/toml.7.1.0/version.mlt +++ b/src/toml.7.1.0/version.mlt @@ -13,7 +13,7 @@ let query cmd = let commit_hash = query "git show -s --pretty=format:%H" let commit_date = query "git show -s --pretty=format:%ci" -let version = "0.9.2~dev2" +let version = "0.9.2~dev3" let string_option = function | None -> "None" From b465d56e5cc58e7d362c9cbba28203d20a67ff30 Mon Sep 17 00:00:00 2001 From: Fabrice Le Fessant Date: Thu, 27 Apr 2023 16:28:02 +0200 Subject: [PATCH 2/2] remove debug printfs --- src/drom_lib/commandNew.ml | 2 -- src/drom_lib/project.ml | 1 - src/drom_lib/update.ml | 2 -- 3 files changed, 5 deletions(-) diff --git a/src/drom_lib/commandNew.ml b/src/drom_lib/commandNew.ml index 191342c9..251f0e9f 100644 --- a/src/drom_lib/commandNew.ml +++ b/src/drom_lib/commandNew.ml @@ -145,7 +145,6 @@ let create_project ~config ~name ~skeleton ~dir ~inplace ~args = } in package.project <- p; - Printf.eprintf "(0.1) project_create = %b\n%!" p.project_create ; if not inplace then ( if Sys.file_exists name then Error.raise "A directory %s already exists" name; @@ -167,7 +166,6 @@ let create_project ~config ~name ~skeleton ~dir ~inplace ~args = (p, Some content) ) in let p, p_content = iter_skeleton skeleton.skeleton_toml in - Printf.eprintf "(0.2) project_create = %b\n%!" p.project_create ; (* second, resolve package skeletons *) let rec iter_skeleton package list = match list with diff --git a/src/drom_lib/project.ml b/src/drom_lib/project.ml index c128145a..e938780e 100644 --- a/src/drom_lib/project.ml +++ b/src/drom_lib/project.ml @@ -86,7 +86,6 @@ let to_files share p = p.project_share_version in let version = - Printf.eprintf "drom version : %s\n%!" share.drom_version ; if VersionCompare.compare share.drom_version "0.9.2~dev2" > 0 then begin version |> EzToml.put_bool [ "project"; "create-project" ] p.project_create diff --git a/src/drom_lib/update.ml b/src/drom_lib/update.ml index e08f17de..17755ba1 100644 --- a/src/drom_lib/update.ml +++ b/src/drom_lib/update.ml @@ -145,7 +145,6 @@ let update_files share ?args ?(git = false) p = | Some edition -> ({ p with edition }, true) in - Printf.eprintf "(1.1) project_create = %b\n%!" p.project_create ; let p, changed = match args.arg_create with | None -> (p, changed) @@ -155,7 +154,6 @@ let update_files share ?args ?(git = false) p = else ({ p with project_create = bool }, true) in - Printf.eprintf "(1.2) project_create = %b\n%!" p.project_create ; let p, changed = match args.arg_min_edition with