diff --git a/README.md b/README.md index 07f7bf5..c88f715 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,9 @@ You can also build locally: You need OCaml ≥ 4.03.0 together with [`nonstd`](http://www.hammerlab.org/docs/nonstd/master/index.html), [`sosa`](http://www.hammerlab.org/docs/sosa/master/index.html), and -[`jbuilder`](https://github.com/janestreet/jbuilder): +[`dune`](https://github.com/janestreet/dune): - ocaml please.mlt configure - jbuilder build @install + dune build @install Getting Started --------------- @@ -148,7 +147,7 @@ To run the tests you also need `make` and there is an additional dependency on the `uri` library, see: genspio_test=_build/default/src/test/main.exe - jbuilder build $genspio_test + dune build $genspio_test $genspio_test --help diff --git a/doc/extra-testing.md b/doc/extra-testing.md index 49f08b2..fd39ef9 100644 --- a/doc/extra-testing.md +++ b/doc/extra-testing.md @@ -89,7 +89,7 @@ provides a command line tool to generate “Qemu” environments. You can build it with: export genspio_vm_tester=_build/default/src/examples/vm_tester.exe - jbuilder build $genspio_vm_tester + dune build $genspio_vm_tester A version is also available in the genspio-doc docker-images (note that the [build](https://hub.docker.com/r/smondet/genspio-doc-dockerfiles/builds/) diff --git a/genspio.opam b/genspio.opam index 4edccac..682e2ba 100644 --- a/genspio.opam +++ b/genspio.opam @@ -1,4 +1,3 @@ -# This Opam file was auto-generated, see the `please.mlt` script. opam-version: "2.0" maintainer: "Seb Mondet " authors: [ @@ -10,7 +9,6 @@ dev-repo: "git+https://github.com/hammerlab/genspio.git" license: "Apache 2.0" version: "0.0.3-dev" build: [ - ["ocaml" "please.mlt" "configure"] ["dune" "build" "-p" name "-j" jobs ] ] depends: [ diff --git a/please.mlt b/please.mlt deleted file mode 100644 index a542882..0000000 --- a/please.mlt +++ /dev/null @@ -1,70 +0,0 @@ -;; -#use "tools/please_lib.ml" - -let version = "0.0.3-dev" - -let main_libs = ["nonstd"; "sosa"] - -let toplevel_merlin = Merlin.lines ~s:["."; "tools"] ~pkg:main_libs () - -let meta_content = - String.concat ~sep:"\n" - [ "(** Metadata Module Generated by the Build System *)" - ; "" - ; sprintf "let version = %S" version ] - -let synopsis = "Typed EDSL to generate POSIX Shell scripts" - -let description = - "Genspio is a typed EDSL used to generate shell scripts and commands from \ - OCaml.\n\n\ - The idea is to build values of type `'a Genspio.EDSL.t` with the\n\ - combinators in the `Genspio.EDSL` module, and compile them to POSIX\n\ - shell scripts (or one-liners) with functions from `Genspio.Compile`.\n\n\ - Genspio's documentation root is at ." - -let describe _ = print_endline description - -let files = - let open File in - let open Dune in - [ file ".merlin" toplevel_merlin - ; file "src/lib/dune" - @@ dune - [ rule ~targets:["meta.ml"] [write_file "meta.ml" meta_content] - ; lib "genspio" ~deps:main_libs ] - ; file "src/test-lib/dune" - @@ dune - [lib "tests" ~deps:("genspio" :: "uri" :: main_libs) ~internal:true] - ; file "src/test/dune" - @@ dune [executable "main" ~libraries:("genspio" :: "tests" :: main_libs)] - ; file "src/examples/dune" - @@ dune - [ executable ~single_module:true "downloader" - ~libraries:("genspio" :: main_libs) - ; executable ~single_module:true "vm_tester" - ~libraries:("genspio" :: main_libs) - ; executable ~single_module:true "service_composer" - ~libraries:("unix" :: "genspio" :: main_libs) - ; executable ~single_module:true "multigit" - ~libraries:("unix" :: "genspio" :: main_libs) - ; executable ~single_module:true "small" - ~libraries:("genspio" :: main_libs) - ; rule ~targets:["small_examples.ml"] ~deps:["small.exe"] - [sprintf "(run ./small.exe small_examples.ml)"] - ; executable ~single_module:true "small_examples" - ~libraries:("genspio" :: "tests" :: main_libs) ] - ; repo_file "genspio.opam" - Opam.( - v2 "genspio" ~maintainer:"Seb Mondet " - ~dev_repo:"git+https://github.com/hammerlab/genspio.git" - ~bug_reports:"https://github.com/hammerlab/genspio/issues" - ~homepage:"https://smondet.gitlab.io/genspio-doc/" - ~license:"Apache 2.0" ~version ~ocaml_min_version:"4.03.0" - ~description ~synopsis - ~deps: - ( Opam.dep "dune" - :: List.map main_libs ~f:dep )) ] - -let () = - Main.make ~files ~describe ~version:(fun _ -> print_endline version) () diff --git a/src/examples/dune b/src/examples/dune index e5cca5e..c8fb822 100644 --- a/src/examples/dune +++ b/src/examples/dune @@ -1,4 +1,3 @@ -;; Generated by `please_lib.ml` (executable (name downloader) (libraries genspio nonstd sosa)(modules downloader)) (executable (name vm_tester) (libraries genspio nonstd sosa)(modules vm_tester)) (executable (name service_composer) (libraries unix genspio nonstd sosa)(modules service_composer)) diff --git a/src/examples/multigit.ml b/src/examples/multigit.ml index e2dc03b..5a5c8d7 100644 --- a/src/examples/multigit.ml +++ b/src/examples/multigit.ml @@ -3,7 +3,7 @@ A simple way to generate and install the scripts is: genspio_multigit=_build/default/src/examples/multigit.exe - jbuilder build $genspio_multigit + dune build $genspio_multigit $genspio_multigit $BINNPATH *) diff --git a/src/examples/service_composer.ml b/src/examples/service_composer.ml index 3409978..a76bb51 100644 --- a/src/examples/service_composer.ml +++ b/src/examples/service_composer.ml @@ -5,7 +5,7 @@ modules. A simple way to generate and install the scripts is: genspio_service_composer=_build/default/src/examples/service_composer.exe - jbuilder build $genspio_service_composer + dune build $genspio_service_composer $genspio_service_composer --name cosc --output-path $BINNPATH The `cosc*` scripts will be installed and ready to use in `$BINPATH` diff --git a/src/lib/dune b/src/lib/dune index 35af884..3c7b058 100644 --- a/src/lib/dune +++ b/src/lib/dune @@ -1,4 +1,3 @@ -;; Generated by `please_lib.ml` (rule (targets meta.ml)(deps )(action (progn (write-file "meta.ml" "(** Metadata Module Generated by the Build System *)\n\nlet version = \"0.0.3-dev\"")))) (library (name genspio) (public_name genspio) (libraries nonstd sosa) ) diff --git a/src/test-lib/dune b/src/test-lib/dune index ea33a17..8617370 100644 --- a/src/test-lib/dune +++ b/src/test-lib/dune @@ -1,2 +1 @@ -;; Generated by `please_lib.ml` (library (name tests) (libraries genspio uri nonstd sosa) ) diff --git a/src/test/dune b/src/test/dune index 8574c1e..abe8623 100644 --- a/src/test/dune +++ b/src/test/dune @@ -1,2 +1,2 @@ -;; Generated by `please_lib.ml` (executable (name main) (libraries genspio tests nonstd sosa)) + diff --git a/tools/build-doc.sh b/tools/build-doc.sh index a738045..7900ba4 100644 --- a/tools/build-doc.sh +++ b/tools/build-doc.sh @@ -4,10 +4,9 @@ set -e genspio_small_examples=_build/default/src/examples/small_examples.exe -ocaml please.mlt configure -jbuilder build @install -jbuilder build @doc -jbuilder build $genspio_small_examples +dune build @install +dune build @doc +dune build $genspio_small_examples export output_path=_build/doc/html/ rm -fr $output_path diff --git a/tools/please_lib.ml b/tools/please_lib.ml deleted file mode 100644 index 047bb5a..0000000 --- a/tools/please_lib.ml +++ /dev/null @@ -1,230 +0,0 @@ -(** - A not-really-library to create ["configure.ml"] (or ["please.ml"]) files. - - Add the file in your repo somewhere and [#use] it in your repo. - - {[ - #use "tools/please_lib.ml";; - ]} - - -*) - -module String = StringLabels -module List = ListLabels -open Printf - -let ( // ) = Filename.concat - -module Util = struct - let write_lines p l = - let o = open_out p in - List.iter l ~f:(fprintf o "%s\n") ; - close_out o - - let cmdf fmt = - ksprintf - (fun s -> - match Sys.command s with - | 0 -> () - | other -> ksprintf failwith "Command %S returned %d" s other ) - fmt -end - -module Merlin = struct - let lines ?(pkg = []) ?(s = []) () = - List.map s ~f:(sprintf "S %s") @ List.map pkg ~f:(sprintf "PKG %s") -end - -module Dune = struct - let dune l = [";; Generated by `please_lib.ml`"] @ l - - let executable ?(ppx = []) ?(modules = []) ?(single_module = false) - ~libraries name = - sprintf "(executable (name %s) %s (libraries %s)%s)" name - ( if ppx = [] then "" - else sprintf "(preprocess (pps (%s)))" (String.concat ~sep:" " ppx) ) - (String.concat libraries ~sep:" ") - ( match (single_module, modules) with - | true, [] -> sprintf "(modules %s)" name - | true, _ -> - failwith "Cannot call `executable` with ~single_module and ~modules" - | false, [] -> "" - | false, more -> sprintf "(modules (%s))" (String.concat " " more) ) - - let rule ~targets ?(deps = []) actions = - sprintf "(rule (targets %s)(deps %s)(action (progn\n%s)))" - (String.concat ~sep:" " targets) - (String.concat ~sep:" " deps) - (String.concat ~sep:"\n" actions) - - let with_stdout_to path l = - sprintf "(with-stdout-to %S (progn %s))" path - (String.concat ~sep:"\n " l) - - let progn l = sprintf "(progn %s)" (String.concat ~sep:"\n" l) - - let echo s = sprintf "(echo %S)" s - - let write_file path content = sprintf "(write-file %S %S)" path content - - let run l = - sprintf "(run %s)" (List.map ~f:(sprintf "%S") l |> String.concat ~sep:" ") - - let install ?(section = "bin") ~package ?(files = []) () = - sprintf - "(install ((section %s)\n\ - \ (package %s)\n\ - \ (files (\n\ - %s\n\ - ))))" - section package - ( List.map files ~f:(function `As (a, b) -> sprintf " (%s as %s)" a b ) - |> String.concat ~sep:"\n" ) - - let lib ?(deps = []) ?(internal = false) name = - sprintf "(library (name %s) %s (libraries %s) )" name - ( if internal then "" - else - sprintf "(public_name %s)" - (String.map name ~f:(function '_' -> '-' | c -> c)) ) - (String.concat deps ~sep:" ") -end - -module Opam = struct - type qualifier = - [`Build | `Version of [`GT] * string | `And of qualifier * qualifier] - - let qualifier_to_string q = - let rec go = function - | `And (a, b) -> sprintf "%s & %s" (go a) (go b) - | `Build -> "build" - | `Version (`GT, s) -> sprintf ">= %S" s - in - sprintf "{%s}" (go q) - - let dep ?qualify ?(build = false) n = - sprintf "%S%s" n - ( match (qualify, build) with - | None, false -> "" - | None, true -> " " ^ qualifier_to_string `Build - | Some q, false -> " " ^ qualifier_to_string q - | Some q, true -> " " ^ qualifier_to_string (`And (`Build, q)) ) - - let obvious_deps = [dep "dune"] - - let make ?(opam_version = "1.2") ~maintainer ?authors ?(deps = obvious_deps) - ~homepage ?bug_reports ?dev_repo ?(license = "ISC") ?version - ?(ocaml_min_version = "4.03.0") ?(configure_script = "please.mlt") name = - let string k v = sprintf "%s: %S" k v in - let opt_default o d = match o with None -> d | Some s -> s in - let opt_f f k v = match v with None -> [] | Some s -> [f k s] in - (let opt_string k v = opt_f string k v in - [ sprintf "# This Opam file was auto-generated, see the `%s` script." - configure_script - ; string "opam-version" opam_version - ; string "maintainer" maintainer - ; (match authors with None -> [maintainer] | Some l -> l) - |> List.map ~f:(sprintf "%S") - |> String.concat ~sep:"\n " - |> sprintf "authors: [\n %s\n]" - ; string "homepage" homepage - ; string "bug-reports" (opt_default bug_reports (homepage // "issues")) - ; string "dev-repo" (opt_default dev_repo (homepage ^ ".git")) - ; string "license" license ] - @ opt_string "version" version) - @ [ sprintf "available: [ ocaml-version >= %S ]" ocaml_min_version - ; sprintf - "build: [\n\ - \ [\"ocaml\" %S \"configure\"]\n\ - \ [\"dune\" \"build\" \"-p\" name \"-j\" jobs ]\n\ - ]" - configure_script - ; sprintf "depends: [\n%s\n]" - (List.map ~f:(sprintf " %s") deps |> String.concat ~sep:"\n") ] - - let v2 ~maintainer ?authors ?(deps = obvious_deps) ~homepage ?bug_reports - ?dev_repo ?(license = "ISC") ?version ?(ocaml_min_version = "4.03.0") - ?(configure_script = "please.mlt") ?synopsis ?description name = - let string k v = sprintf "%s: %S" k v in - let opt_default o d = match o with None -> d | Some s -> s in - let opt_f f k v = match v with None -> [] | Some s -> [f k s] in - (let opt_string k v = opt_f string k v in - [ sprintf "# This Opam file was auto-generated, see the `%s` script." - configure_script - ; string "opam-version" "2.0" - ; string "maintainer" maintainer - ; (match authors with None -> [maintainer] | Some l -> l) - |> List.map ~f:(sprintf "%S") - |> String.concat ~sep:"\n " - |> sprintf "authors: [\n %s\n]" - ; string "homepage" homepage - ; string "bug-reports" (opt_default bug_reports (homepage // "issues")) - ; string "dev-repo" (opt_default dev_repo ("git+" ^ homepage ^ ".git")) - ; string "license" license ] - @ opt_string "version" version) - @ [ sprintf - "build: [\n\ - \ [\"ocaml\" %S \"configure\"]\n\ - \ [\"dune\" \"build\" \"-p\" name \"-j\" jobs ]\n\ - ]" - configure_script - ; sprintf "depends: [\n%s\n]" - ( sprintf " \"ocaml\" { >= %S }" ocaml_min_version - :: List.map ~f:(sprintf " %s") deps - |> String.concat ~sep:"\n" ) ] - @ opt_f (sprintf "%s: %S") "synopsis" synopsis - @ opt_f (sprintf "%s: \"\"\"\n%s\n\"\"\"") "description" description -end - -module File = struct - type t = {path: string; content: string list; no_clean: bool} - - let make ?(no_clean = false) path content = {path; content; no_clean} - - let file = make - - let repo_file = make ~no_clean:true -end - -module Main = struct - let make ?(command = "ocaml " ^ Sys.argv.(0)) ~files ?(argv = Sys.argv) - ?version ?describe ?(more_commands = []) () = - let usage () = - eprintf - "usage: %s {clean,configure,version ,describe %s}\n%!" - command - ( List.map more_commands ~f:(fun (k, _) -> sprintf ",%s" k) - |> String.concat ~sep:"" ) - in - match argv.(1) with - | "clean" -> - List.iter files ~f:(function - | {File.no_clean= false; path; _} -> - Util.cmdf "rm -f %s" (Filename.quote path) - | _ -> () ) - | "configure" -> - List.iter files ~f:(fun {File.path; content} -> - Util.cmdf "mkdir -p %s" Filename.(dirname path |> quote) ; - Util.write_lines path content ) ; - () - | "describe" -> ( - match describe with - | None -> failwith "describe function not defined" - | Some f -> ( try f (Some Sys.argv.(2)) with _ -> f None ) ) - | "version" -> ( - match version with - | None -> failwith "version function not defined" - | Some f -> ( try f (Some Sys.argv.(2)) with _ -> f None ) ) - | other -> ( - match List.find more_commands ~f:(fun (k, v) -> k = other) with - | _, f -> f () - | exception _ -> - eprintf "Cannot understand command: %S\n%!" other ; - usage () ; - exit 1 ) - | exception _ -> - eprintf "Missing command\n" ; - usage () ; - exit 1 -end diff --git a/tools/travis_ci_test.sh b/tools/travis_ci_test.sh index 488305d..b08e14d 100644 --- a/tools/travis_ci_test.sh +++ b/tools/travis_ci_test.sh @@ -103,15 +103,14 @@ genspio_service_composer=_build/default/src/examples/service_composer.exe genspio_multigit=_build/default/src/examples/multigit.exe echo "================== BUILD ALL ===================================================" -ocaml please.mlt configure -jbuilder build @install - -jbuilder build $genspio_test -jbuilder build $genspio_downloader_maker -jbuilder build $genspio_small_examples -jbuilder build $genspio_vm_tester -jbuilder build $genspio_service_composer -jbuilder build $genspio_multigit +dune build @install + +dune build $genspio_test +dune build $genspio_downloader_maker +dune build $genspio_small_examples +dune build $genspio_vm_tester +dune build $genspio_service_composer +dune build $genspio_multigit echo "================== TESTS ======================================================="