use dune_site module to find inputs

this packages the inputs as part of the build and exposes the directory
to find them via a generated module. this way, inputs are a resource of
the library rather than an input.

this means that `dune exec aoc` and `dune utop` will always find the
file regardless of where they are invoked, which makes developing in
emacs simpler :)
This commit is contained in:
ryan committed 2023-09-21 21:40:21 -07:00
1 parent e1402bc17d
commit 89eb0c7a27
6 files changed
+24 -11

No files matched your search

+2
View File
@@ -23,9 +23,11 @@ build: [
name name
"-j" "-j"
jobs jobs
"--promote-install-files=false"
"@install" "@install"
"@runtest" {with-test} "@runtest" {with-test}
"@doc" {with-doc} "@doc" {with-doc}
] ]
["dune" "install" "-p" name "--create-install-files" name]
] ]
dev-repo: "git+https://github.com/username/reponame.git" dev-repo: "git+https://github.com/username/reponame.git"
+3
View File
@@ -15,11 +15,14 @@
(documentation https://url/to/documentation) (documentation https://url/to/documentation)
(using dune_site 0.1)
(package (package
(name aoc) (name aoc)
(synopsis "A short synopsis") (synopsis "A short synopsis")
(description "A longer description") (description "A longer description")
(depends ocaml dune) (depends ocaml dune)
(sites (lib inputs))
(tags (tags
(topics "to describe" your project))) (topics "to describe" your project)))
+1 -1
View File
@@ -24,7 +24,7 @@ let part2 lines =
;; ;;
let print () = let print () =
let lines = Utils.lines_of_file "inputs/day1.tt" in let lines = Utils.lines_of_input 1 in
Printf.( Printf.(
printf "Day 1.1: %d\n" @@ part1 lines; printf "Day 1.1: %d\n" @@ part1 lines;
printf "Day 1.2: %d\n" @@ part2 lines) printf "Day 1.2: %d\n" @@ part2 lines)
+1 -1
View File
@@ -87,7 +87,7 @@ let part2 lines =
;; ;;
let print () = let print () =
let lines = Utils.lines_of_file "./inputs/day2.tt" in let lines = Utils.lines_of_input 2 in
Printf.( Printf.(
printf "Day 2.1: %d\n" @@ part1 lines; printf "Day 2.1: %d\n" @@ part1 lines;
printf "Day 2.2: %d\n" @@ part2 lines) printf "Day 2.2: %d\n" @@ part2 lines)
+9 -1
View File
@@ -1,4 +1,12 @@
(library (library
(name aoc) (name aoc)
(libraries stdio re) (libraries stdio re dune-site)
(preprocess (pps ppx_regexp))) (preprocess (pps ppx_regexp)))
(install
(section (site (aoc inputs)))
(files (glob_files ../inputs/*)))
(generate_sites_module
(module inputs)
(sites aoc))
+8 -8
View File
@@ -1,9 +1,9 @@
let lines_of_file filename = Stdio.In_channel.(with_file filename ~f:input_lines) let lines_of_input day =
let base_path =
let rec print_int_list = function match Inputs.Sites.inputs with
| [] -> () | path :: _ -> path
| e :: l -> | _ -> failwith "cant find sites path"
print_int e; in
print_string " "; let path = Printf.sprintf "%s/day%d.tt" base_path day in
print_int_list l Stdio.In_channel.(with_file path ~f:input_lines)
;; ;;