Bug 90917 - Allow overriding package variables with env vars
Summary: Allow overriding package variables with env vars
Status: RESOLVED FIXED
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Dan Nicholson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-09 18:53 UTC by Alexander Larsson
Modified: 2016-01-29 22:38 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Implement environment overrides of package variables (1.10 KB, patch)
2015-06-09 18:54 UTC, Alexander Larsson
Details | Splinter Review
New version (1.87 KB, patch)
2015-06-09 19:37 UTC, Alexander Larsson
Details | Splinter Review
Now with comment too (2.00 KB, patch)
2015-06-09 19:40 UTC, Alexander Larsson
Details | Splinter Review
Allow overriding package variables with env vars (4.12 KB, patch)
2015-06-13 17:27 UTC, Dan Nicholson
Details | Splinter Review
Pass key into parse_package_key so it can be set early (3.09 KB, patch)
2015-06-15 07:23 UTC, Alexander Larsson
Details | Splinter Review
Allow overriding package variables with env vars (4.04 KB, patch)
2015-06-15 07:23 UTC, Alexander Larsson
Details | Splinter Review
testoverlay: Add new input stacking test (2.61 KB, patch)
2015-06-15 08:56 UTC, Alexander Larsson
Details | Splinter Review
gdk: Add gdk_window_set_pass_through (6.81 KB, patch)
2015-06-15 08:56 UTC, Alexander Larsson
Details | Splinter Review
overlay: Add reorder_overlay() (8.12 KB, patch)
2015-06-15 08:56 UTC, Alexander Larsson
Details | Splinter Review
GtkOverlay: Add support for input pass-through overlays (4.82 KB, patch)
2015-06-15 08:56 UTC, Alexander Larsson
Details | Splinter Review
testoverlay: Fix test by using add_pass_through_overlay (896 bytes, patch)
2015-06-15 08:56 UTC, Alexander Larsson
Details | Splinter Review
testoverlay: Add test for overlay z ordering (2.97 KB, patch)
2015-06-15 08:56 UTC, Alexander Larsson
Details | Splinter Review

Description Alexander Larsson 2015-06-09 18:53:51 UTC
I'm building some stuff in a custom prefix (say /opt/foo) which relies on some variable in a pc file to detect where to install. For example, take the catalogdir variable in gladeui-2.0. This is normally in /usr/share/glade/catalogs, and when building modules this is looked up for the install destination.

I want to locally override this and install in /opt/foo/share/glade/catalogs instead (and I will then have to set the correct runtime env vars for glade to pick this up). 

There is currently no great way to do this. I tried setting PKG_CONFIG to "pkg-config --define-variable=catalogdir=/opt/foo/share/glade/catalogs", but that breaks when code doesn't look at PKG_CONFIG, and when code expects it to be an executable rather than a full commandline. It is also global, rather than per package.

I propose that we allow overriding package variables using environment variables. For instance in the above case one would set PKG_CONFIG_GLADEUI_2_0_CATALOGDIR=/opt/foo/share/glade/catalogs.
Comment 1 Alexander Larsson 2015-06-09 18:54:42 UTC
Created attachment 116399 [details] [review]
Implement environment overrides of package variables
Comment 2 Dan Nicholson 2015-06-09 19:12:06 UTC
Comment on attachment 116399 [details] [review]
Implement environment overrides of package variables

Review of attachment 116399 [details] [review]:
-----------------------------------------------------------------

Clever. I'd like to think there was another way to do this, but I think you may have come up with the most surefire way. You could add an overriding pc file, but that's cumbersome.

I can't think of any good reason not to take this. Could you please document this in pkg.1? A comment in the code above the block about what's going on would be helpful, too.

::: pkg-config-0.28/pkg.c.env
@@ +1012,4 @@
>  }
>  
>  char *
> +var_to_env_var (const char *key, const char *var)

It's called key in the struct, but here I think it would be clearer if the local variable was called pkg.

@@ +1043,5 @@
> +      char *env_var = var_to_env_var (pkg->key, var);
> +      const char *env_var_content = g_getenv (env_var);
> +      g_free (env_var);
> +      if (env_var_content)
> +        return g_strdup (env_var_content);

Can you add a debug statement here that the setting was overrident? Use debug_spew().
Comment 3 Alexander Larsson 2015-06-09 19:37:22 UTC
Created attachment 116400 [details] [review]
New version

I don't really know how to write manpages, but this one has at least some semblance of docs.
Comment 4 Alexander Larsson 2015-06-09 19:40:56 UTC
Created attachment 116401 [details] [review]
Now with comment too
Comment 5 Dan Nicholson 2015-06-13 17:27:06 UTC
Created attachment 116478 [details] [review]
Allow overriding package variables with env vars

pkg-config allows a way to override package variables through the
--define-prefix interface, but this is very cumbersome to do in a global
way since it always needs to be passed on the command line and the
override cannot be scoped to a single packge.

