Skip to content

Commit

Permalink
Merge branch 'main' into test-ocaml-5.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon authored Aug 2, 2024
2 parents 6cb9608 + f0d9877 commit 40c6a89
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1757,9 +1757,27 @@ let build_rule context_name ~source_deps (pkg : Pkg.t) =
in
copy_action
@ List.map pkg.info.extra_sources ~f:(fun (local, _) ->
(* If the package has extra sources, they will be
initially stored in the extra_sources directory for that
package. Prior to building, the contents of
extra_sources must be copied into the package's source
directory. *)
let src = Paths.extra_source pkg.paths local in
let dst = Path.Build.append_local pkg.write_paths.source_dir local in
Action.copy src dst |> Action.Full.make |> Action_builder.With_targets.return)
Action.progn
[ (* If the package has no source directory (some
low-level packages are exclusively made up of extra
sources), the source directory is first created. *)
Action.mkdir pkg.write_paths.source_dir
; (* It's possible for some extra sources to already be at
the destination. If these files are write-protected
then the copy action will fail if we don't first remove
them. *)
Action.remove_tree dst
; Action.copy src dst
]
|> Action.Full.make
|> Action_builder.With_targets.return)
and+ build_action =
match Action_expander.build_command context_name pkg with
| None -> Memo.return []
Expand Down
24 changes: 24 additions & 0 deletions test/blackbox-tests/test-cases/pkg/exclusively-extra-sources.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Test for packages with no source field but with extra_sources.

$ . ./helpers.sh
$ make_lockdir

$ cat > dune.lock/foo.pkg <<EOF
> (version 1)
> (extra_sources
> (foo.txt
> (fetch
> (url file://$PWD/foo.txt))))
> EOF

$ touch foo.txt

$ cat > dune-project <<EOF
> (lang dune 3.16)
> (package
> (allow_empty)
> (name a)
> (depends foo))
> EOF

$ dune build
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Test for packages with an extra-source file with the same name as a
file in the package's source.

$ . ./helpers.sh
$ make_lockdir

$ cat > dune.lock/foo.pkg <<EOF
> (version 1)
> (source
> (copy $PWD/foo-source))
> (extra_sources
> (foo.txt
> (fetch
> (url file://$PWD/foo.txt))))
> EOF

$ mkdir -p foo-source
$ echo "from source" > foo-source/foo.txt

$ echo "from extra source" > foo.txt

$ cat > dune-project <<EOF
> (lang dune 3.16)
> (package
> (allow_empty)
> (name a)
> (depends foo))
> EOF

$ dune build

Make sure that the package's source directory ends up with the version
of foo.txt from extra_sources:
$ cat _build/_private/default/.pkg/foo/source/foo.txt
from extra source

0 comments on commit 40c6a89

Please sign in to comment.