Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/subst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ let subst_file path ~map opam_package_files =
try
subst_string ("version: \"%%" ^ "VERSION_NUM" ^ "%%\"") ~map (Path.source path)
with
| User_error.E e ->
raise (User_error.E { e with loc = Some (Loc.in_file (Path.source path)) }))
| User_error.E _ -> None)
else None
in
let path = Path.source path in
Expand Down Expand Up @@ -264,6 +263,11 @@ end

let make_watermark_map ~commit ~version ~dune_project ~info =
let dune_project = Dune_project.project dune_project in
let version =
match version with
| Some _ -> version
| None -> Option.map ~f:Package_version.to_string (Dune_project.version dune_project)
in
let version_num =
let open Option.O in
let+ version = version in
Expand Down
5 changes: 5 additions & 0 deletions doc/changes/11801.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- fix: `$ dune subst` should not fail when adding the version field in opam
files (#11801, fixes #11045, @btjorge)

- feature: `$ dune subst` use version from `dune-project` when no version control repository
has been detected
1 change: 1 addition & 0 deletions src/source/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ let equal : t -> t -> bool = phys_equal
let hash = Poly.hash
let packages t = t.packages
let name t = t.name
let version t = t.version
let root t = t.root
let stanza_parser t = Dune_lang.Decoder.set key t t.stanza_parser
let file t = t.project_file
Expand Down
1 change: 1 addition & 0 deletions src/source/dune_project.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ val to_dyn : t -> Dyn.t
val file_key : t -> File_key.t
val packages : t -> Package.t Package.Name.Map.t
val name : t -> Dune_project_name.t
val version : t -> Package_version.t option
val root : t -> Path.Source.t
val stanza_parser : t -> Dune_lang.Stanza.t list Dune_lang.Decoder.t
val generate_opam_files : t -> bool
Expand Down
62 changes: 62 additions & 0 deletions test/blackbox-tests/test-cases/subst/dont-fail-on-opam-files.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
dune subst should not fail when adding the version field in opam files

$ cat > dune-project << EOF
> (lang dune 3.19)
> (name test)
> (version 0.1)
> (generate_opam_files)
> (package (name test) (allow_empty))
> EOF

$ dune build

$ cat test.opam
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1"
depends: [
"dune" {>= "3.19"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
x-maintenance-intent: ["(latest)"]

$ dune subst

$ cat test.opam
version: "0.1"
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1"
depends: [
"dune" {>= "3.19"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
x-maintenance-intent: ["(latest)"]
16 changes: 16 additions & 0 deletions test/blackbox-tests/test-cases/subst/without-repo.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ Demonstrate $ dune subst without a git repository

$ cat README.md
test

dune subst should take the project version from the dune-project file when
there is no vcs

$ cat > dune-project << EOF
> (lang dune 3.19)
> (name test)
> (version 0.1)
> EOF

$ echo "%%VERSION%%" > README.md

$ dune subst

$ cat README.md
0.1
Loading