Allow overriding package variables using environment variables of the
form PKG_CONFIG_$PACKAGE_$VARIABLE. For example, setting
PKG_CONFIG_GLADEUI_2_0_CATALOGDIR will override the variable
"catalogdir" in the "gladeui-2.0" package.
Comment 6 Dan Nicholson 2015-06-13 17:30:42 UTC
While integrating this patch, I added a test case for it. See the attached patch (against git HEAD). Unfortunately, it seems to break as the variable is derived too late and won't be referenced correctly when resolving other variables. For instance, if prefix=/usr and libdir=${prefix}/lib but I override prefix to /foo, libdir is still /usr/lib.

I think this needs to happen earlier. You might have to take a look at how --define-variable works.
Comment 7 Alexander Larsson 2015-06-15 07:14:20 UTC
The reason it breaks is because pkg->key is not set until after we've fully parsed the pc file, and at that time the variables have already been resolved. So, when we resolve them pkg->key is NULL and we don't know what env var to look up in.
Comment 8 Alexander Larsson 2015-06-15 07:23:12 UTC
Created attachment 116498 [details] [review]
Pass key into parse_package_key so it can be set early

We will need this to properly pick up environment-overridden
per-package vairables.
Comment 9 Alexander Larsson 2015-06-15 07:23:15 UTC
Created attachment 116499 [details] [review]
Allow overriding package variables with env vars

pkg-config allows a way to override package variables through the
--define-prefix interface, but this is very cumbersome to do in a global
way since it always needs to be passed on the command line and the
override cannot be scoped to a single packge.

Allow overriding package variables using environment variables of the
form PKG_CONFIG_$PACKAGE_$VARIABLE. For example, setting
PKG_CONFIG_GLADEUI_2_0_CATALOGDIR will override the variable
"catalogdir" in the "gladeui-2.0" package.
Comment 10 Alexander Larsson 2015-06-15 07:23:57 UTC
(Note: The last patch did not actually change)
Comment 11 Alexander Larsson 2015-06-15 08:56:05 UTC
Created attachment 116501 [details] [review]
testoverlay: Add new input stacking test

In this case we have a bunch of interactive main children
of the overlay, and then a centered overlay that contains both
non-interactive (labels) and interactive (entry) widgets.

This shows off a problem where the non-interactive parts (the labels)
steals input from the overlay main children (breaks button click and
hover effects).

https://bugzilla.gnome.org/show_bug.cgi?id=750568
Comment 12 Alexander Larsson 2015-06-15 08:56:07 UTC
Created attachment 116502 [details] [review]
gdk: Add gdk_window_set_pass_through

An pass_through window is something you can draw in but does not
affect event handling. Normally if a window has with no event mask set
for a particular event then input events in it go to its parent window
(X11 semantics), whereas if pass_through is enabled the window below
the window will get the event. The later mode is useful when the
window is partially transparent. Note that an pass-through windows can
have child windows that are not pass-through so they can still get events
on some parts.

Semantically, this behaves the same as an regular window with
gdk_window_set_child_input_shapes() called on it (and re-called any
time a child is changed), but its far more efficient and easy to use.

This allows us to fix the testoverlay input stacking test.

https://bugzilla.gnome.org/show_bug.cgi?id=750568
Comment 13 Alexander Larsson 2015-06-15 08:56:10 UTC
Created attachment 116503 [details] [review]
overlay: Add reorder_overlay()

This allows you to control the z-ordering of overlay children

https://bugzilla.gnome.org/show_bug.cgi?id=750568
Comment 14 Alexander Larsson 2015-06-15 08:56:13 UTC
Created attachment 116504 [details] [review]
GtkOverlay: Add support for input pass-through overlays

For these widgets we set pass-through on the child window so that
input over these widgets (that are not on a child input window) goes
to the window below the overlay.

https://bugzilla.gnome.org/show_bug.cgi?id=750568
Comment 15 Alexander Larsson 2015-06-15 08:56:15 UTC
Created attachment 116505 [details] [review]
testoverlay: Fix test by using add_pass_through_overlay

https://bugzilla.gnome.org/show_bug.cgi?id=750568
Comment 16 Alexander Larsson 2015-06-15 08:56:18 UTC
Created attachment 116506 [details] [review]
testoverlay: Add test for overlay z ordering

https://bugzilla.gnome.org/show_bug.cgi?id=750568
Comment 17 Alexander Larsson 2015-06-15 09:59:55 UTC
Eh, sorry for the spam! Got the wrong bug link into git-bz.
Comment 18 Alexander Larsson 2015-06-24 13:01:59 UTC
ping? Any chance to get the latest version reviewed?
Comment 19 Alexander Larsson 2016-01-28 13:56:02 UTC
Ping again? This is very useful when building app bundles as some modules pick up installdir from system .pc files and try to write to /usr, not the prefix.
Comment 20 Dan Nicholson 2016-01-29 22:38:42 UTC
Fixed in ae0a8b1. I had to tweak the 2nd test case to skip on windows since apparently environment variables are case insensitive there. :/

Thanks!


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.