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

Fix pkg-config quoting behavior #1842

Merged
merged 4 commits into from
Feb 20, 2019

Conversation

rgrinberg
Copy link
Member

@rgrinberg rgrinberg commented Feb 14, 2019

Shows that on OSX (whenever brew is present), things are not being quoted correctly. This is another incentive for us to drop the builtin homebrew support we have in configurator (cc @avsm, @ejgallego, and @andreypopp)

@rgrinberg rgrinberg requested a review from a user February 14, 2019 04:13
@rgrinberg
Copy link
Member Author

To reiterate the arguments against any kind of homebrew support:

  • we don't have any special support for any of the package managers out there
  • the current support does not let users opt out of homebrew easily. They can't use macports for example.

The root of the problem is that we'd like dune to look for external libraries in places that the user has not specified explicitly. I'm not sure it's such a good idea to do this by default, and if it's done at all, it should clearly be more flexible than we have now

@rgrinberg
Copy link
Member Author

The last commit removes the homebrew magic, which is admittedly a breaking change and not something we can just do.

A more backwards compatible way to proceed would be to leave the homebrew stuff intact, and parse the ~query the user provides. We basically ignore anything after > < or =.

@rgrinberg
Copy link
Member Author

Okay, so I implemented the workaround mentioned above. It's not very attractive but should do the job. For dropping the brew support, perhaps we should finally introduce that V2 API. The API would be the same, but only V1 would use brew. I'm not such a fan of this idea, but I don't think we should break user packages.

