From 1a8b43f449cf00996281b5c73b2a0f3400817a00 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Tue, 24 Sep 2024 14:52:27 +0200 Subject: [PATCH 1/2] refactor(pkg test): Avoid `gzip` on tarballs (#10952) This avoids gzipping the tarballs that are created to test end to end functionality. Compressing and decompressing them takes time for minimal space saving so this PR just removes it. It retains the compression in the tarballs test, to make sure compressed tarballs continue to work. Signed-off-by: Marek Kubica --- .../test-cases/pkg/depexts/error-message.t | 6 +++--- .../test-cases/pkg/different-dune-in-path.t | 6 +++--- test/blackbox-tests/test-cases/pkg/e2e.t | 6 +++--- .../test-cases/pkg/ocamlformat/helpers.sh | 14 +++++++------- ...amlformat-dev-tool-deps-conflict-project-deps.t | 6 +++--- .../test-cases/pkg/ocamlformat/ocamlformat-e2e.t | 4 ++-- .../blackbox-tests/test-cases/pkg/source-caching.t | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test/blackbox-tests/test-cases/pkg/depexts/error-message.t b/test/blackbox-tests/test-cases/pkg/depexts/error-message.t index 1fba5725782a..677c20f69d51 100644 --- a/test/blackbox-tests/test-cases/pkg/depexts/error-message.t +++ b/test/blackbox-tests/test-cases/pkg/depexts/error-message.t @@ -8,7 +8,7 @@ Make a library that would fail when building it: $ mkdir foo $ cat > foo/dune-project < EOF - $ tar -czf foo.tar.gz foo + $ tar cf foo.tar foo $ rm -rf foo Make a project that uses the foo library: @@ -33,8 +33,8 @@ Make dune.lock files > (depexts unzip gnupg) > (source > (fetch - > (url file://$PWD/foo.tar.gz) - > (checksum md5=$(md5sum foo.tar.gz | cut -f1 -d' ')))) + > (url file://$PWD/foo.tar) + > (checksum md5=$(md5sum foo.tar | cut -f1 -d' ')))) > EOF Build the project, when it fails building 'foo' package, it shows diff --git a/test/blackbox-tests/test-cases/pkg/different-dune-in-path.t b/test/blackbox-tests/test-cases/pkg/different-dune-in-path.t index d57ecc84af7c..d05fc46c40ee 100644 --- a/test/blackbox-tests/test-cases/pkg/different-dune-in-path.t +++ b/test/blackbox-tests/test-cases/pkg/different-dune-in-path.t @@ -12,7 +12,7 @@ Clarify the behavior when the `dune` in PATH is not the one used to start the bu > (allow_empty)) > EOF > cd .. - > tar -czf $1.tar.gz tmp + > tar cf $1.tar tmp > rm -rf tmp > } @@ -43,7 +43,7 @@ Make lockfiles for the packages. > > (source > (fetch - > (url $PWD/foo.tar.gz))) + > (url $PWD/foo.tar))) > > (dev) > EOF @@ -57,7 +57,7 @@ Make lockfiles for the packages. > > (source > (fetch - > (url $PWD/bar.tar.gz))) + > (url $PWD/bar.tar))) > > (dev) > EOF diff --git a/test/blackbox-tests/test-cases/pkg/e2e.t b/test/blackbox-tests/test-cases/pkg/e2e.t index 4ad6ab4c00cd..ac27e3e8179c 100644 --- a/test/blackbox-tests/test-cases/pkg/e2e.t +++ b/test/blackbox-tests/test-cases/pkg/e2e.t @@ -19,12 +19,12 @@ Make a library: > (public_name foo)) > EOF $ cd .. - $ tar -czf foo.tar.gz foo + $ tar cf foo.tar foo $ rm -rf foo Configure our fake curl to serve the tarball - $ echo foo.tar.gz >> fake-curls + $ echo foo.tar >> fake-curls $ PORT=1 Make a package for the library: @@ -46,7 +46,7 @@ Make a package for the library: > url { > src: "http://0.0.0.0:$PORT" > checksum: [ - > "md5=$(md5sum foo.tar.gz | cut -f1 -d' ')" + > "md5=$(md5sum foo.tar | cut -f1 -d' ')" > ] > } > EOF diff --git a/test/blackbox-tests/test-cases/pkg/ocamlformat/helpers.sh b/test/blackbox-tests/test-cases/pkg/ocamlformat/helpers.sh index be957f2b5721..d436055da94a 100644 --- a/test/blackbox-tests/test-cases/pkg/ocamlformat/helpers.sh +++ b/test/blackbox-tests/test-cases/pkg/ocamlformat/helpers.sh @@ -28,7 +28,7 @@ EOF (executable (public_name ocamlformat)) EOF - tar -czf ocamlformat-$version.tar.gz ocamlformat + tar cf ocamlformat-$version.tar ocamlformat rm -rf ocamlformat } @@ -55,7 +55,7 @@ build: [ url { src: "http://127.0.0.1:$port" checksum: [ - "md5=$(md5sum ocamlformat-$version.tar.gz | cut -f1 -d' ')" + "md5=$(md5sum ocamlformat-$version.tar | cut -f1 -d' ')" ] } EOF @@ -71,9 +71,9 @@ build: [ ] ] url { - src: "file://$PWD/ocamlformat-$version.tar.gz" + src: "file://$PWD/ocamlformat-$version.tar" checksum: [ - "md5=$(md5sum ocamlformat-$version.tar.gz | cut -f1 -d' ')" + "md5=$(md5sum ocamlformat-$version.tar | cut -f1 -d' ')" ] } EOF @@ -128,7 +128,7 @@ EOF (library (public_name printer)) EOF - tar -czf printer.$version.tar.gz printer + tar cf printer.$version.tar printer rm -r printer } @@ -145,9 +145,9 @@ build: [ ] ] url { - src: "file://$PWD/printer.$version.tar.gz" + src: "file://$PWD/printer.$version.tar" checksum: [ - "md5=$(md5sum printer.$version.tar.gz | cut -f1 -d' ')" + "md5=$(md5sum printer.$version.tar | cut -f1 -d' ')" ] } EOF diff --git a/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-dev-tool-deps-conflict-project-deps.t b/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-dev-tool-deps-conflict-project-deps.t index dbb5ab92dff2..645e741baf1e 100644 --- a/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-dev-tool-deps-conflict-project-deps.t +++ b/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-dev-tool-deps-conflict-project-deps.t @@ -25,7 +25,7 @@ Make a fake OCamlFormat which depends on printer lib: > (libraries printer)) > EOF $ cd .. - $ tar -czf ocamlformat.tar.gz ocamlformat + $ tar cf ocamlformat.tar ocamlformat $ rm -rf ocamlformat Make a printer lib(version 1) that prints "formatted": @@ -51,9 +51,9 @@ Make a package for the fake OCamlFormat library which depends on printer.1.0: > ] > ] > url { - > src: "file://$PWD/ocamlformat.tar.gz" + > src: "file://$PWD/ocamlformat.tar" > checksum: [ - > "md5=$(md5sum ocamlformat.tar.gz | cut -f1 -d' ')" + > "md5=$(md5sum ocamlformat.tar | cut -f1 -d' ')" > ] > } > EOF diff --git a/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-e2e.t b/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-e2e.t index c5e64a995ec9..5d75ae6e522a 100644 --- a/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-e2e.t +++ b/test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-e2e.t @@ -7,13 +7,13 @@ Exercises end to end, locking and building ocamlformat dev tool. $ make_fake_ocamlformat "0.26.3" Add the tar file for the fake curl to copy it: - $ echo ocamlformat-0.26.2.tar.gz > fake-curls + $ echo ocamlformat-0.26.2.tar > fake-curls $ PORT=1 $ make_ocamlformat_opam_pkg "0.26.2" $PORT Add the tar file for the fake curl to copy it: - $ echo ocamlformat-0.26.3.tar.gz >> fake-curls + $ echo ocamlformat-0.26.3.tar >> fake-curls $ PORT=2 We consider this version of OCamlFormat as the latest version: diff --git a/test/blackbox-tests/test-cases/pkg/source-caching.t b/test/blackbox-tests/test-cases/pkg/source-caching.t index b76119654d9b..4992e79e6bb3 100644 --- a/test/blackbox-tests/test-cases/pkg/source-caching.t +++ b/test/blackbox-tests/test-cases/pkg/source-caching.t @@ -4,10 +4,10 @@ This test demonstrates that fetching package sources should be cached $ make_lockdir - $ tarball=source.tar.gz + $ tarball=source.tar $ sources="sources/" $ mkdir $sources; touch $sources/dummy - $ tar -czf $tarball $sources + $ tar cf $tarball $sources $ checksum=$(md5sum $tarball | awk '{ print $1 }') $ echo $tarball > fake-curls $ port=1 From 17071ec30d10390badcb6cb1f6a43984b1be54a6 Mon Sep 17 00:00:00 2001 From: Teague Hansen <62850132+H-ANSEN@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:14:59 -0400 Subject: [PATCH 2/2] Fix error messages when referring to the dune config (#10923) Signed-off-by: teague hansen Signed-off-by: Marek Kubica --- doc/changes/10923.md | 3 ++ src/dune_config_file/dune_config_file.ml | 6 ++- src/dune_sexp/syntax.ml | 32 +++++++----- src/dune_sexp/syntax.mli | 20 ++++++++ .../test-cases/config-project-defaults.t | 2 +- .../config/config-in-workspace-file.t | 2 +- .../test-cases/config/config-version.t | 49 +++++++++++++++++++ 7 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 doc/changes/10923.md create mode 100644 test/blackbox-tests/test-cases/config/config-version.t diff --git a/doc/changes/10923.md b/doc/changes/10923.md new file mode 100644 index 000000000000..53c916fae11f --- /dev/null +++ b/doc/changes/10923.md @@ -0,0 +1,3 @@ +- Fix the file referred to in the error/warning message displayed due to the + dune configuration version not supporting a particular configuration + stanza in use. (#10923, @H-ANSEN) diff --git a/src/dune_config_file/dune_config_file.ml b/src/dune_config_file/dune_config_file.ml index 7d97cfdf90c3..6d4e8958b738 100644 --- a/src/dune_config_file/dune_config_file.ml +++ b/src/dune_config_file/dune_config_file.ml @@ -367,8 +367,10 @@ module Dune_config = struct let decode_generic ~min_dune_version = let check min_ver = - let ver = Dune_lang.Syntax.Version.max min_ver min_dune_version in - Dune_lang.Syntax.since Stanza.syntax ver + let module S = Dune_lang.Syntax in + let ver = S.Version.max min_ver min_dune_version in + let* loc, what = S.desc () in + S.since_fmt ~fmt:(S.Error_msg.since_config ~what) Stanza.syntax ver loc in let field_o n v d = field_o n (check v >>> d) in let+ display = field_o "display" (1, 0) (enum Display.all) diff --git a/src/dune_sexp/syntax.ml b/src/dune_sexp/syntax.ml index 3e6d43457ee2..c2108c0b2148 100644 --- a/src/dune_sexp/syntax.ml +++ b/src/dune_sexp/syntax.ml @@ -250,18 +250,22 @@ module Key = struct end module Error_msg = struct - let since t ver ~what = - let lang_or_using = if t.name = "dune" then "lang" else "using" in + let fmt_error_msg t ver ~what ~file = + let lang_or_using name = if name = "dune" then "lang" else "using" in Printf.sprintf - "%s is only available since version %s of %s. Please update your dune-project file \ - to have (%s %s %s)." + "%s is only available since version %s of %s. Please update your %s file to have \ + (%s %s %s)." what (Version.to_string ver) t.desc - lang_or_using + file + (lang_or_using t.name) t.name (Version.to_string ver) ;; + + let since t ver ~what = fmt_error_msg t ver ~what ~file:"dune-project" + let since_config t ver ~what = fmt_error_msg t ver ~what ~file:"dune config" end module Error = struct @@ -520,16 +524,20 @@ let renamed_in t ver ~to_ = Error.renamed_in loc t ver ~what ~to_ ;; -let since ?what ?(fatal = true) t ver = +let since_fmt ?(fatal = true) ~fmt t ver loc = let open Version.Infix in let* current_ver = get_exn t in if current_ver >= ver then return () - else - let* loc, what_ctx = desc () in - let what = Option.value what ~default:what_ctx in + else ( if fatal - then Error.since loc t ver ~what - else User_warning.emit ~loc [ Pp.text (Error_msg.since t ver ~what) ]; - return () + then User_error.raise ~loc [ Pp.text (fmt t ver) ] + else User_warning.emit ~loc [ Pp.text (fmt t ver) ]; + return ()) +;; + +let since ?what ?(fatal = true) t ver = + let* loc, what_ctx = desc () in + let what = Option.value what ~default:what_ctx in + since_fmt ~fatal ~fmt:(Error_msg.since ~what) t ver loc ;; diff --git a/src/dune_sexp/syntax.mli b/src/dune_sexp/syntax.mli index f4fd657aa507..0352e34108be 100644 --- a/src/dune_sexp/syntax.mli +++ b/src/dune_sexp/syntax.mli @@ -29,7 +29,14 @@ end type t module Error_msg : sig + (** [since t ver what] formats an error string indicating that the syntax + [t] described by [what] is only available since [ver] of the dune-project + file. *) val since : t -> Version.t -> what:string -> string + + (** Like [since] but formats an error message relating to the dune config file + rather than the dune-project file. *) + val since_config : t -> Version.t -> what:string -> string end module Error : sig @@ -71,6 +78,9 @@ val create (** Return the name of the syntax. *) val name : t -> string +(** Indicate the location and kind of value being parsed *) +val desc : unit -> (Loc.t * string, 'a) Decoder.parser + (** Check that the given version is supported and raise otherwise. *) val check_supported : dune_lang_ver:Version.t -> t -> Loc.t * Version.t -> unit @@ -98,6 +108,16 @@ val renamed_in : t -> Version.t -> to_:string -> (unit, _) Decoder.parser [fatal] defaults to true. [what] allows customizing the error message. *) val since : ?what:string -> ?fatal:bool -> t -> Version.t -> (unit, _) Decoder.parser +(** Like [since] but accepts a function [fmt] allowing custom formatting of the + entire error/warning message. See [Error_msg] for format functions. *) +val since_fmt + : ?fatal:bool + -> fmt:(t -> Version.t -> string) + -> t + -> Version.t + -> Loc.t + -> (unit, 'a) Decoder.parser + (** {2 Low-level functions} *) module Key : sig diff --git a/test/blackbox-tests/test-cases/config-project-defaults.t b/test/blackbox-tests/test-cases/config-project-defaults.t index 4bfd71e62d38..7186ee51147b 100644 --- a/test/blackbox-tests/test-cases/config-project-defaults.t +++ b/test/blackbox-tests/test-cases/config-project-defaults.t @@ -39,7 +39,7 @@ Change the version of the config file to one which does not support the 4 | (maintainers MaintainerTest) 5 | (license MIT)) Error: 'project_defaults' is only available since version 3.17 of the dune - language. Please update your dune-project file to have (lang dune 3.17). + language. Please update your dune config file to have (lang dune 3.17). [1] $ sed -i -e '1s|.*|(lang dune 3.17)|' dune-config diff --git a/test/blackbox-tests/test-cases/config/config-in-workspace-file.t b/test/blackbox-tests/test-cases/config/config-in-workspace-file.t index 5dddf2a7324f..2d4c97593c02 100644 --- a/test/blackbox-tests/test-cases/config/config-in-workspace-file.t +++ b/test/blackbox-tests/test-cases/config/config-in-workspace-file.t @@ -19,7 +19,7 @@ Setting such options is not supported with older Dune: 2 | (display short) ^^^^^^^^^^^^^^^ Error: 'display' is only available since version 3.0 of the dune language. - Please update your dune-project file to have (lang dune 3.0). + Please update your dune config file to have (lang dune 3.0). [1] But is supported with Dune >= 3.0.0: diff --git a/test/blackbox-tests/test-cases/config/config-version.t b/test/blackbox-tests/test-cases/config/config-version.t new file mode 100644 index 000000000000..2c935354de09 --- /dev/null +++ b/test/blackbox-tests/test-cases/config/config-version.t @@ -0,0 +1,49 @@ +Tests verifying that the config file presents accurate error or warning +messages when a stanza is used with a version of dune which does not support +such a stanza. + +Create a config file to use in the following tests. We will initialize the +config with a version and a stanza incompatable with that version. + + $ export DUNE_CACHE_ROOT=$PWD/dune-cache + $ touch dune-config + $ cat >dune-config < (lang dune 1.0) + > (cache enabled) + > EOF + +Attempt to initialize a new project while an invaild stanza due to versioning +exists in the config. + + $ dune init proj test --config-file=dune-config + File "$TESTCASE_ROOT/dune-config", line 2, characters 0-15: + 2 | (cache enabled) + ^^^^^^^^^^^^^^^ + Error: 'cache' is only available since version 2.0 of the dune language. + Please update your dune config file to have (lang dune 2.0). + [1] + +Update the dune configuration with a version that would support the +'(cache enabled)' stanza and attempt a successful project initialization. + + $ cat >dune-config < (lang dune 2.0) + > (cache enabled) + > EOF + + $ dune init proj test_vaild --config-file=dune-config + Entering directory 'test_vaild' + Success: initialized project component named test_vaild + Leaving directory 'test_vaild' + +Append an invaild stanza to the config file and attempt project initialzation. + + $ echo "(cache-check-probability 0.5)" >> dune-config + $ dune init proj test --config-file=dune-config + File "$TESTCASE_ROOT/dune-config", line 3, characters 0-29: + 3 | (cache-check-probability 0.5) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + Error: 'cache-check-probability' is only available since version 2.7 of the + dune language. Please update your dune config file to have (lang dune 2.7). + [1] +