Skip to content

Commit

Permalink
Merge pull request #209 from lefessan/z-2023-04-24-headers-and-create
Browse files Browse the repository at this point in the history
Bump to 0.9.2~dev3, fix on create
  • Loading branch information
lefessan authored Apr 27, 2023
2 parents 3a349aa + b465d56 commit 75a452c
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 52 deletions.
14 changes: 7 additions & 7 deletions .drom
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion drom.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion opam/drom.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion opam/drom_lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion opam/drom_toml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/drom_lib/commandNew.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ let create_project ~config ~name ~skeleton ~dir ~inplace ~args =
}
in
package.project <- p;

if not inplace then (
if Sys.file_exists name then
Error.raise "A directory %s already exists" name;
Expand All @@ -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

(* second, resolve package skeletons *)
let rec iter_skeleton package list =
match list with
Expand Down Expand Up @@ -212,12 +210,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 *)
Expand Down
6 changes: 4 additions & 2 deletions src/drom_lib/commandTree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 20 additions & 18 deletions src/drom_lib/ezPrintTree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/drom_lib/ezPrintTree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ module TYPES : sig

end

val print_tree : ?indent:string -> TYPES.tree -> unit
val print_tree : ?indent:string -> TYPES.tree -> string
1 change: 0 additions & 1 deletion src/drom_lib/project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 15 additions & 9 deletions src/drom_lib/skeleton.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/drom_lib/update.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,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

Expand Down Expand Up @@ -281,6 +281,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;
Expand All @@ -297,8 +298,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
Expand Down Expand Up @@ -347,7 +347,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
Expand Down
2 changes: 1 addition & 1 deletion src/drom_lib/version.mlt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/toml.7.1.0/version.mlt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 75a452c

Please sign in to comment.