| init :: xs ->
let pos = List.fold_left ~init ~f:min xs in
String.trim (String.take package pos)
in
[sprintf "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:%s/opt/%s/lib/pkgconfig"
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to construct %s/opt/%s/lib/pkgconfig and quote it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Quoting the environment is a good idea (Although I have a better fix for that coming up), but I don't think it would fix the issue. The ~package contains a pkg-config query which contains more than just name + version. So it wouldn't work to include it in the path.

@rgrinberg
Copy link
Member Author

Another possibility would be to add another function for our pkg-config API that would take the package name and the version query separately.

@rgrinberg rgrinberg changed the title Add test for pkg-config arugment quoting Add test for pkg-config argument quoting Feb 14, 2019
@rgrinberg
Copy link
Member Author

I've pushed a commit that avoids all env/quoting issues for pkg-config by avoiding the shell in the first place. We could extend its usage in other places, but there's no immediate need. It also seems like we should just extract this code and share it in our spawn module. We have a few other spots with very similar code.

As for the querying issue, @ejgallego I think the best course of action to fix the v1 API is to an optional argument. Roughly:

val query : t -> ?version_expr:string -> package:string -> package_conf option

In the V2 API, we'll get rid of this homebrew support altogether.

@ejgallego
Copy link
Collaborator

ejgallego commented Feb 14, 2019

As for the querying issue, @ejgallego I think the best course of action to fix the v1 API is to an optional argument.

I am very far from an expert on pkg-config but this doesn't seem right to me. pkg-config query language is not exactly trivial and users may come up with some complex constraints gtk+3.0 >= 3.12 libxml = 3 thus IMHO the package argument should be properly sent as a single quoted entry.

Also this seems better to keep compatibility in V1.

@rgrinberg
Copy link
Member Author

It certainly doesn't seem right to me either. But to "fix" the current homebrew behavior, we need to know the package name. Otherwise, we will not know how to append the PKG_CONFIG_PATH.

How about:

val query' : t -> query:string -> package_name:string -> package_conf option

where you provide the full expression query.

@avsm
Copy link
Member

avsm commented Feb 14, 2019

@rgrinberg wrote:

The root of the problem is that we'd like dune to look for external libraries in places that the user has not specified explicitly. I'm not sure it's such a good idea to do this by default, and if it's done at all, it should clearly be more flexible than we have now

I agree with this entirely. But we have to bear in mind that macOS developers form the majority of our desktop-dev users, and we should try to make things work out of the box. Some mechanism for Dune to centrally specify a search mechanism that could be tailored for the local package manager in one place would be extremely useful to have. Homebrew is very predictable in where it places libraries -- it's just different from all the other package managers.

@ejgallego
Copy link
Collaborator

where you provide the full expression query.

I'm afraid I don't know the necessary details to contribute a lot more here :(

I am just wondering why we cannot restore the old behavior, which so far used to work fine, didn't it?

@rgrinberg
Copy link
Member Author

rgrinberg commented Feb 14, 2019

I am just wondering why we cannot restore the old behavior, which so far used to work fine, didn't it?

The old behavior worked, but our homebrew support was still broken. By default, homebrew's pkg-config will indeed list most packages (which includes the gtk family of packages), so no homebrew specific hacks are necessary. However, if you tried doing that kind of expression with openssl for example, it would be broken again.

@rgrinberg
Copy link
Member Author

I agree with this entirely. But we have to bear in mind that macOS developers form the majority of our desktop-dev users, and we should try to make things work out of the box. Some mechanism for Dune to centrally specify a search mechanism that could be tailored for the local package manager in one place would be extremely useful to have. Homebrew is very predictable in where it places libraries -- it's just different from all the other package managers.

Note that the issue isn't with homebrew in general, but only a few select packages that are "keg only" - openssl being the most prominent example. I think it's acceptable that these packages will take on these hacks rather than configurator.

@ejgallego
Copy link
Collaborator

I see, thanks for the explanation @rgrinberg

@rgrinberg rgrinberg changed the title Add test for pkg-config argument quoting Fix pkg-config quoting behavior Feb 17, 2019
@ghost
Copy link

ghost commented Feb 18, 2019

Looking at this discussion, I suggest the following changes:

  • we introduce query' with the suggested API
  • we keep the quoting performed by query unchanged (i.e. as in 1.6)
  • to avoid constructing bindings of the form PKG_CONFIG_PATH=/opt/gtk >= 3/lib/pkg-config, we only extend PKG_CONFIG_PATH if the directory /opt/PACKAGE/lib/pkg-config exists, where PACKAGE is the exact string given by the user
  • we make query display a warning when the package name contains special characters

with this plan, existing packages won't be affected. Packages using configurator to query keg-only pkg-config packages will have to upgrade to query' in order to perform complex queries.

@ejgallego
Copy link
Collaborator

ejgallego commented Feb 18, 2019

Isn't it query' a bit of an strange name?

@ghost
Copy link

ghost commented Feb 18, 2019

Indeed. I don't have a better suggestion though

@rgrinberg
Copy link
Member Author

I've added a query_expr function that attempts to implement the proposal. @ejgallego could you try it out?

@rgrinberg rgrinberg force-pushed the show-quoting-issue-osx branch 2 times, most recently from c6c9b04 to 8aabc1b Compare February 19, 2019 10:31
@rgrinberg
Copy link
Member Author

@diml this is ready for review

src/configurator/v1.ml Outdated Show resolved Hide resolved
let stdout = openfile stdout_fn in
let stderr = openfile stderr_fn in
let (stdin, stdin_w) = Unix.pipe () in
Unix.close stdin_w;
Copy link

@ghost ghost Feb 19, 2019

Choose a reason for hiding this comment

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

No objection here, but note that we don't do this for processes started by dune

@ejgallego
Copy link
Collaborator

ejgallego commented Feb 19, 2019

I've added a query_expr function that attempts to implement the proposal. @ejgallego could you try it out?

Thanks @rgrinberg , I've launched a build with this branch here:

it seems to work !

And this is one where I am using the new API:

one build fails due to missing OPAM constraint on dune >= 1.7.2 but indeed it seems to work fine too.

Shows that on OSX (whenever brew is present), things are not being quoted correctly.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Running it directly avoids issues with quoting and environment handling

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
For more complex pkg config queries

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
@rgrinberg rgrinberg merged commit 8fc5284 into ocaml:master Feb 20, 2019
@rgrinberg rgrinberg deleted the show-quoting-issue-osx branch February 20, 2019 09:14
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Feb 21, 2019
CHANGES:

- Add `${corrected-suffix}`, `${library-name}` and a few other
  variables to the list of variables to upgrade. This fixes the
  support for various framework producing corrections (ocaml/dune#1840, ocaml/dune#1853,
  @diml)

- Fix `$ dune subst` failing because the build directory wasn't set. (ocaml/dune#1854, fix
  ocaml/dune#1846, @rgrinberg)

- Configurator: Add warning to `Pkg_config.query` when a full package expression
  is used. Add `Pkg_config.query_expr` for cases when the full power of
  pkg-config's querying is needed (ocaml/dune#1842, fix ocaml/dune#1833, @rgrinberg)

- Fix unavailable, optional implementations eagerly breaking the build (ocaml/dune#1857,
  fix ocaml/dune#1856, @rgrinberg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants