Get rid of indexed lookups for deps

Have %{first-dep} to replace %{<}

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-06 18:25:00 +07:00
parent 2c29217a20
commit c4545fce18
19 changed files with 54 additions and 69 deletions

View File

@ -169,7 +169,7 @@ Jbuild Dune
======================== ============ ======================== ============
``${@}`` ``%{targets}`` ``${@}`` ``%{targets}``
``${^}`` ``%{deps}`` ``${^}`` ``%{deps}``
``${<}`` ``%{deps[0]}`` ``${<}`` ``%{first-dep}``
``${path:file}`` ``%{dep:file}`` ``${path:file}`` ``%{dep:file}``
``${SCOPE_ROOT}`` ``%{project_root}`` ``${SCOPE_ROOT}`` ``%{project_root}``
``${findlib:..}`` ``%{lib:..}`` ``${findlib:..}`` ``%{lib:..}``

View File

@ -136,7 +136,7 @@ Add this field to your ``library`` or ``executable`` stanzas:
.. code:: scheme .. code:: scheme
(preprocess (action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{deps[0]}))) (preprocess (action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{first-dep})))
Additionally, if you are include a ``config.h`` file, you need to Additionally, if you are include a ``config.h`` file, you need to
declare the dependency to this file via: declare the dependency to this file via:
@ -155,7 +155,7 @@ Write this in your ``dune`` file:
(rule (rule
(targets foo.ml) (targets foo.ml)
(deps foo.cppo.ml <other files that foo.ml includes>) (deps foo.cppo.ml <other files that foo.ml includes>)
(action (run %{bin:cppo} %{deps[0]} -o %{targets}))) (action (run %{bin:cppo} %{first-dep} -o %{targets})))
Defining a library with C stubs Defining a library with C stubs
=============================== ===============================
@ -193,7 +193,7 @@ compilation and link flags. Write this ``dune`` file:
(rule (rule
(targets c_flags.sexp c_library_flags.sexp) (targets c_flags.sexp c_library_flags.sexp)
(deps config/discover.exe) (deps config/discover.exe)
(action (run %{deps[0]} -ocamlc %{OCAMLC}))) (action (run %{first-dep} -ocamlc %{OCAMLC})))
Then create a ``config`` subdirectory and write this ``dune`` file: Then create a ``config`` subdirectory and write this ``dune`` file:
@ -241,7 +241,7 @@ To generate a file ``foo.ml`` using a program from another directory:
(rule (rule
(targets foo.ml) (targets foo.ml)
(deps ../generator/gen.exe) (deps ../generator/gen.exe)
(action (run %{deps[0]} -o %{targets}))) (action (run %{first-dep} -o %{targets})))
Defining tests Defining tests
============== ==============
@ -253,7 +253,7 @@ Write this in your ``dune`` file:
(alias (alias
(name runtest) (name runtest)
(deps my-test-program.exe) (deps my-test-program.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))
And run the tests with: And run the tests with:

View File

@ -2,7 +2,7 @@
((fallback) ((fallback)
(targets (config)) (targets (config))
(deps (config.defaults)) (deps (config.defaults))
(action (copy %{deps[0]} %{targets})))) (action (copy %{first-dep} %{targets}))))
(rule (rule
((targets (config.full)) ((targets (config.full))

View File

@ -8,5 +8,5 @@
(rule (rule
((targets (config.ml)) ((targets (config.ml))
(deps (../config.full)) (deps (../config.full))
(action (copy %{deps[0]} %{targets})))) (action (copy %{first-dep} %{targets}))))

View File

@ -11,7 +11,7 @@
which_program) which_program)
(synopsis "Internal Dune library, do not use!")) (synopsis "Internal Dune library, do not use!"))
(ocamllex meta_lexer glob_lexer dune_lexer dune_vars) (ocamllex meta_lexer glob_lexer dune_lexer)
(rule (rule
(targets setup.ml) (targets setup.ml)

View File

@ -1 +0,0 @@
val deps : string -> int option

View File

@ -1,13 +0,0 @@
{
open Stdune
}
let digit = ['0'-'9']
rule deps = parse
| "deps[" (digit+ as i) "]" eof { Some (Int.of_string_exn i) }
| _ { None }
{
let deps s = deps (Lexing.from_string s)
}

View File

@ -1243,7 +1243,7 @@ module Rule = struct
[ S.virt_text __POS__ "-q" [ S.virt_text __POS__ "-q"
; S.virt_text __POS__ "-o" ; S.virt_text __POS__ "-o"
; S.virt_var __POS__ "targets" ; S.virt_var __POS__ "targets"
; S.virt_var __POS__"deps[0]" ; S.virt_var __POS__"first-dep"
]))) ])))
; mode ; mode
; locks = [] ; locks = []
@ -1261,7 +1261,7 @@ module Rule = struct
Chdir Chdir
(S.virt_var __POS__ "ROOT", (S.virt_var __POS__ "ROOT",
Run (S.virt_text __POS__ "ocamlyacc", Run (S.virt_text __POS__ "ocamlyacc",
[S.virt_var __POS__ "deps[0]"]))) [S.virt_var __POS__ "first-dep"])))
; mode ; mode
; locks = [] ; locks = []
; loc ; loc

