392 lines
13 KiB
Plaintext
392 lines
13 KiB
Plaintext
use assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
|
|
use namespace="System"
|
|
use namespace="System.Globalization"
|
|
use namespace="System.IO"
|
|
use namespace="System.Linq"
|
|
use import="BuildEnv"
|
|
use import="Environment"
|
|
use import="Files"
|
|
use import="Json"
|
|
use-teamcity
|
|
|
|
default BASE_DIR='${Directory.GetCurrentDirectory()}'
|
|
default TARGET_DIR='${Path.Combine(BASE_DIR, "artifacts")}'
|
|
default BUILD_DIR='${Path.Combine(TARGET_DIR, "build")}'
|
|
default TEST_DIR='${Path.Combine(TARGET_DIR, "test")}'
|
|
default Configuration='${E("Configuration")}'
|
|
default PACKAGELIST_JSON_FILENAME = 'NuGetPackageVerifier.json'
|
|
default DNX_TOOLS_FEED = 'https://www.myget.org/F/dnxtools/api/v3/index.json'
|
|
default NUGET_FEED = 'https://api.nuget.org/v3/index.json'
|
|
|
|
@{
|
|
if (string.IsNullOrEmpty(E("DOTNET_BUILD_VERSION")))
|
|
{
|
|
E("DOTNET_BUILD_VERSION", BuildNumber);
|
|
}
|
|
if (string.IsNullOrEmpty(E("DOTNET_AUTHOR")))
|
|
{
|
|
E("DOTNET_AUTHOR", AUTHORS);
|
|
}
|
|
if (string.IsNullOrEmpty(E("DOTNET_ASSEMBLY_FILE_VERSION")))
|
|
{
|
|
E("DOTNET_ASSEMBLY_FILE_VERSION", CreateDayBasedVersionNumber());
|
|
}
|
|
if (string.IsNullOrEmpty(Configuration))
|
|
{
|
|
Configuration = "Debug";
|
|
E("Configuration", Configuration);
|
|
}
|
|
}
|
|
|
|
#restore-npm-modules
|
|
-// Find all dirs that contain a package.json file
|
|
var npmDirs = '${GetDirectoriesContaining(Directory.GetCurrentDirectory(), "package.json")}'
|
|
npm npmCommand='install ${E("KOREBUILD_NPM_INSTALL_OPTIONS")}' each='var npmDir in npmDirs'
|
|
|
|
#restore-bower-components
|
|
-// Find all dirs that contain a bower.json file
|
|
var bowerDirs = '${GetDirectoriesContaining(Directory.GetCurrentDirectory(), "bower.json")}'
|
|
bower each='var bowerDir in bowerDirs' bowerCommand='install ${E("KOREBUILD_BOWER_INSTALL_OPTIONS")}'
|
|
|
|
#run-grunt .restore-npm-modules .restore-bower-components target='initialize'
|
|
-// Find all dirs that contain a gruntfile.js file
|
|
var gruntDirs = '${GetDirectoriesContaining(Directory.GetCurrentDirectory(), "gruntfile.js")}'
|
|
grunt each='var gruntDir in gruntDirs'
|
|
|
|
#clean-bin-folder
|
|
rimraf rimrafDir='bin' if='Directory.Exists("bin")'
|
|
|
|
#clean-npm-modules
|
|
-// Find all dirs that contain a package.json file
|
|
var npmDirs = '${
|
|
GetDirectoriesContaining(Directory.GetCurrentDirectory(), "package.json")
|
|
.Select(directory => Path.Combine(directory, "node_modules"))
|
|
.Where(directory => Directory.Exists(directory))
|
|
}'
|
|
rimraf each='var rimrafDir in npmDirs'
|
|
|
|
-// Target order is important because clean-npm-modules may (re)create bin folder.
|
|
#deep-clean .clean-npm-modules .clean-bin-folder description='Clean folders that may cause problems for `git clean`.'
|
|
|
|
#repo-initialize target='initialize'
|
|
use-volatile-feed
|
|
dotnet-restore if='!NoRestore'
|
|
|
|
#target-dir-clean target='clean'
|
|
@{
|
|
if (Directory.Exists(TARGET_DIR))
|
|
{
|
|
var directory = new DirectoryInfo(TARGET_DIR);
|
|
directory.Attributes &= ~FileAttributes.ReadOnly;
|
|
|
|
foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories))
|
|
{
|
|
info.Attributes &= ~FileAttributes.ReadOnly;
|
|
}
|
|
|
|
directory.Delete(true);
|
|
}
|
|
}
|
|
|
|
#build-clean if='Directory.Exists("src")'
|
|
k-clean each='var projectFile in Files.Include("src/*/project.json")'
|
|
|
|
#ci-deep-clean .deep-clean target='clean' if='IsTeamCity'
|
|
|
|
#build-compile target='compile' if='Directory.Exists("src")'
|
|
@{
|
|
var projectFiles = Files.Include("src/*/project.json").ToList();
|
|
projectFiles.ForEach(projectFile => DotnetPack(projectFile, BUILD_DIR, Configuration));
|
|
|
|
foreach (var nupkg in Files.Include(Path.Combine(BUILD_DIR, "*/" + Configuration + "/*.nupkg")))
|
|
{
|
|
File.Copy(nupkg, Path.Combine(BUILD_DIR, Path.GetFileName(nupkg)), true);
|
|
}
|
|
}
|
|
|
|
#build-test target='compile' if='Directory.Exists("test") && !BuildSrcOnly'
|
|
@{
|
|
var projectFiles = Files.Include("test/*/project.json").ToList();
|
|
projectFiles.ForEach(projectFile => DotnetBuild(projectFile, Configuration));
|
|
}
|
|
|
|
#build-samples target='compile' if='Directory.Exists("samples") && !BuildSrcOnly'
|
|
@{
|
|
var projectFiles = Files.Include("samples/*/project.json").ToList();
|
|
projectFiles.ForEach(projectFile => DotnetBuild(projectFile, Configuration));
|
|
}
|
|
|
|
#native-compile target='compile' if='!IsLinux && Directory.Exists(Path.Combine(BASE_DIR, "src"))'
|
|
var programFilesX86 = '${Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)}'
|
|
var nativeProjects ='${Files.Include(Path.Combine(BASE_DIR, "src", "**", "*.vcxproj"))}'
|
|
|
|
@{
|
|
if (nativeProjects.Any())
|
|
{
|
|
var msbuildVersions = new[] { "14.0", "12.0"};
|
|
|
|
for (var i = 0; i < msbuildVersions.Length; i++)
|
|
{
|
|
var msbuildPath = Path.Combine(programFilesX86, "MSBuild", msbuildVersions[i], "Bin", "MSBuild.exe");
|
|
if (File.Exists(msbuildPath))
|
|
{
|
|
var commonParameters =
|
|
" /p:Configuration=" + Configuration +
|
|
" /p:ProductVersion=1.0.0" +
|
|
" /p:FileRevision=" + E("DNX_ASSEMBLY_FILE_VERSION") +
|
|
" /p:BuildVersion=" + E("DNX_BUILD_VERSION");
|
|
|
|
foreach (var project in nativeProjects)
|
|
{
|
|
Exec(msbuildPath, project + " /p:Platform=Win32" + commonParameters);
|
|
Exec(msbuildPath, project + " /p:Platform=x64" + commonParameters);
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
if (i == msbuildVersions.Length - 1)
|
|
{
|
|
Log.Warn("msbuild version 14 or 12 not found. Please ensure you have the VS 2015 or VS 2013 C++ SDK installed.");
|
|
Environment.Exit(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
copy sourceDir='${Path.GetDirectoryName(project)}' include='bin/**/' outputDir='${Path.Combine(BUILD_DIR, Path.GetFileNameWithoutExtension(project))}' overwrite='${true}' each='var project in nativeProjects'
|
|
|
|
#nuget-verify target='package' if='File.Exists(PACKAGELIST_JSON_FILENAME) && ShouldVerifyNupkgs' description='Verify if all the packages are generated properly'
|
|
var commandsDirectory = '${Path.Combine(BASE_DIR, "commands")}'
|
|
exec program='.build/NuGet.exe' commandline='install -ExcludeVersion -pre NuGetPackageVerifier -Source ${DNX_TOOLS_FEED} -out ${commandsDirectory}'
|
|
exec program='${Path.Combine(commandsDirectory, "NuGetPackageVerifier", "NuGetPackageVerifier.exe")}' commandline='"${BUILD_DIR}" "${Path.Combine(BASE_DIR, PACKAGELIST_JSON_FILENAME)}"'
|
|
@{
|
|
if (Directory.Exists(commandsDirectory))
|
|
{
|
|
Directory.Delete(commandsDirectory, recursive: true);
|
|
}
|
|
}
|
|
|
|
#nuget-install target='install' description='Install NuGet packages to local repo'
|
|
-if (Directory.Exists("src")) {
|
|
nuget-packages-add sourcePackagesDir='${BUILD_DIR}' targetPackagesDir='${E("PACKAGES_PUBLISH_DIR")}'
|
|
nuget-resilient-publish sourcePackagesDir='${BUILD_DIR}' nugetFeed='${E("NUGET_PUBLISH_FEED")}' if='!string.IsNullOrEmpty(E("NUGET_PUBLISH_FEED"))'
|
|
-}
|
|
|
|
#xunit-test target='test' if='Directory.Exists("test")'
|
|
@{
|
|
var projectFiles = Files.Include("test/*/project.json");
|
|
foreach (var projectFile in projectFiles)
|
|
{
|
|
var projectText = File.ReadAllText(projectFile);
|
|
var project = (JsonObject)Json.Deserialize(projectText);
|
|
var configs = project.ValueAsJsonObject("frameworks");
|
|
var targetFrameworks = configs == null ? new string[0] : configs.Keys;
|
|
|
|
var net45TFM = targetFrameworks.FirstOrDefault(t => t.StartsWith("net45", StringComparison.OrdinalIgnoreCase));
|
|
var dnx451TFM = targetFrameworks.FirstOrDefault(t => t.Equals("dnx451", StringComparison.OrdinalIgnoreCase));
|
|
var dnxCore50TFM = targetFrameworks.FirstOrDefault(t => t.Equals("dnxcore50", StringComparison.OrdinalIgnoreCase));
|
|
if (dnxCore50TFM != null && project.Keys.Contains("testRunner"))
|
|
{
|
|
DotnetTest(projectFile, Configuration);
|
|
}
|
|
|
|
if (project.Keys.Contains("testRunner"))
|
|
{
|
|
if (net45TFM != null)
|
|
{
|
|
XunitTest(projectFile, net45TFM, Configuration);
|
|
}
|
|
else if (dnx451TFM != null)
|
|
{
|
|
XunitTest(projectFile, dnx451TFM, Configuration);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#make-roslyn-fast
|
|
ngen-roslyn
|
|
|
|
#resx
|
|
@{
|
|
var cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures | CultureTypes.InstalledWin32Cultures | CultureTypes.SpecificCultures);
|
|
foreach (var file in Directory.EnumerateFiles(BASE_DIR, "*.resx", SearchOption.AllDirectories))
|
|
{
|
|
var splitFileName = Path.GetFileNameWithoutExtension(file).Split(new string[] { "." }, StringSplitOptions.None);
|
|
|
|
if (splitFileName.Length > 1)
|
|
{
|
|
var localeString = splitFileName.Last();
|
|
if (!cultures.Any(c => localeString.Equals(c.Name)))
|
|
{
|
|
UpdateResx(file);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UpdateResx(file);
|
|
}
|
|
}
|
|
}
|
|
|
|
#--no-restore
|
|
@{ NoRestore = true; }
|
|
|
|
#--quiet
|
|
@{
|
|
AddToE("KOREBUILD_DOTNET_RESTORE_OPTIONS", "--verbosity minimal");
|
|
AddToE("KOREBUILD_BOWER_INSTALL_OPTIONS", "--quiet");
|
|
AddToE("KOREBUILD_NPM_INSTALL_OPTIONS", "--quiet");
|
|
Quiet = true;
|
|
}
|
|
|
|
#--parallel
|
|
@{
|
|
Log.Warn("The --parallel flag is no longer supported. It will be ignored.");
|
|
}
|
|
|
|
#--test-dnxcore
|
|
@{
|
|
Log.Warn("The --test-dnxcore flag is no longer supported. It will be ignored.");
|
|
}
|
|
|
|
functions @{
|
|
private static bool Quiet { get; set; }
|
|
private static bool NoRestore { get; set; }
|
|
|
|
string E(string key) { return Environment.GetEnvironmentVariable(key); }
|
|
void E(string key, string value) { Environment.SetEnvironmentVariable(key, value); }
|
|
void AddToE(string key, string append)
|
|
{
|
|
var original = E(key);
|
|
if (string.IsNullOrEmpty(original))
|
|
{
|
|
E(key, append);
|
|
}
|
|
else
|
|
{
|
|
E(key, original + " " + append);
|
|
}
|
|
}
|
|
|
|
IEnumerable<string> GetDirectoriesContaining(string path, string searchPattern)
|
|
{
|
|
var sep = Path.DirectorySeparatorChar;
|
|
// Don't include directories that are children of a node_modules or bower_components directory
|
|
return Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories)
|
|
.Where(p => p.IndexOf(sep + "node_modules" + sep) < 0 &&
|
|
p.IndexOf(sep + "bower_components" + sep) < 0 &&
|
|
p.IndexOf(sep + "wwwroot" + sep + "lib" + sep) < 0)
|
|
.Select(p => Path.GetDirectoryName(p))
|
|
.Distinct();
|
|
}
|
|
|
|
bool TestCommand(string program, string commandline)
|
|
{
|
|
// Tests whether a given command succeeds at the command line.
|
|
// Useful for testing whether a given command is installed and on the path, e.g. node
|
|
ProcessStartInfo processStartInfo;
|
|
|
|
if(!IsLinux)
|
|
{
|
|
processStartInfo = new ProcessStartInfo {
|
|
UseShellExecute = false,
|
|
FileName = "cmd",
|
|
Arguments = "/C " + program + " " + commandline,
|
|
};
|
|
} else
|
|
{
|
|
processStartInfo = new ProcessStartInfo {
|
|
UseShellExecute = false,
|
|
FileName = program,
|
|
Arguments = commandline,
|
|
};
|
|
}
|
|
try
|
|
{
|
|
Log.Info(string.Format("Testing for command: {0} {1}", program, commandline));
|
|
var process = Process.Start(processStartInfo);
|
|
process.WaitForExit();
|
|
if (process.ExitCode == 0)
|
|
{
|
|
Log.Info(" command found (0 exit code)");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Log.Warn(" command not found (non-0 exit code)");
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Warn(" command exception: " + ex.ToString());
|
|
Log.Warn(" command not found");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool ShouldVerifyNupkgs
|
|
{
|
|
get { return E("KOREBUILD_VERIFY_NUPKGS") == "1"; }
|
|
}
|
|
|
|
bool BuildSrcOnly
|
|
{
|
|
get { return E("KOREBUILD_BUILD_SRC_ONLY") == "1"; }
|
|
}
|
|
}
|
|
|
|
macro name='Exec' program='string' commandline='string'
|
|
exec
|
|
|
|
macro name='Exec' program='string' commandline='string' workingdir='string'
|
|
exec
|
|
|
|
macro name='ExecClr' program='string' commandline='string'
|
|
exec-clr
|
|
|
|
macro name='ExecClr' program='string' commandline='string' workingdir='string'
|
|
exec-clr
|
|
|
|
macro name="DeleteFolder" delete='string'
|
|
directory
|
|
|
|
macro name="Copy" sourceDir='string' outputDir='string' include='string' overwrite='bool'
|
|
copy
|
|
|
|
macro name="CopyFolder" sourceDir='string' outputDir='string' overwrite='bool'
|
|
copy
|
|
|
|
macro name='Dotnet' command='string'
|
|
dotnet
|
|
|
|
macro name='Dotnet' command='string' dotnetDir='string'
|
|
dotnet
|
|
|
|
macro name="DotnetBuild" projectFile='string' configuration='string'
|
|
dotnet-build
|
|
|
|
macro name="DotnetPack" projectFile='string' dotnetPackOutputDir='string' configuration='string'
|
|
dotnet-pack
|
|
|
|
macro name="DotnetPublish" projectFile='string' outputFolder='string' framework='string' configuration='string'
|
|
dotnet-publish
|
|
|
|
macro name="DotnetTest" projectFile='string' configuration='string'
|
|
dotnet-test
|
|
|
|
macro name="XunitTest" projectFile='string' framework='string' configuration='string'
|
|
xunit-test
|
|
|
|
macro name='Dnx' command='string' dnxDir='string' dnvmUse='string'
|
|
dnx
|
|
|
|
macro name="DnxTest" projectFile='string' framework='string' configuration='string'
|
|
dnx-test
|
|
|
|
macro name="UpdateResx" resxFile='string'
|
|
k-generate-resx
|