Last active
October 23, 2015 16:26
-
-
Save SjB/431c5469894898c7681c to your computer and use it in GitHub Desktop.
sample build cake file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2015 Sagacity Solutions Inc. All right reserved. | |
var project = "ProjectName"; | |
var target = Argument("target", "Default"); | |
var configuration = Argument("configuration", "Release"); | |
var platform = Argument("platform", ""); | |
var prefix = Argument("prefix", "/" + project); | |
var destdir = EnvironmentVariable("DESTDIR"); | |
destdir = Argument("destdir", destdir); | |
if (null == destdir) { | |
destdir = "App"; | |
} | |
var installdir = MakeAbsolute(Directory(destdir + prefix)); | |
var toolsdir = Directory("tools"); | |
var protobuild = toolsdir + File("Protobuild.exe"); | |
var protobuildUrl = "https://github.com/SjB/Protobuild/blob/master/Protobuild.exe?raw=true"; | |
var primaryProject = "Loundness" + "/**/" + configuration + "/Loundness.exe"; | |
Func<IEnumerable<string>, int> Protobuild = delegate(IEnumerable<string> arguments) { | |
var processArgs = new ProcessArgumentBuilder(); | |
FilePath filename; | |
if (IsRunningOnUnix()) { | |
processArgs.Append(protobuild.ToString()); | |
filename = File("mono"); | |
} else { | |
filename = protobuild; | |
} | |
foreach (var arg in arguments) | |
processArgs.Append(arg); | |
return StartProcess(filename, new ProcessSettings { Arguments = processArgs}); | |
}; | |
Func<string, FilePath> FindFile = delegate(string glob) { | |
var files = GetFiles(glob); | |
foreach (var file in files) | |
return file; | |
Error("Can't find any file with glob {0}", glob); | |
return File(""); | |
}; | |
Func<string, bool> GlobFileExists = delegate(string glob) { | |
var files = GetFiles(glob); | |
foreach (var file in files) | |
return true; | |
return false; | |
}; | |
Task("fetch-protobuild") | |
.WithCriteria(!FileExists(protobuild)) | |
.Does(() => | |
{ | |
DownloadFile(protobuildUrl, protobuild); | |
}); | |
Task("Configure") | |
.IsDependentOn("fetch-protobuild") | |
.WithCriteria(!GlobFileExists(project + ".*.sln")) | |
.Does(() => | |
{ | |
if (0 != Protobuild(new string[]{"-generate"})) | |
Error("Couldn't generate solution file."); | |
var sln = FindFile(project + ".*.sln"); | |
NuGetRestore(sln); | |
// need to regenerate solution so that the dependent dll | |
// can be referenced | |
if (0 != Protobuild(new string[]{"-generate"})) | |
Error("Couldn't generate solution file."); | |
}); | |
Task("Clean") | |
.IsDependentOn("fetch-protobuild") | |
.Does(() => | |
{ | |
Protobuild(new string[]{"-clean"}); | |
var binDirs = GetDirectories("./**/bin"); | |
DeleteDirectories(binDirs, true); | |
var objDirs = GetDirectories("./**/obj"); | |
DeleteDirectories(objDirs, true); | |
}); | |
Task("Maintainer-Clean") | |
.IsDependentOn("Clean") | |
.Does(() => | |
{ | |
var dirs = new DirectoryPath[]{ "packages", toolsdir }; | |
foreach (var dir in dirs) { | |
if (DirectoryExists(dir)) | |
DeleteDirectory(dir, true); | |
} | |
var files = GetFiles("*.speccache"); | |
foreach (var file in files) { | |
if (FileExists(file)) | |
DeleteFile(file); | |
} | |
}); | |
Task("Build") | |
.IsDependentOn("Configure") | |
.Does(() => | |
{ | |
var sln = FindFile(project + ".*.sln"); | |
DotNetBuild(sln, settings => { | |
settings.Configuration = configuration; | |
}); | |
}); | |
Task("Package") | |
.IsDependentOn("Build") | |
.Does(() => | |
{ | |
var exe = FindFile(primaryProject); | |
Information(exe.ToString()); | |
Information(installdir.ToString()); | |
CopyDirectory(exe.GetDirectory(), installdir); | |
}); | |
Task("Default") | |
.IsDependentOn("Build"); | |
RunTarget(target); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment