1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- module backporter.dmd;
-
- import backporter.core;
- import std.experimental.logger;
-
- void downloadCompiler(ref Config config)
- {
- static import std.file;
- import std.path : buildPath;
- auto binLoc = download(config.compilerRelease);
- config.dmdLoc = buildPath(binLoc, "dmd");
-
- auto dubLoc = buildPath(binLoc, "dub");
- if (std.file.exists(dubLoc))
- {
- config.dubLoc = dubLoc;
- }
- else
- {
- config.dubLoc = config.fallbackDub;
- }
- }
-
- private string download(string release)
- {
- import std.string : format;
- import std.net.curl : download;
- import backporter.git : run, env, dataDir, cd;
- import std.process : environment;
- static import std.file;
- import std.path : buildPath, absolutePath;
-
- auto dir = ("dmd" ~ release).absolutePath;
- auto binDir = buildPath(dir, "dmd2/linux/bin64/").absolutePath;
- auto dmd = binDir.buildPath("dmd");
- if (std.file.exists(dmd)) return binDir;
- std.file.mkdirRecurse(dir);
- cd(dir);
- scope (exit) cd(dataDir);
- if (!std.file.exists(binDir))
- {
- auto url = "http://downloads.dlang.org/releases/2.x/%1$s/dmd.%1$s.linux.tar.xz".format(release);
- infof("downloading dmd %s from %s", release, url);
- auto xz = dir.buildPath("dmd.tar.xz");
- if (std.file.exists(xz)) std.file.remove(xz);
- download(url, xz);
- infof("downloaded, unpacking");
- auto res = run("tar", "xf", xz);
- if (res.status != 0)
- {
- throw new Exception("failed to download/extract " ~ release ~ " from " ~ url);
- }
- }
- env["PATH"] = binDir ~ ":" ~ environment["PATH"];
- return binDir;
- }
|