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("DNX_BUILD_VERSION"))) { E("DNX_BUILD_VERSION", BuildNumber); } if (string.IsNullOrEmpty(E("DNX_AUTHOR"))) { E("DNX_AUTHOR", AUTHORS); } if (string.IsNullOrEmpty(E("DNX_ASSEMBLY_FILE_VERSION"))) { E("DNX_ASSEMBLY_FILE_VERSION", CreateDayBasedVersionNumber()); } if (string.IsNullOrEmpty(Configuration)) { Configuration = "Debug"; E("Configuration", Configuration); } Log.Info("Build v2: " + IsBuildV2); } #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' k-restore #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 target='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='!IsBuildV2 && Directory.Exists("src")' @{ var projectFiles = Files.Include("src/**/project.json").ToList(); if (ShouldRunInParallel) { Parallel.ForEach(projectFiles, projectFile => DnuPack(projectFile, BUILD_DIR, Configuration)); } else { projectFiles.ForEach(projectFile => DnuPack(projectFile, BUILD_DIR, Configuration)); } foreach (var nupkg in Files.Include(Path.Combine(BUILD_DIR, "*/*.nupkg"))) { File.Copy(nupkg, Path.Combine(BUILD_DIR, Path.GetFileName(nupkg)), true); } } #build-compile target='compile' if='IsBuildV2' @{ // If the src folder, build and create the packages if (Directory.Exists("src")) { // Handle projects 1 to 3 levels down from src/, avoiding path too long errors. DnuPack("src/*;src/*/*;src/*/*/*", BUILD_DIR, Configuration); foreach (var nupkg in Files.Include(Path.Combine(BUILD_DIR, "*/*.nupkg"))) { File.Copy(nupkg, Path.Combine(BUILD_DIR, Path.GetFileName(nupkg)), true); } } // For test and samples only check if they compile var projectsToBuild = new List(); if (Directory.Exists("test")) { // Handle projects 1 to 3 levels down from test/, avoiding path too long errors. projectsToBuild.Add("test/*"); projectsToBuild.Add("test/*/*"); projectsToBuild.Add("test/*/*/*"); } if (Directory.Exists("samples")) { // Handle projects 1 to 3 levels down from samples/, avoiding path too long errors. projectsToBuild.Add("samples/*"); projectsToBuild.Add("samples/*/*"); projectsToBuild.Add("samples/*/*/*"); } if (projectsToBuild.Any()) { DnuBuild( string.Join(";", projectsToBuild), 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' if='Directory.Exists("src")' description='Install NuGet packages to local repo' kpm-publish 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").Exclude("**/bin/*/app/project.json").ToList(); if (ShouldRunInParallel) { Parallel.ForEach(projectFiles, projectFile => DnxTest(projectFile, testParallel: true)); } else { projectFiles.ForEach(projectFile => DnxTest(projectFile, testParallel: false)); } } #build-samples target='test' if='!IsBuildV2 && Directory.Exists("samples")' @{ var projectFiles = Files.Include("samples/**/project.json").ToList(); if (ShouldRunInParallel) { Parallel.ForEach(projectFiles, projectFile => DnuBuild(projectFile, Configuration)); } else { projectFiles.ForEach(projectFile => DnuBuild(projectFile, 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); } } } #--quiet @{ AddToE("KOREBUILD_BOWER_INSTALL_OPTIONS", "--quiet"); AddToE("KOREBUILD_DNU_BUILD_OPTIONS", "--quiet"); AddToE("KOREBUILD_DNU_PACK_OPTIONS", "--quiet"); AddToE("KOREBUILD_DNU_RESTORE_OPTIONS", "--quiet"); AddToE("KOREBUILD_NPM_INSTALL_OPTIONS", "--quiet"); Quiet = true; } #--parallel @{ E("KOREBUILD_PARALLEL", "1"); } #--test-dnxcore @{ E("KOREBUILD_TEST_DNXCORE", "1"); } #stylecop if='Directory.Exists("src")' stylecop-setup stylecop-run each='var projectFile in Files.Include("src/**/project.json")' functions @{ private static bool Quiet { 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 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 ShouldRunInParallel { get { return !string.IsNullOrEmpty(E("KOREBUILD_PARALLEL")); } } bool ShouldVerifyNupkgs { get { return E("KOREBUILD_VERIFY_NUPKGS") == "1"; } } } macro name='Exec' program='string' commandline='string' exec macro name='Dnu' command='string' dnu macro name='Dnx' command='string' dnxDir='string' k macro name='Dnx' command='string' dnxDir='string' dnvmUse='string' k macro name="UpdateResx" resxFile='string' k-generate-resx macro name="DnxTest" projectFile='string' testParallel='bool' k-test macro name="DnuBuild" projectFile='string' configuration='string' kpm-build macro name="DnuPack" projectFile='string' kpmPackOutputDir='string' configuration='string' kpm-pack macro name="DeleteFolder" delete='string' directory macro name="CopyFolder" sourceDir='string' outputDir='string' overwrite='bool' copy