@@ -27,14 +27,8 @@ import dmd.root.outbuffer;
27
27
import dmd.root.rmem;
28
28
import dmd.root.string ;
29
29
30
- version (IN_LLVM)
31
- {
32
- enum supportedPre2017Versions = [" 14.0" .ptr];
33
- }
34
- else
35
- {
36
- enum supportedPre2017Versions = [" 14.0" .ptr, " 12.0" , " 11.0" , " 10.0" , " 9.0" ];
37
- }
30
+ version (IN_LLVM) enum supportedPre2017Versions = [" 14.0" .ptr];
31
+ else enum supportedPre2017Versions = [" 14.0" .ptr, " 12.0" , " 11.0" , " 10.0" , " 9.0" ];
38
32
39
33
extern (C++ ) struct VSOptions
40
34
{
@@ -361,15 +355,7 @@ public:
361
355
*/
362
356
const (char )* getVCBinDir (bool x64, out const (char )* addpath) const
363
357
{
364
- static const (char )* linkExists (scope const (char )* [] dirs... )
365
- {
366
- auto p = buildPathWithSuffix(" link.exe" , dirs);
367
- const (char )* result = null ;
368
- if (FileName.exists(p))
369
- result = FileName.path(p);
370
- mem.xfree(p);
371
- return result;
372
- }
358
+ alias linkExists = returnDirIfContainsFile! " link.exe" ;
373
359
374
360
const bool isHost64 = isWin64Host();
375
361
if (VCToolsInstallDir ! is null )
@@ -478,15 +464,7 @@ public:
478
464
{
479
465
if (WindowsSdkDir)
480
466
{
481
- static const (char )* kernel32Exists (scope const (char )* [] dirs... )
482
- {
483
- auto p = buildPathWithSuffix(" kernel32.lib" , dirs);
484
- const (char )* result = null ;
485
- if (FileName.exists(p))
486
- result = FileName.path(p);
487
- mem.xfree(p);
488
- return result;
489
- }
467
+ alias kernel32Exists = returnDirIfContainsFile! " kernel32.lib" ;
490
468
491
469
const (char )* arch = x64 ? " x64" : " x86" ;
492
470
auto sdk = FileName.combine(WindowsSdkDir, " lib" );
@@ -685,49 +663,50 @@ char* getenv(wstring name)
685
663
return null ;
686
664
}
687
665
688
- char * buildPathWithSuffix ( string suffix, const (char )* [] dirs ... )
666
+ char * buildPath ( const (char )* [] fragments ... )
689
667
{
690
- assert (dirs .length);
668
+ assert (fragments .length);
691
669
692
- const (char )[][] ddirs = (cast (const (char )[]* ) mem.xmalloc_noscan(dirs .length * string .sizeof))[0 .. dirs .length];
693
- scope (exit) mem.xfree(ddirs .ptr);
670
+ const (char )[][] f = (cast (const (char )[]* ) mem.xmalloc_noscan(fragments .length * string .sizeof))[0 .. fragments .length];
671
+ scope (exit) mem.xfree(f .ptr);
694
672
695
673
size_t size;
696
- foreach (i, dir; dirs )
674
+ foreach (i, fragment; fragments )
697
675
{
698
- ddirs [i] = dir .toDString;
699
- size += ddirs [i].length + 1 ;
676
+ f [i] = fragment .toDString;
677
+ size += f [i].length + 1 ;
700
678
}
701
- if (suffix.length)
702
- size += suffix.length + 1 ;
703
679
704
680
char * p = cast (char * ) mem.xmalloc_noscan(size);
705
681
size_t length;
706
- foreach (dir; ddirs )
682
+ foreach (fragment; f )
707
683
{
708
- assert (dir .length);
709
- p[length .. length + dir .length] = dir ;
710
- length += dir .length;
684
+ assert (fragment .length);
685
+ p[length .. length + fragment .length] = fragment ;
686
+ length += fragment .length;
711
687
const last = p[length - 1 ];
712
688
if (last != ' \\ ' && last != ' /' )
713
689
p[length++ ] = ' \\ ' ;
714
690
}
715
691
716
- if (suffix.length)
717
- {
718
- p[length .. length + suffix.length] = suffix;
719
- length += suffix.length;
720
- p[length] = 0 ;
721
- }
722
- else
723
- p[-- length] = 0 ; // overwrite last '\' with null terminator
692
+ // overwrite last '\' with null terminator
693
+ p[-- length] = 0 ;
724
694
725
695
return p;
726
696
}
727
697
728
- char * buildPath ( const (char )* [] fragments ... )
698
+ char * returnDirIfContainsFile ( string fileName)( scope const (char )* [] dirs ... )
729
699
{
730
- return buildPathWithSuffix (null , fragments);
700
+ auto dirPath = buildPath(dirs);
701
+
702
+ auto filePath = FileName.combine(dirPath, fileName);
703
+ scope (exit) FileName.free(filePath);
704
+
705
+ if (FileName.exists(filePath))
706
+ return dirPath;
707
+
708
+ mem.xfree(dirPath);
709
+ return null ;
731
710
}
732
711
733
712
extern (C ) int _waccess(const (wchar )* _FileName, int _AccessMode);
0 commit comments