A tool that tries to build every Dub package against a wide range of DMD versions.

dmd.d 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. module backporter.dmd;
  2. import backporter.core;
  3. import std.experimental.logger;
  4. void downloadCompiler(ref Config config)
  5. {
  6. static import std.file;
  7. import std.path : buildPath;
  8. auto binLoc = download(config.compilerRelease);
  9. config.dmdLoc = buildPath(binLoc, "dmd");
  10. auto dubLoc = buildPath(binLoc, "dub");
  11. if (std.file.exists(dubLoc))
  12. {
  13. config.dubLoc = dubLoc;
  14. }
  15. else
  16. {
  17. config.dubLoc = config.fallbackDub;
  18. }
  19. }
  20. private string download(string release)
  21. {
  22. import std.string : format;
  23. import std.net.curl : download;
  24. import backporter.git : run, env, dataDir, cd;
  25. import std.process : environment;
  26. static import std.file;
  27. import std.path : buildPath, absolutePath;
  28. auto dir = ("dmd" ~ release).absolutePath;
  29. auto binDir = buildPath(dir, "dmd2/linux/bin64/").absolutePath;
  30. auto dmd = binDir.buildPath("dmd");
  31. if (std.file.exists(dmd)) return binDir;
  32. std.file.mkdirRecurse(dir);
  33. cd(dir);
  34. scope (exit) cd(dataDir);
  35. if (!std.file.exists(binDir))
  36. {
  37. auto url = "http://downloads.dlang.org/releases/2.x/%1$s/dmd.%1$s.linux.tar.xz".format(release);
  38. infof("downloading dmd %s from %s", release, url);
  39. auto xz = dir.buildPath("dmd.tar.xz");
  40. if (std.file.exists(xz)) std.file.remove(xz);
  41. download(url, xz);
  42. infof("downloaded, unpacking");
  43. auto res = run("tar", "xf", xz);
  44. if (res.status != 0)
  45. {
  46. throw new Exception("failed to download/extract " ~ release ~ " from " ~ url);
  47. }
  48. }
  49. env["PATH"] = binDir ~ ":" ~ environment["PATH"];
  50. return binDir;
  51. }