gcc 4.8.1 made it to Debian Sid

Iain Buclaw ibuclaw at ubuntu.com
Wed Jul 10 08:08:03 PDT 2013


On 10 July 2013 15:14, H. S. Teoh <hsteoh at 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 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.
>

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';


More information about the D.gnu mailing list