From 0ec0b078985a53309a8e976e3158540229115334 Mon Sep 17 00:00:00 2001 From: Patrick Baudin <patrick.baudin@cea.fr> Date: Thu, 2 Dec 2021 14:59:26 +0100 Subject: [PATCH] [ptests] %{bin:tool} is replaced by ./bin/tool --- ptests/ptests.ml | 130 ++++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 64 deletions(-) diff --git a/ptests/ptests.ml b/ptests/ptests.ml index 32ef1974563..23858ad857b 100644 --- a/ptests/ptests.ml +++ b/ptests/ptests.ml @@ -1359,71 +1359,73 @@ end = struct let expand_macros = let dune_cmd_features = Str.regexp "%{[a-z][a-z-]*:\\([^}]*\\)}" in + let dune_bin_features = Str.regexp "%{bin:\\([^}]*\\)}" in fun ~defaults cmd -> - let ptest_config = - if !special_config = "" then "" else "_" ^ !special_config - in - let ptest_file = get_ptest_file cmd in - let ptest_name = - try Filename.chop_extension cmd.file - with Invalid_argument _ -> cmd.file - in - let ptest_file = Filename.sanitize ptest_file in - let ptest_load_plugin = Macros.get "PTEST_LOAD_PLUGIN" cmd.macros in - let ptest_load_module = Macros.get "PTEST_LOAD_MODULE" cmd.macros in - let ptest_load_libs = Macros.get "PTEST_LOAD_LIBS" cmd.macros in - let ptest_load_script = Macros.get "PTEST_LOAD_SCRIPT" cmd.macros in - let macros = - [ "PTEST_CONFIG", ptest_config; - "PTEST_DIR", SubDir.get cmd.directory; - "PTEST_RESULT", - SubDir.get cmd.directory ^ "/" ^ redefine_name "result"; - "PTEST_FILE", ptest_file; - "PTEST_NAME", ptest_name; - "PTEST_NUMBER", string_of_int cmd.n; - "PTEST_OPT", cmd.options; - "PTEST_LOAD_OPTIONS", (String.concat " " - [ ptest_load_plugin ; - ptest_load_libs ; - ptest_load_module ; - ptest_load_script ; ]) - ] - in - let macros = Macros.add_list macros cmd.macros in - let macros = Macros.add_defaults ~defaults macros in - let process_macros s = Macros.expand macros s in - let toplevel = - let in_toplevel,toplevel= Macros.does_expand macros cmd.toplevel in - if not cmd.execnow then begin - let has_ptest_file, options = - if in_toplevel.has_ptest_opt then in_toplevel.has_ptest_file, [] - else - let in_option,options= Macros.does_expand macros cmd.options in - (in_option.has_ptest_file || in_toplevel.has_ptest_file), - (if in_toplevel.has_frama_c_exe then - [ process_macros "@PTEST_PRE_OPTIONS@" ; - options ; - process_macros "@PTEST_POST_OPTIONS@" ; - ] - else [ options ]) - in - String.concat " " (toplevel::(if has_ptest_file then options else ptest_file::options)) - end - else toplevel - in - let toplevel = (* removes dune feature such as %{deps:...} *) - str_global_replace dune_cmd_features "\\1" toplevel - in - { cmd with - macros; - toplevel; - options = ""; (* no more usable *) - log_files = List.map process_macros cmd.log_files; - filter = - match cmd.filter with - | None -> None - | Some filter -> Some (process_macros filter) - } + let ptest_config = + if !special_config = "" then "" else "_" ^ !special_config + in + let ptest_file = get_ptest_file cmd in + let ptest_name = + try Filename.chop_extension cmd.file + with Invalid_argument _ -> cmd.file + in + let ptest_file = Filename.sanitize ptest_file in + let ptest_load_plugin = Macros.get "PTEST_LOAD_PLUGIN" cmd.macros in + let ptest_load_module = Macros.get "PTEST_LOAD_MODULE" cmd.macros in + let ptest_load_libs = Macros.get "PTEST_LOAD_LIBS" cmd.macros in + let ptest_load_script = Macros.get "PTEST_LOAD_SCRIPT" cmd.macros in + let macros = + [ "PTEST_CONFIG", ptest_config; + "PTEST_DIR", SubDir.get cmd.directory; + "PTEST_RESULT", + SubDir.get cmd.directory ^ "/" ^ redefine_name "result"; + "PTEST_FILE", ptest_file; + "PTEST_NAME", ptest_name; + "PTEST_NUMBER", string_of_int cmd.n; + "PTEST_OPT", cmd.options; + "PTEST_LOAD_OPTIONS", (String.concat " " + [ ptest_load_plugin ; + ptest_load_libs ; + ptest_load_module ; + ptest_load_script ; ]) + ] + in + let macros = Macros.add_list macros cmd.macros in + let macros = Macros.add_defaults ~defaults macros in + let process_macros s = Macros.expand macros s in + let toplevel = + let in_toplevel,toplevel= Macros.does_expand macros cmd.toplevel in + if not cmd.execnow then begin + let has_ptest_file, options = + if in_toplevel.has_ptest_opt then in_toplevel.has_ptest_file, [] + else + let in_option,options= Macros.does_expand macros cmd.options in + (in_option.has_ptest_file || in_toplevel.has_ptest_file), + (if in_toplevel.has_frama_c_exe then + [ process_macros "@PTEST_PRE_OPTIONS@" ; + options ; + process_macros "@PTEST_POST_OPTIONS@" ; + ] + else [ options ]) + in + String.concat " " (toplevel::(if has_ptest_file then options else ptest_file::options)) + end + else toplevel + in + let toplevel = (* removes dune feature such as %{deps:...} *) + let x = str_global_replace dune_bin_features "./bin/\\1" toplevel in + str_global_replace dune_cmd_features "\\1" x + in + { cmd with + macros; + toplevel; + options = ""; (* no more usable *) + log_files = List.map process_macros cmd.log_files; + filter = + match cmd.filter with + | None -> None + | Some filter -> Some (process_macros filter) + } let basic_command_string = fun command -> -- GitLab