Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Responsible for grabbing latest source and building
- */
- module build.dsystem;
- import std.conv;
- import std.file;
- import std.path;
- import std.process;
- import std.stdio;
- struct SrcGrabber {
- const(string) PhobosUrl = "https://github.com/D-Programming-Language/phobos.git";
- const(string) DRuntimeUrl = "https://github.com/D-Programming-Language/druntime.git";
- const(string) DmdUrl = "https://github.com/D-Programming-Language/dmd.git";
- const(string) ToolsUrl = "https://github.com/D-Programming-Language/tools.git";
- // custom <dstruct src_grabber public_section>
- @disable this();
- this(string targetPath,
- string phobosUrl = PhobosUrl,
- string dRuntimeUrl = DRuntimeUrl,
- string dmdUrl = DmdUrl,
- string toolsUrl = ToolsUrl) {
- _targetPath = targetPath;
- _phobosUrl = phobosUrl;
- _dRuntimeUrl = dRuntimeUrl;
- _dmdUrl = dmdUrl;
- _toolsUrl = toolsUrl;
- }
- void grab() {
- bool firstTime = !exists(_targetPath);
- if(firstTime) {
- mkdirRecurse(_targetPath);
- }
- cd(_targetPath);
- string[] all = [_phobosUrl, _dRuntimeUrl, _dmdUrl, _toolsUrl];
- foreach(repository; all) {
- auto folder = baseName(stripExtension(repository));
- if(firstTime || !exists(folder)) {
- runCommand("git clone "~repository);
- } else {
- cd(folder);
- runCommand("git pull");
- cd(_targetPath);
- }
- }
- }
- // end <dstruct src_grabber public_section>
- private {
- /**
- Where to download the files
- */
- string _targetPath;
- string _phobosUrl;
- string _dRuntimeUrl;
- string _dmdUrl;
- string _toolsUrl;
- }
- }
- struct SrcBuilder {
- /**
- Discriminate on what to build
- */
- enum BuildType {
- DebugBuild,
- ReleaseBuild
- }
- // custom <dstruct src_builder public_section>
- @property bool isDebug() const {
- return _buildType == BuildType.DebugBuild;
- }
- this(string srcPath, BuildType buildType = BuildType.ReleaseBuild) {
- _buildType = buildType;
- _srcPath = buildPath(srcPath, (isDebug? "debug" : "release"));
- }
- void build(bool grabFirst = true) {
- if(grabFirst) {
- auto grabber = SrcGrabber(_srcPath);
- grabber.grab();
- }
- version(linux) {
- auto makefile = "posix.mak";
- }
- version(Windows) {
- auto makefile = "win32.mak";
- }
- auto debugFlag = (isDebug? " DEBUG=1 " : "");
- auto buildFlag = (isDebug? " BUILD=debug " : "");
- version(X86) {
- const auto cpu = " TARGET_CPU=X86 ";
- } else version(X86_64) {
- const auto cpu = " TARGET_CPU=X86 ";
- } else {
- static assert(0, "Put your cpu type here");
- }
- auto dryRun = "";
- cd(buildPath(_srcPath, "dmd", "src"));
- runCommand(text("make ", dryRun, " -f ", makefile, cpu, " clean"));
- runCommand(text("make ", dryRun, " MODEL=64 ", debugFlag, cpu, "-f ", makefile));
- // TODO: druntime is not needed directly as phobos builds what is needed
- // After building dmd, adjust path to be sure to use the just built dmd
- // instead of current one
- cd(buildPath(_srcPath, "druntime"));
- runCommand(text("make ", dryRun, " -f ", makefile, cpu, " clean"));
- runCommand(text("make ", dryRun, " MODEL=64 ", debugFlag, cpu, " -f ", makefile));
- cd(buildPath(_srcPath, "phobos"));
- runCommand(text("make ", dryRun, " -f ", makefile, cpu, " clean"));
- runCommand(text("make ", dryRun, " MODEL=64 ", buildFlag, cpu, " -f ", makefile));
- static if(0) {
- cd(buildPath(_srcPath, "tools"));
- runCommand(text("make ", dryRun, " -f ", makefile, cpu, " clean"));
- runCommand(text("make ", dryRun, " MODEL=64 ", debugFlag, cpu, " -f ", makefile));
- }
- }
- // end <dstruct src_builder public_section>
- private {
- BuildType _buildType;
- /**
- Where to find the source to build
- */
- string _srcPath;
- }
- }
- // custom <dmodule dsystem public_section>
- void log(string msg) {
- writeln(msg);
- stdout.flush();
- }
- void runCommand(string command) {
- log(text("Running: ", command));
- system(command);
- }
- void cd(string path) {
- log(text("cd to ", path));
- chdir(path);
- }
- // end <dmodule dsystem public_section>
- unittest {
- // custom <dmodule dsystem unittest>
- auto home = environment.get("HOME");
- auto targetPath = buildPath(home, "stage", "d_master");
- static if(1) {
- auto releaseBuilder = SrcBuilder(targetPath, SrcBuilder.BuildType.ReleaseBuild);
- releaseBuilder.build(false);
- }
- static if(0) {
- auto debugBuilder = SrcBuilder(targetPath, SrcBuilder.BuildType.DebugBuild);
- debugBuilder.build(false);
- }
- // end <dmodule dsystem unittest>
- }
Add Comment
Please, Sign In to add comment