gcc 4.8.1 made it to Debian Sid
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Jul 10 07:14:27 PDT 2013
On Wed, Jul 10, 2013 at 03:39:48PM +0200, eles wrote:
> On Wednesday, 10 July 2013 at 12:58:41 UTC, Iain Buclaw wrote:
> >On 10 July 2013 13:14, eles <eles at eles.com> wrote:
> >>On Wednesday, 10 July 2013 at 12:03:06 UTC, eles wrote:
> >>Quick and unportable (Linux-only) drop-in replacement:
> >>
> >
> >Christ on a bike. What's wrong with:
> >
> >import std.file;
> >import std.process : environment;
> >
> >auto binpaths = environment.get("PATH");
> >
> >foreach (path; binpaths.split(<delimiter>)
> >{
> > auto exe = path ~ <dirsep> ~ "gdc";
> > if (exists (exe)) {
> > // found
> > }
> >}
>
> Almost nothing (just a bracket).
lol, you guys are a riot. :)
> So, to make Teoh's life easier:
>
> diff --git a/gdmd.d b/gdmd.d
> index 6607ce2..12c610f 100644
> --- a/gdmd.d
> +++ b/gdmd.d
> @@ -141,13 +141,19 @@ string findScriptPath(string argv0)
> /**
> * Finds GDC.
> */
> -string findGDC(string argv0)
> +string findGDC()
> {
> - // FIXME: this does not work 100% of the time.
> - auto c = match(baseName(argv0),
> `^(.*-)?g?dmd(-.*)?$`).captures;
> - auto targetPrefix = c[1];
> - auto gdcDir = absolutePath(dirName(argv0));
> - return buildNormalizedPath(gdcDir, targetPrefix ~ "gdc" ~
> c[2]);
> + auto binpaths = environment.get("PATH");
> +
> + foreach (path; binpaths.split(pathSeparator))
> + {
> + auto exe = path ~ dirSeparator ~ "gdc";
> + if (exists (exe)) {
> + return exe;
> + }
> + }
> +
> + return "";
> }
>
> /**
> @@ -262,7 +268,7 @@ Config init(string[] args)
> {
> auto cfg = new Config();
> cfg.scriptPath = findScriptPath(args[0]);
> - cfg.gdc = findGDC(args[0]);
> + cfg.gdc = findGDC();
> cfg.linker = cfg.gdc;
>
> readDmdConf(cfg);
I actually thought about this before I wrote what I did; the reason I
didn't do it, was because what the original script *appeared* to be
doing (I didn't check, so I'm not sure) is to first identify itself
(find the path to itself) then use that path to locate gdc. This is
pretty useful because you can have multiple gdc/gdmd installations:
/usr
/usr/bin
/usr/bin/gdc
/usr/bin/gdmd
/opt
/opt/bin
/opt/bin/gdc
/opt/bin/gdmd
then if you run /opt/bin/gdmd, it knows to invoke /opt/bin/gdc, and if
you run /usr/bin/gdmd, it knows to invoke /usr/bin/gdc.
But like Iain said, this is probably nitpicking about unimportant
things, so I think I'll just apply the patch and be done with it. :)
(Unless somebody comes up with an easy way of doing the above that
doesn't involve (too much) black magic.)
Also, I've added some naïve option-parsing since I wrote that previous
email, but I'm not 100% happy with it. It's too Perl-like. Last night
after going to bed I was thinking about whether it would be nicer to use
an AA or trie to match options instead of a long chain of if-else.
What's the usual "D way"? (I *did* consider using std.getopt as I'm
accustomed to, but in this case DMD appears to have an idiomatic syntax
that std.getopt doesn't quite provide, so I didn't.)
T
--
Valentine's Day: an occasion for florists to reach into the wallets of
nominal lovers in dire need of being reminded to profess their
hypothetical love for their long-forgotten.
More information about the D.gnu
mailing list