Thread overview
Re: gcc 4.8.1 made it to Debian Sid
Jul 10, 2013
H. S. Teoh
Jul 10, 2013
Johannes Pfau
Jul 10, 2013
Johannes Pfau
Jul 10, 2013
Kagamin
Jul 10, 2013
Kagamin
Jul 10, 2013
Iain Buclaw
July 10, 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@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.
July 10, 2013
On 10 July 2013 15:14, H. S. Teoh <hsteoh@quickfur.ath.cx> wrote:
> 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@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.
>

Most people won't invoke the command by it's absolute path.  But for those who do, I guess it's not unreasonable to check /absolute/path/gdc too.  I was just raising eyebrows at platform-dependant or "does not work 100% of the time" solutions. :o)

--
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
July 10, 2013
Am Wed, 10 Jul 2013 07:14:27 -0700
schrieb "H. S. Teoh" <hsteoh@quickfur.ath.cx>:

> 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.

Getting the real application path is not simple and not portable, but if you really want to do that:

http://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe/1024937#1024937
July 10, 2013
On 07/10/2013 05:25 PM, Johannes Pfau wrote:
> Getting the real application path is not simple and not portable, but if you really want to do that:

I found the same links and was wondering about that, but to be honest -- I think Iain is right and this kind of stuff is overkill.

Let gdmd just be a script that invokes the default system gdc (i.e. the first in the path).  To do that, we just need to get the PATH variable, and we don't even need to care about where gdmd itself is located.
July 10, 2013
Am Wed, 10 Jul 2013 18:23:54 +0200
schrieb Joseph Rushton Wakeling <joseph.wakeling@webdrake.net>:

> On 07/10/2013 05:25 PM, Johannes Pfau wrote:
> > Getting the real application path is not simple and not portable, but if you really want to do that:
> 
> I found the same links and was wondering about that, but to be honest -- I think Iain is right and this kind of stuff is overkill.
> 
> Let gdmd just be a script that invokes the default system gdc (i.e. the first in the path).  To do that, we just need to get the PATH variable, and we don't even need to care about where gdmd itself is located.

Right. And you could always still accept an optional parameter --use-gdc=/path/gdc and an environment variable GDMD_GDC=/path/gdc.
July 10, 2013
On Wednesday, 10 July 2013 at 15:25:02 UTC, Johannes Pfau wrote:
> Getting the real application path is not simple and not portable, but
> if you really want to do that:
>
> http://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c
> http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe/1024937#1024937

On Windows you don't have to use GetModuleFileName as argv[0] has the full path.
July 10, 2013
Also this getexecname function is a good candidate for std.process.