View File

@ -807,20 +807,23 @@ module Action = struct
match String.Map.find dynamic_expansions key with match String.Map.find dynamic_expansions key with
| Some _ as opt -> opt | Some _ as opt -> opt
| None -> | None ->
let dep i = let first_dep () =
match List.nth deps_written_by_user i with Some (
| None -> match deps_written_by_user with
Loc.warn loc "Variable '%s' used with no explicit \ | [] ->
dependencies@." key; Loc.warn loc "Variable '%s' used with no explicit \
[Value.String ""] dependencies@." key;
| Some v -> [Path v] [Value.String ""]
| v :: _ -> [Path v]
)
in in
match key with match key with
| "<" -> | "<" ->
if syntax_version < (1, 0) then if syntax_version < (1, 0) then
Some (dep 0) first_dep ()
else else
Loc.fail loc "Variable '<' is renamed to 'deps[0]' in dune" Loc.fail loc "Variable '<' is renamed to 'first-dep' in dune"
| "first-dep" when syntax_version >= (1, 0) -> first_dep ()
| "^" -> | "^" ->
if syntax_version < (1, 0) then if syntax_version < (1, 0) then
Some (Value.L.paths deps_written_by_user) Some (Value.L.paths deps_written_by_user)
@ -828,11 +831,7 @@ module Action = struct
Loc.fail loc "Variable %%{^} has been renamed to %%{deps}" Loc.fail loc "Variable %%{^} has been renamed to %%{deps}"
| "deps" when syntax_version >= (1, 0) -> | "deps" when syntax_version >= (1, 0) ->
Some (Value.L.paths deps_written_by_user) Some (Value.L.paths deps_written_by_user)
| _ -> | _ -> None)
if syntax_version < (1, 0) then
None
else
Option.map (Dune_vars.deps key) ~f:dep)
let run sctx ~loc ?(extra_vars=String.Map.empty) let run sctx ~loc ?(extra_vars=String.Map.empty)
t ~dir ~dep_kind ~targets:targets_written_by_user ~scope t ~dir ~dep_kind ~targets:targets_written_by_user ~scope

View File

