env_helper
Jeremy Huddleston
jeremyhu at macports.org
Mon Mar 16 10:45:42 PDT 2009
On Mar 16, 2009, at 08:55, Bradley Giesbrecht wrote:
> On Mar 15, 2009, at 7:21 PM, Jeremy Huddleston wrote:
>
>> I think this is a bit too many files lying around.
>
> I really don't understand what the implied problem is here. Can you
> explain?
Clutter is bad. It's better to have everything in one file if
possible. This way if you have one port that wants to set PATH,
MANPATH, C_INCLUDE_PATH, OBJC_INCLUDE_PATH, PKG_CONFIG_PATH, ... it
just needs to create ONE file rather than one file per variable
>> Why have separate directories/files for each environment variable.
>
> That's the way path_helper does it.
Yes, and that is a problem. It doesn't scale well.
>> It seems cleaner to me to have:
>>
>> ${etcdir}/paths.d contain a set of files (one file per port).
>> These files are newline-delimited in the form:
>> ENVIRONMENT_VARIABLE=VALUE
>>
>> so you would have:
>>
>> ${etcdir}/paths.d/mysql contain:
>> PATH=/opt/local/lib/mysql5/bin
>>
>> ${etcdir}/paths.d/perl5 contain:
>> MANPATH=/opt/local/share/p5/man
>>
>> It would be nice to actually have this be backwards compatible with
>> path_helper, so if ${etcdir}/paths.d/myapp contained:
>> /opt/local/lib/some/bin
> That's what my script does now. paths.d is renamed PATH.d but
> that's the only diff. The files in PATH.d can be written exactly
> like path_helper files or they CAN use ${PREFIX} so the ports would
> use the system could have pre-written support files that would just
> be copied in place.
That's great, but that's only the backwards compatibility that I
mentioned, not the main idea. You said you have separate files per
port per variable:
/opt/local/etc/env_helper/paths/<VARIABLE>/<PORT>
I'm saying we should have one file per port:
/opt/local/etc/paths.d/<PORT>
> So you would parse the file into left and right side values and add
> them to the beginning of the current env var?
> echo $PATH
> /sbin:/bin
> becomes
> /opt/local/lib/mysql5/bin/sbin:/bin
I'm guessing you meant:
/opt/local/lib/mysql5/bin:/sbin:/bin
> This is obviously doable but it's more work then I wanted to put
> into it before I knew whether or not there is even an audience.
I don't think it's any more work than what you currently proposed, and
yes, there's certainly an audience. I wanted to do this last year,
but I never got around to it.
>> it would default to assume an implicit PATH=. Similarly, it could
>> support ${etcdir}/manpaths.d with an implicit MANPATH
>>
>> I thought about that last year, but I never got around to doing
>> anything about it ;)
>
> If you or someone wants to contribute parsing left and right of
> equal into vars go ahead and I'll support that.
>
> The thing is, when you have ENVIRONMENT_VARIABLE=VALUE how are you
> going to know whether or not you should prepend current var values
> with the new value and a path separator.
The same way you know now whether or not to prepend the current values
with the new value and a path separator. I don't understand the
confusion.
MANPATH=${PARSED_VALUE}${MANPATH+:${MANPATH}}
> I think your script wound have to be smart enough to know what to do
> with names.
I'm not sure what you mean by that.
> By having a path TYPE var we can drop anything in this dir and treat
> it the same knowing nothing about the var name.
And by having a line of the form "TYPE=VALUE", we know the exact same
information.
> I don't need to know what PERL5LIB is used for, it's in the paths
> dir, I'm going to concat with sep.
You don't need to know what PERL5LIB is used for any more in the
scenario that I proposed. The scenarios are bijective, so there's
nothing different in terms of expressibility or capability. It's just
a matter of organization.
Example (yes, this uses eval... no, I didn't feel like finding another
way):
simple_parse() {
local LINE VALUE VARIABLE
while read LINE ; do
VARIABLE=${LINE%%=*}
VALUE=${LINE#*=}
eval ${VARIABLE}=${VALUE}${!VARIABLE+:${!VARIABLE}}
done < ${1}
}
~ $ cat test
MYVAR=1234
MYVAR2=4567:3223
~ $ cat test2
MYVAR=432
MYVAR2=467:33
~ $ simple_parse test
~ $ echo $MYVAR
1234
~ $ echo $MYVAR2
4567:3223
~ $ simple_parse test2
~ $ echo $MYVAR
432:1234
~ $ echo $MYVAR2
467:33:4567:3223
More information about the macports-dev
mailing list