env_helper

Rainer Müller raimue at macports.org
Mon Mar 16 11:17:44 PDT 2009


On 2009-03-15 23:25, Bradley Giesbrecht wrote:
> I'm thinking I like this.
> 
> I just added paths for ${PREFIX}/apach2/bin and ${PREFIX}/lib/mysql5/ 
> bin to /opt/local/etc/env_helper/paths/PATH/(apache2 & mysql5).

Okay, so you expect this to be added to PATH. At the front? At the end?
In which order?

How will it now it needs to do concat at all and not replace? (Thinking
of possible more general settings). How will it know to concat using ":"
and not spaces?

For apache2, this is just the old lame reason that nobody fixed the
layout yet to be inside $prefix :-)

mysql5 does not put the files into $prefix/bin because it conflicts with
mysql4. If now both ports add the alternative dir to PATH this lends to
confusion and breakage.

For example, you installed mysql4 which has added the libdir to PATH
this way. Typing "mysql" is actually mysql4. Now some port also pulls in
mysql5 which you do not recognize at all and suddenly "mysql" is mysql5
because for some reason the PATH ended up in this order.

By the way, can anybody think of other ports we did not talk about yet
for which something like this could be useful? For example, I can think
of bash-completion.

I concur with Jeremy that a equal sign separated format would be the
better choice for this, for clarity and maintenance, one file per port
is enough.

What I would like to see is a way to choose which items
are actually added to my environment, because I still want to have
control. I think the easiest would be to use symlinks. I have a layout
in mind similar to what is used for init-scripts on most systems.

To address the issues mentioned above and support a little bit more we
would have to split it into env and profile:

${etcdir}/env-avail.d/:
  apache2
  mysql5
${etcdir}/env.d/:
  apache2 -> ../env-avail.d/apache2
  mysql5 -> ../env-avail.d/mysql5
${etcdir}/profile-avail.d/:
  bash-completion
  trac-tools
${etcdir}/profile.d/:
  trac-tools -> ../profile-avail.d/trac-tools

(Think of trac-tools making [1] available, as I can't think of another
existing port right now).

env.d is meant to contain files in the equal sign separated format which
are concatenated. Rules for concatenation are The order has yet to be
defined (possible using 00foo through 99bar in the symlinks?).

profile.d is meant to contain arbitrary shell scripts registering
aliases/functions etc.

And then we would have a `port env` command which operates on these dirs
and files as follows:

port env --enable bash-completion
port env --disable bash-completion
  Creates/removes a symlink in profile.d pointing to profile-avail.d

port env --update
  Generates or updates ${etcdir}/profile based on the current symlink
  layout, which is then used by `port env` as traversing all the files
  each time a shell is spawned is probably a bit slow. Could also
  generate ${etcdir}/profile.csh or similar. Needs to be run
  after --enable/--disable or port installes/upgrades to apply changes.
  Ideally port would check for file modification time of ${etcdir}/*.d/
  after activation and recommend to run env-update if necessary.

A user would only need to add this line to his .profile to load MacPorts:
  [ -f /opt/local/etc/profile ] && source /opt/local/etc/profile


Still reading? Comments? ;-)

> [...]
> This can probably be done better but I do think this adds value with  
> little cost.

This will definitely be useful, especially as it reduces the need of
lines to be added to the profile. I started something different for this
earlier with $prefix/share/macports/setupenv.bash in which nobody seemed
to be interested (e.g. similar scripts for tcsh/zsh). But this could be
incorporated into the new ${etcdir}/profile.

Rainer

[1]
http://trac.macports.org/wiki/CommittersTipsAndTricks#ApplypatchesdirectlyfromTracURL


More information about the macports-dev mailing list