@ -4,4 +4,4 @@
(alias (alias
(name runtest) (name runtest)
(deps f.exe) (deps f.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))

View File

@ -8,7 +8,7 @@
(name runtest) (name runtest)
(package lib1) (package lib1)
(deps test1.exe) (deps test1.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))
(executable (executable
(name test1) (name test1)
@ -25,7 +25,7 @@
(name runtest) (name runtest)
(package lib2) (package lib2)
(deps test2.exe) (deps test2.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))
(executable (executable
(name test2) (name test2)

View File

@ -1,6 +1,6 @@
(alias (alias
(name runtest) (name runtest)
(deps main.exe) (deps main.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))
(executable (name main)) (executable (name main))

View File

@ -1,6 +1,6 @@
(alias (alias
(name runtest) (name runtest)
(deps main.exe) (deps main.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))
(executable (name main)) (executable (name main))

View File

@ -33,7 +33,7 @@
(rule (rule
(targets dynamic.exe) (targets dynamic.exe)
(deps dynamic.c) (deps dynamic.c)
(action (run %{CC} -o %{targets} %{deps[0]} %{ocaml-config:native_c_libraries}))) (action (run %{CC} -o %{targets} %{first-dep} %{ocaml-config:native_c_libraries})))
(alias (alias
(name runtest) (name runtest)
@ -48,9 +48,9 @@
(alias (alias
(name runtest) (name runtest)
(deps test.bc%{ext_dll}) (deps test.bc%{ext_dll})
(action (run ./dynamic.exe ./%{deps[0]}))) (action (run ./dynamic.exe ./%{first-dep})))
(alias (alias
(name runtest) (name runtest)
(deps test%{ext_dll}) (deps test%{ext_dll})
(action (run ./dynamic.exe ./%{deps[0]}))) (action (run ./dynamic.exe ./%{first-dep})))

View File

@ -8,18 +8,18 @@
(lint (lint
(per_module (per_module
((pps (reasonppx (-lint true))) (hello cppome)) ((pps (reasonppx (-lint true))) (hello cppome))
((action (run ./pp/reasononlypp.exe -lint %{deps[0]})) (foo bar pped)))) ((action (run ./pp/reasononlypp.exe -lint %{first-dep})) (foo bar pped))))
(preprocess (preprocess
(per_module (per_module
((pps (reasonppx)) (foo)) ((pps (reasonppx)) (foo))
((pps (reasonppx (-lint false))) (hello)) ((pps (reasonppx (-lint false))) (hello))
((action (run ./pp/reasononlypp.exe %{deps[0]})) (cppome)))))) ((action (run ./pp/reasononlypp.exe %{first-dep})) (cppome))))))
(executable (executable
((name rbin) ((name rbin)
(modules rbin) (modules rbin)
(lint (action (run ./pp/reasononlypp.exe -lint %{deps[0]}))) (lint (action (run ./pp/reasononlypp.exe -lint %{first-dep})))
(preprocess (action (run ./pp/reasononlypp.exe %{deps[0]}))) (preprocess (action (run ./pp/reasononlypp.exe %{first-dep})))
(libraries (rlib)))) (libraries (rlib))))
;; we want to make sure that .rei files are present ;; we want to make sure that .rei files are present
@ -31,4 +31,4 @@
(alias (alias
((name runtest) ((name runtest)
(deps (rbin.exe)) (deps (rbin.exe))
(action (run %{deps[0]})))) (action (run %{first-dep}))))

View File

@ -11,4 +11,4 @@
(alias (alias
(name runtest) (name runtest)
(deps main.exe) (deps main.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))

View File

@ -5,4 +5,4 @@
(alias (alias
(name runtest) (name runtest)
(deps ./test_configurator.exe) (deps ./test_configurator.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))

View File

@ -25,8 +25,8 @@
(source_tree findlib-db)) (source_tree findlib-db))
(action (chdir %{project_root} (action (chdir %{project_root}
(progn (progn
(run %{exe:expect_test.exe} %{deps[0]}) (run %{exe:expect_test.exe} %{first-dep})
(diff? %{deps[0]} %{deps[0]}.corrected))))) (diff? %{first-dep} %{first-dep}.corrected)))))
(alias (alias
(name runtest) (name runtest)
@ -35,8 +35,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi)) (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root} (action (chdir %{project_root}
(progn (progn
(run %{exe:expect_test.exe} %{deps[0]}) (run %{exe:expect_test.exe} %{first-dep})
(diff? %{deps[0]} %{deps[0]}.corrected))))) (diff? %{first-dep} %{first-dep}.corrected)))))
(alias (alias
(name runtest) (name runtest)
@ -45,8 +45,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi)) (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root} (action (chdir %{project_root}
(progn (progn
(run %{exe:expect_test.exe} %{deps[0]}) (run %{exe:expect_test.exe} %{first-dep})
(diff? %{deps[0]} %{deps[0]}.corrected))))) (diff? %{first-dep} %{first-dep}.corrected)))))
(alias (alias
(name runtest) (name runtest)
@ -55,8 +55,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi)) (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root} (action (chdir %{project_root}
(progn (progn
(run %{exe:expect_test.exe} %{deps[0]}) (run %{exe:expect_test.exe} %{first-dep})
(diff? %{deps[0]} %{deps[0]}.corrected))))) (diff? %{first-dep} %{first-dep}.corrected)))))
(alias (alias
(name runtest) (name runtest)
@ -65,8 +65,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi)) (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root} (action (chdir %{project_root}
(progn (progn
(run %{exe:expect_test.exe} %{deps[0]}) (run %{exe:expect_test.exe} %{first-dep})
(diff? %{deps[0]} %{deps[0]}.corrected))))) (diff? %{first-dep} %{first-dep}.corrected)))))
(alias (alias
(name runtest) (name runtest)
@ -75,8 +75,8 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi)) (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root} (action (chdir %{project_root}
(progn (progn
(run %{exe:expect_test.exe} %{deps[0]}) (run %{exe:expect_test.exe} %{first-dep})
(diff? %{deps[0]} %{deps[0]}.corrected))))) (diff? %{first-dep} %{first-dep}.corrected)))))
(alias (alias
(name runtest) (name runtest)
@ -85,5 +85,5 @@
(glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi)) (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi))
(action (chdir %{project_root} (action (chdir %{project_root}
(progn (progn
(run %{exe:expect_test.exe} %{deps[0]}) (run %{exe:expect_test.exe} %{first-dep})
(diff? %{deps[0]} %{deps[0]}.corrected))))) (diff? %{first-dep} %{first-dep}.corrected)))))

View File

@ -5,4 +5,4 @@
(alias (alias
(name runtest) (name runtest)
(deps ./gh637.exe) (deps ./gh637.exe)
(action (run %{deps[0]}))) (action (run %{first-dep})))