Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce the @pkg-deps alias #11046

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

maiste
Copy link
Collaborator

@maiste maiste commented Oct 28, 2024

This PR solves one part of #10949. It introduces a global alias with the source deps as a dependency. When you use it, you will automatically build the source deps of the project. Regarding the PR, I have various questions:

  • Should I update the documentation as it is related to package management? (I know we don't want to "pollute" the documentation with not released part)
  • Is there a better way to declare an alias, or is this way fine? I tried to take inspiration from other aliases.
  • For the test, would there be a cleaner way to check we only installed what we want at each stage. Here, it seems we can't use the printing solution, as we need to install a complete package.

Copy link
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure what our policy is about looking into _build in tests, but I have some ideas how to avoid doing it.

$ dune build @pkg-deps
$ ls _build/_private/default/.pkg/
foo
$ ls _build/default/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about the way to detect that the build is happening is to maybe enable the console output and have the opam file echo "foo is building".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should there be a build happening? This alias is supposed to only download the deps.

Verify that building the `bar.exe` file is working:
$ dune build ./bar.exe
$ ls _build/default/bar.exe
_build/default/bar.exe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this could then just be replaced by dune exec ./bar.exe?

This has the slight downside that bar.exe could've been built before so maybe building bar.exe should also echo something to stdout?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would mean to add a rule that depends on the bar.exe no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dune exec ./bar.exe automatically adds a dependency. Unless I misunderstand your question.

> (depends foo))
> EOF
$ add_mock_repo_if_needed
$ dune pkg lock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to involve the solver in this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the easiest way to write the test. However, it should be possible to write it without using the lock command. I'll rework it.


$ . ./helpers.sh

Create a fake library to install in the target project as a dependency:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really get why you need a fake library and executable in this test. I see the following as sufficient:

  1. Write a lock directory
  2. Build your new alias
  3. Verify that the sources exist

Everything else seems redundant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we want to build the library and ensure it is installed, you need the fake library to make sure dune build correctly. Otherwise, it will fail when you try to use it as a dependency.

@rgrinberg
Copy link
Member

To be consistent with dune, aliases should be attached to source directories. In particular:

The following should build all the sources in dune.lock

dune build @dune.lock/pkg-deps

The following should build all the sources in the workspace:

dune build @pkg-deps

If you'd like to download the sources for a particular package, maybe you could add an alias like dune build @dune.lock/$pkg-deps

@@ -25,4 25,5 @@ let check = standard "check"
let install = standard "install"
let ocaml_index = standard "ocaml-index"
let runtest = standard "runtest"
let pkg_deps = standard "pkg-deps"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this aliases is to download the sources? If it is, a more suggestive name would be pkg-sources or even just sources

@maiste
Copy link
Collaborator Author

maiste commented Oct 30, 2024

@rgrinberg, I feel there is a misunderstanding with the purpose of this PR... The goal is to introduce an alias that allows to download and build the sources of a project. In the issue related to it, we discuss two aliases with two different purposes:

  • @pkg-fetch whose role is to download the sources without building them. The use case targetted here is when you know you are going to be offline.
  • @pkg-deps whose role is to download the source and build them. Doing this allow to add a caching layer with Docker when building image. Docker can cache the build dependencies. Hence, when you update your own code, the engine won't try to rebuild the source. This is what this PR is trying to do.

The following should build all the sources in dune.lock
dune build @dune.lock/pkg-deps

I see. Where would be the best part to add the alias? gen_rules.ml? Also, could I take inspiration from runtest? I feel this is pretty related to this mechanism.

If you'd like to download the sources for a particular package, maybe you could add an alias like dune build @dune.lock/$pkg-deps

Isn't it something that should be attached to @pkg-fetch as it seems more relevant?

@rgrinberg
Copy link
Member

Okay, I think got confused by your implementation. It's currently adding the source deps to the alias. If you'd like the package build to included in the alias, you need to add the target directory of the package as a dependency.

@rgrinberg
Copy link
Member

I see. Where would be the best part to add the alias? gen_rules.ml? Also, could I take inspiration from runtest? I feel this is pretty related to this mechanism.

pkg_rules would be the ideal place

Isn't it something that should be attached to @pkg-fetch as it seems more relevant?

Don't think there's any difference between fetching and building here. But if you decide that you don't need per package granularity, that's OK too.

Also, if you want to check that a package has been built, inspecting _build or using of the shell commands in helpers.sh seems like the better bet. Including extra libraries or executables is still unnecessary moving parts. Our tests suffer from being slow, redundant, and rather hard to understand when failing. Less is more here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants