diff --git a/src/autofonce_core/parser.ml b/src/autofonce_core/parser.ml index 4b00379..491b10c 100644 --- a/src/autofonce_core/parser.ml +++ b/src/autofonce_core/parser.ml @@ -293,11 +293,17 @@ let load_file ~dirs ~keep_files ~path c filename = let content = M4Parser.to_string content in AT_DATA { file ; content } - | Macro ( ( "AF_DATA_FILE" ) , [ file ; content_file]) -> + | Macro ( ( "AF_DATA_COPY" ) , [ file ; content_file]) -> let file = M4Parser.to_string file in let content_file = M4Parser.to_string content_file in let dir = Filename.dirname macro.loc.file in - AF_DATA_FILE { file ; dir ; content_file } + AF_DATA_COPY { file ; dir ; content_file } + + | Macro ( ( "AF_DATA_LINK" ) , [ file ; content_file]) -> + let file = M4Parser.to_string file in + let content_file = M4Parser.to_string content_file in + let dir = Filename.dirname macro.loc.file in + AF_DATA_LINK { file ; dir ; content_file } | Macro ( ( "AF_CAPTURE_FILE" | "AT_CAPTURE_FILE" ) , [ file ] ) -> let file = M4Parser.to_string file in diff --git a/src/autofonce_core/types.ml b/src/autofonce_core/types.ml index 70b2518..5cbaaed 100644 --- a/src/autofonce_core/types.ml +++ b/src/autofonce_core/types.ml @@ -38,7 +38,6 @@ type check = { (* variable name is `check` *) and action = | AT_DATA of { file:string ; content: string } - | AF_DATA_FILE of { file:string ; dir : string ; content_file: string } | AT_CAPTURE_FILE of string | AT_XFAIL | AT_XFAIL_IF of { step : step ; loc : location ; command : string } @@ -58,6 +57,8 @@ and action = promote : bool ; (* explicit or implicit ? *) } | AF_COMMENT of string + | AF_DATA_LINK of { file:string ; dir : string ; content_file: string } + | AF_DATA_COPY of { file:string ; dir : string ; content_file: string } and test = { (* variable name is `t` *) test_suite : suite ; @@ -91,9 +92,6 @@ let string_of_location = Autofonce_m4.M4Printer.string_of_location let rec string_of_action = function | AT_DATA { file ; content } -> Printf.sprintf "AT_DATA ( file=%S, content=%s )" file content - | AF_DATA_FILE { file ; dir ; content_file } -> - Printf.sprintf "AF_DATA_FILE ( file=%S, dir=%s, content_file=%s )" - file dir content_file | AT_CAPTURE_FILE string -> Printf.sprintf "AT_CAPTURE_FILE %s" string | AT_XFAIL -> "AT_XFAIL_IF([true])" @@ -118,6 +116,12 @@ let rec string_of_action = function Printf.sprintf "AF_ENV %S" env | AF_COMMENT comment -> Printf.sprintf "AF_COMMENT %S" comment + | AF_DATA_COPY { file ; dir ; content_file } -> + Printf.sprintf "AF_DATA_COPY ( file=%S, dir=%s, content_file=%s )" + file dir content_file + | AF_DATA_LINK { file ; dir ; content_file } -> + Printf.sprintf "AF_DATA_LINK ( file=%S, dir=%s, content_file=%s )" + file dir content_file and string_of_check_output = function | Ignore -> "IGNORE" diff --git a/src/autofonce_lib/logging.ml b/src/autofonce_lib/logging.ml index 3764685..4aef49b 100644 --- a/src/autofonce_lib/logging.ml +++ b/src/autofonce_lib/logging.ml @@ -123,7 +123,8 @@ let log_checks ?failed_check state ter = | AF_COMMENT _ | AF_COPY _ | AT_DATA _ - | AF_DATA_FILE _ + | AF_DATA_COPY _ + | AF_DATA_LINK _ | AF_ENV _ | AT_CAPTURE_FILE _ | AT_XFAIL diff --git a/src/autofonce_lib/promote.ml b/src/autofonce_lib/promote.ml index 9b739fe..d2870a7 100644 --- a/src/autofonce_lib/promote.ml +++ b/src/autofonce_lib/promote.ml @@ -214,8 +214,12 @@ let print_actions t ~ignore_exitcode ~keep_old b actions = Printf.bprintf b "AT_DATA(%s, %s)\n" ( PARSER.m4_escape file ) ( PARSER.m4_escape content ) - | AF_DATA_FILE { file ; dir=_; content_file } -> - Printf.bprintf b "AF_DATA_FILE(%s, %s)\n" + | AF_DATA_COPY { file ; dir=_; content_file } -> + Printf.bprintf b "AF_DATA_COPY(%s, %s)\n" + ( PARSER.m4_escape file ) + ( PARSER.m4_escape content_file ) + | AF_DATA_LINK { file ; dir=_; content_file } -> + Printf.bprintf b "AF_DATA_LINK(%s, %s)\n" ( PARSER.m4_escape file ) ( PARSER.m4_escape content_file ) | AF_ENV string -> diff --git a/src/autofonce_lib/runner_common.ml b/src/autofonce_lib/runner_common.ml index e206c1b..836c3c9 100644 --- a/src/autofonce_lib/runner_common.ml +++ b/src/autofonce_lib/runner_common.ml @@ -183,7 +183,12 @@ let exec_action_no_check ter action = match action with | AT_DATA { file ; content } -> EzFile.write_text_file ( tester_dir ter // file ) content - | AF_DATA_FILE { file ; dir ; content_file } -> + | AF_DATA_COPY { file ; dir ; content_file } -> + let dst_file = tester_dir ter // file in + if Sys.file_exists dst_file then Unix.unlink dst_file; + let content = EzFile.read_file ( dir // content_file ) in + EzFile.write_file dst_file content + | AF_DATA_LINK { file ; dir ; content_file } -> let dst_file = tester_dir ter // file in if Sys.file_exists dst_file then Unix.unlink dst_file; Unix.link ( dir // content_file ) dst_file diff --git a/src/autofonce_lib/runner_par.ml b/src/autofonce_lib/runner_par.ml index 18cc089..d6e4240 100644 --- a/src/autofonce_lib/runner_par.ml +++ b/src/autofonce_lib/runner_par.ml @@ -103,7 +103,8 @@ and schedule_action r action = | AF_COMMENT _ | AT_XFAIL | AT_DATA _ - | AF_DATA_FILE _ + | AF_DATA_COPY _ + | AF_DATA_LINK _ | AT_CAPTURE_FILE _ | AT_CLEANUP _ | AF_ENV _ diff --git a/src/autofonce_lib/runner_seq.ml b/src/autofonce_lib/runner_seq.ml index 72a28ed..aa321ba 100644 --- a/src/autofonce_lib/runner_seq.ml +++ b/src/autofonce_lib/runner_seq.ml @@ -44,7 +44,8 @@ let rec exec_action_or_check ter action = | AF_COMMENT _ | AT_XFAIL | AT_DATA _ - | AF_DATA_FILE _ + | AF_DATA_COPY _ + | AF_DATA_LINK _ | AT_CAPTURE_FILE _ | AT_CLEANUP _ | AF_ENV _ diff --git a/src/autofonce_m4/m4Lexer.mll b/src/autofonce_m4/m4Lexer.mll index 20c29eb..b401a14 100644 --- a/src/autofonce_m4/m4Lexer.mll +++ b/src/autofonce_m4/m4Lexer.mll @@ -221,6 +221,14 @@ and unescape = parse | "@:>@" { quadrigraph lexbuf "]"; unescape lexbuf } | "@S|@" { quadrigraph lexbuf "$"; unescape lexbuf } | "@%:@" { quadrigraph lexbuf "#"; unescape lexbuf } + | "@&t@" ['0'-'9' ]+ "@&t@" { + let s = Lexing.lexeme lexbuf in + let len = String.length s in + let code = String.sub s 4 (len-8) in + let code = int_of_string code in + let c = char_of_int code in + let s = String.make 1 c in + quadrigraph lexbuf s; unescape lexbuf } | "@&t@" { quadrigraph lexbuf ""; unescape lexbuf } | "@{:@" { quadrigraph lexbuf "("; unescape lexbuf } | "@:}@" { quadrigraph lexbuf ")"; unescape lexbuf }