Skip to content

Commit

Permalink
Fix rule target conflict with extra source (#10706)
Browse files Browse the repository at this point in the history
* Fix rule target conflict with extra source

This is a quick fix that addresses the "Error: Multiple rules
generated for <target>" when building a package with the extra-source
field. This isn't expected to work in cases where a package has
multiple extra-source entries, which will come in a later change.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>

* Update test output after rebasing

Signed-off-by: Marek Kubica <marek@tarides.com>

* Fix test so it does not accidentally vendor `needs-patch`

Signed-off-by: Marek Kubica <marek@tarides.com>

* Remove git dir from extra-sources test tarball

Workaround for an issue where our oneshot webserver disconnects from
the client too early when sending large files. Remoning the .git
directory from the tarball used in the extra-sources test reduces the
size of the tarball to avoid the problem.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>

---------

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
Signed-off-by: Marek Kubica <marek@tarides.com>
Co-authored-by: Marek Kubica <marek@tarides.com>
  • Loading branch information
gridbugs and Leonidas-from-XIV authored Jul 10, 2024
1 parent 5905292 commit a855dd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ let source_rules (pkg : Pkg.t) =
| `Directory_or_archive src ->
loc, Action_builder.copy ~src:(Path.external_ src) ~dst:extra_source
| `Fetch ->
let rule = Fetch_rules.fetch ~target:pkg.paths.source_dir `File fetch in
let rule = Fetch_rules.fetch ~target:extra_source `File fetch in
loc, rule
in
Path.build extra_source, rule)
Expand Down
26 changes: 11 additions & 15 deletions test/blackbox-tests/test-cases/pkg/extra-sources.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@ First we need a project that will have the patch applied:
$ git init --quiet
$ cat > dune-project <<EOF
> (lang dune 3.15)
> (name needs-patch)
> EOF
$ cat > needs_patch.opam <<EOF
$ cat > needs-patch.opam <<EOF
> opam-version: "2.0"
> EOF
$ cat > dune <<EOF
> (library (public_name needs_patch))
> (library (public_name needs-patch) (name needs_patch))
> EOF
$ cat > needs_patch.ml <<EOF
> let msg = "Needs to be patched"
> EOF
$ git add -A
$ git commit -m "Initial" --quiet
$ cd ..
$ tar cf needs-patch.tar needs-patch
$ SRC_MD5=$(md5sum needs-patch.tar | cut -f1 -d' ')
$ cd needs-patch
$ git add -A
$ git commit -m "Initial" --quiet
$ cat > needs_patch.ml <<EOF
> let msg = "Patch successfully applied"
> EOF
Expand All @@ -62,6 +63,7 @@ First we need a project that will have the patch applied:
> EOF
$ git diff > ../additional.patch
$ cd ..
$ rm -rf needs-patch
$ REQUIRED_PATCH_MD5=$(md5sum required.patch | cut -f1 -d' ')
$ ADDITIONAL_PATCH_MD5=$(md5sum additional.patch | cut -f1 -d' ')
Expand All @@ -79,6 +81,7 @@ package.
$ mkrepo
$ mkpkg needs-patch 0.0.1 <<EOF
> build: ["dune" "build" "-p" name "-j" jobs]
> patches: ["required.patch"]
> url {
> src: "http://localhost:$SRC_PORT"
Expand All @@ -98,7 +101,7 @@ that is supposed to get patched.
> (package (name my) (depends needs-patch))
> EOF
$ cat > dune <<EOF
> (executable (public_name display) (libraries needs_patch))
> (executable (public_name display) (libraries needs-patch))
> EOF
$ cat > display.ml <<EOF
> let () = print_endline Needs_patch.msg
Expand All @@ -116,11 +119,7 @@ Running the binary should download the tarball & patch, build them and show the
correct, patched, message:

$ dune exec ./display.exe
Error: Multiple rules generated for
_build/_private/default/.pkg/needs-patch/source:
- dune.lock/needs-patch.pkg:14
- dune.lock/needs-patch.pkg:8
[1]
Patch successfully applied

Set up a new version of the package which has multiple `extra-sources`, the
application order of them mattering:
Expand All @@ -136,6 +135,7 @@ application order of them mattering:
$ ADDITIONAL_PATCH_PORT=$(cat additional-patch-port.txt)

$ mkpkg needs-patch 0.0.2 <<EOF
> build: ["dune" "build" "-p" name "-j" jobs]
> patches: ["required.patch" "additional.patch"]
> url {
> src: "http://localhost:$SRC_PORT"
Expand All @@ -160,8 +160,4 @@ Lock the project to use that new package
Running the binary should work and output the double patched message:

$ dune exec ./display.exe
Error: Multiple rules generated for
_build/_private/default/.pkg/needs-patch/source:
- dune.lock/needs-patch.pkg:16
- dune.lock/needs-patch.pkg:20
[1]
Patch successfully applied, multiple times

0 comments on commit a855dd7

Please sign in to comment.