Closed Fabien-Chouteau closed 4 years ago
It would be nice if the with command prints the GNAT projects that the new library provides.
@mosteo Do you have an idea where I could start to implement this? How do I get the list of project file dependencies from a crate that is "withed"?
You need to first solve the new dependency to get the recursive solution. This is done with https://github.com/alire-project/alire/blob/123fd7ca303ddb16ed6d2a6f3a5c0d118b814afa/src/alr/alr-query.ads#L110
Then you can iterate over the releases in the solution to get their project files.
Seems like it would be easier to have all the with
between special comments in the project file and rewrite all of them every time.
Here are some of the results of my investigations on the subject:
This is a little bit more difficult to implement than I expected. I couldn't find a way to get just the list of project files for the new dependency.
The main problem I see, is the handling of all the possibilities of project files. For instance:
with
will result in an error.with
will result in an error.In my opinion, the options are:
alr with
is not enough to use a dependency.I couldn't find a way to get just the list of project files for the new dependency.
I think I misunderstood you in my previous answer. I don't know why I was thinking of the complete solution when you only want the newly withed crate, or the direct dependencies at most.
I'll prepare a snippet shortly.
The main problem I see, is the handling of all the possibilities of project files.
Right. Some thoughts about these cases you list:
- Delay this feature for a future release, and rely on tutorial to explain that
alr with
is not enough to use a dependency.
If we do nothing, at least I'd add a warning to alr with
like "Remember to modify your project file or consult the crate documentation".
- Add a key in the manifest for maintainers to declare if the project files should be automatically added or not (probably with a default to yes).
Seems a sensible next step after 1). One of the choices to cover all bases instead of binary add all/add none could be to prompt interactively, see below.
- Consider that the the corner cases will not cause more harm than good. And implement the feature anyway.
I'd avoid introducing a feature that will fail in some cases during expected use if we have some kind of alternative. Especially if this will require the user to edit the "out-of-bounds" with-section created by alr in their project file to fix the situation.
As for interactivity, I imagined a menu like:
Consult the crate documentation on usage. Do you want alr to:
0 : Do nothing.
[1]: Add all new project files to your <crate.gpr> project file
2 : Add only <file1.gpr>
3 : Add only <file2.gpr>
If there is one/none declared project files, modify choice one to show that [default] project file.
If running non-interactive we do nothing (we can add a switch to alr with
to handle it). We could even store in the index a with-notes
text to be shown during this prompt (or instead, for cases like GESTE).
Here is an example of retrieving the project files in a new dependency (lines 67-83): https://github.com/mosteo/alire/blob/aa6155c76f6e56269c84460c69a68936fcb481d4/src/alr/alr-commands-withing.adb#L67
This is a very interesting suggestion that we had a FOSDEM and I think we should do it.
The idea is that currently when the users do
alr with ada_toml
, they will also have to edit their gpr file to addwith "ada_toml.gpr";
. It would be way more user friendly to automate this.I think we have all the information required because we know the project file of the current/local
Alire
project that needs to be edited, and we also have the list of project files from a dependency that have to be added.For project that needs to be extended like
GESTE
, we can potentially offer an option to deactivate this feature from the toml file.And for users that don't want their project file to be modified, we can have command line option to deactivate as well.