Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Enabling running scripts per configuration per framework
Browse files Browse the repository at this point in the history
Required to fix #887
  • Loading branch information
moozzyk committed Sep 9, 2015
1 parent c9adfd8 commit 3ee1b0d
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 133 deletions.
262 changes: 129 additions & 133 deletions src/Microsoft.Dnx.Tooling/Building/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using Microsoft.Dnx.Compilation;
using Microsoft.Dnx.Compilation.Caching;
using Microsoft.Dnx.Compilation.FileSystem;
using Microsoft.Dnx.Runtime;
using Microsoft.Dnx.Runtime.Compilation;
using Microsoft.Dnx.Tooling.SourceControl;
using Microsoft.Dnx.Tooling.Utils;
using Microsoft.Framework.FileSystemGlobbing;
Expand Down Expand Up @@ -127,192 +126,189 @@ private bool BuildInternal(string projectPath)
return false;
}

if (_buildOptions.GeneratePackages &&
!ScriptExecutor.Execute(_currentProject, "prepack", GetScriptVariable))
var success = true;

var allDiagnostics = new List<DiagnosticMessage>();

// Build all specified configurations
foreach (var configuration in configurations)
{
LogError(ScriptExecutor.ErrorMessage);
return false;
success &= BuildConfiguration(baseOutputPath, frameworks, allDiagnostics, configuration);
}

if (!ScriptExecutor.Execute(_currentProject, "prebuild", GetScriptVariable))
sw.Stop();

if (projectDiagnostics.Any())
{
LogError(ScriptExecutor.ErrorMessage);
return false;
}
// Add a new line to separate the project diagnostics information from compilation diagnostics
_buildOptions.Reports.Information.WriteLine();

var success = true;
projectDiagnostics.ForEach(d => LogWarning(d.FormattedMessage));
}

var allDiagnostics = new List<DiagnosticMessage>();
allDiagnostics.AddRange(projectDiagnostics);
WriteSummary(allDiagnostics);

_buildOptions.Reports.Information.WriteLine("Time elapsed {0}", sw.Elapsed);
return success;
}

private bool BuildConfiguration(string baseOutputPath, IEnumerable<FrameworkName> frameworks, List<DiagnosticMessage> allDiagnostics, string configuration)
{
PackageBuilder packageBuilder = null;
PackageBuilder symbolPackageBuilder = null;
InstallBuilder installBuilder = null;
SourceBuilder sourceBuilder = null;

// Build all specified configurations
foreach (var configuration in configurations)
if (_buildOptions.GeneratePackages)
{
if (_buildOptions.GeneratePackages)
if(!ScriptExecutor.Execute(_currentProject, "prepack", GetScriptVariable))
{
// Create a new builder per configuration
packageBuilder = new PackageBuilder();
symbolPackageBuilder = new PackageBuilder();
InitializeBuilder(_currentProject, packageBuilder);
InitializeBuilder(_currentProject, symbolPackageBuilder);
installBuilder = new InstallBuilder(_currentProject, packageBuilder, _buildOptions.Reports);
sourceBuilder = new SourceBuilder(_currentProject, packageBuilder, _buildOptions.Reports);
LogError(ScriptExecutor.ErrorMessage);
return false;
}

var configurationSuccess = true;
// Create a new builder per configuration
packageBuilder = new PackageBuilder();
symbolPackageBuilder = new PackageBuilder();
InitializeBuilder(_currentProject, packageBuilder);
InitializeBuilder(_currentProject, symbolPackageBuilder);
installBuilder = new InstallBuilder(_currentProject, packageBuilder, _buildOptions.Reports);
sourceBuilder = new SourceBuilder(_currentProject, packageBuilder, _buildOptions.Reports);
}

var outputPath = Path.Combine(baseOutputPath, configuration);
var success = true;

var outputPath = Path.Combine(baseOutputPath, configuration);

// Build all target frameworks a project supports
foreach (var targetFramework in frameworks)
{
_buildOptions.Reports.Information.WriteLine();
_buildOptions.Reports.Information.WriteLine("Building {0} for {1}",
_currentProject.Name, targetFramework.ToString().Yellow().Bold());

// Build all target frameworks a project supports
foreach (var targetFramework in frameworks)
if (!ScriptExecutor.Execute(_currentProject, "prebuild", GetScriptVariable))
{
_buildOptions.Reports.Information.WriteLine();
_buildOptions.Reports.Information.WriteLine("Building {0} for {1}",
_currentProject.Name, targetFramework.ToString().Yellow().Bold());
LogError(ScriptExecutor.ErrorMessage);
success = false;
continue;
}

var diagnostics = new List<DiagnosticMessage>();
var diagnostics = new List<DiagnosticMessage>();
var context = new BuildContext(_compilationEngine,
_currentProject,
targetFramework,
configuration,
outputPath);

var context = new BuildContext(_compilationEngine,
_currentProject,
targetFramework,
configuration,
outputPath);
context.Initialize(_buildOptions.Reports.Quiet);

context.Initialize(_buildOptions.Reports.Quiet);
success &= context.Build(diagnostics);

if (context.Build(diagnostics))
if (success)
{
if (_buildOptions.GeneratePackages)
{
if (_buildOptions.GeneratePackages)
{
context.PopulateDependencies(packageBuilder);
context.AddLibs(packageBuilder, "*.dll");
context.AddLibs(packageBuilder, "*.xml");
context.PopulateDependencies(packageBuilder);
context.AddLibs(packageBuilder, "*.dll");
context.AddLibs(packageBuilder, "*.xml");

context.PopulateDependencies(symbolPackageBuilder);
context.AddLibs(symbolPackageBuilder, "*.*");
context.PopulateDependencies(symbolPackageBuilder);
context.AddLibs(symbolPackageBuilder, "*.*");

context.AddLibs(packageBuilder, "*.resources.dll", recursiveSearch: true);
}
context.AddLibs(packageBuilder, "*.resources.dll", recursiveSearch: true);
}
else

if (!ScriptExecutor.Execute(_currentProject, "postbuild", GetScriptVariable))
{
configurationSuccess = false;
LogError(ScriptExecutor.ErrorMessage);
success = false;
}
}

allDiagnostics.AddRange(diagnostics);
allDiagnostics.AddRange(diagnostics);

WriteDiagnostics(diagnostics);
}
WriteDiagnostics(diagnostics);
}

success = success && configurationSuccess;
if (_buildOptions.GeneratePackages)
{
success = success &&
// Generates the application package only if this is an application packages
installBuilder.Build(outputPath) &&
sourceBuilder.Build(outputPath);

if (_buildOptions.GeneratePackages)
if (success)
{
// Create a package per configuration
string nupkg = GetPackagePath(_currentProject, outputPath);
string symbolsNupkg = GetPackagePath(_currentProject, outputPath, symbols: true);
var nupkg = GetPackagePath(_currentProject, outputPath);
var symbolsNupkg = GetPackagePath(_currentProject, outputPath, symbols: true);

if (configurationSuccess)
{
// Generates the application package only if this is an application packages
configurationSuccess = installBuilder.Build(outputPath);
success = success && configurationSuccess;
}
success &= GeneratePackage(success, allDiagnostics, packageBuilder, symbolPackageBuilder, nupkg, symbolsNupkg);
}

if (configurationSuccess)
if (success)
{
if (!ScriptExecutor.Execute(_currentProject, "postpack", GetScriptVariable))
{
configurationSuccess = sourceBuilder.Build(outputPath);
success = success && configurationSuccess;
LogError(ScriptExecutor.ErrorMessage);
return false;
}
}
}

if (configurationSuccess)
{
var packDiagnostics = new List<DiagnosticMessage>();
foreach (var sharedFile in _currentProject.Files.SharedFiles)
{
var file = new PhysicalPackageFile();
file.SourcePath = sharedFile;
file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile));
packageBuilder.Files.Add(file);
}
return success;
}

var root = _currentProject.ProjectDirectory;
private bool GeneratePackage(bool success, List<DiagnosticMessage> allDiagnostics, PackageBuilder packageBuilder, PackageBuilder symbolPackageBuilder, string nupkg, string symbolsNupkg)
{
var packDiagnostics = new List<DiagnosticMessage>();
foreach (var sharedFile in _currentProject.Files.SharedFiles)
{
var file = new PhysicalPackageFile();
file.SourcePath = sharedFile;
file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile));
packageBuilder.Files.Add(file);
}

if (_currentProject.Files.PackInclude != null && _currentProject.Files.PackInclude.Any())
{
AddPackageFiles(_currentProject.ProjectDirectory, _currentProject.Files.PackInclude, packageBuilder, packDiagnostics);
}
success &= !packDiagnostics.HasErrors();
allDiagnostics.AddRange(packDiagnostics);
var root = _currentProject.ProjectDirectory;

foreach (var path in _currentProject.Files.SourceFiles)
{
var srcFile = new PhysicalPackageFile();
srcFile.SourcePath = path;
srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path));
symbolPackageBuilder.Files.Add(srcFile);
}

// Write the packages as long as we're still in a success state.
if (success)
{
using (var fs = File.Create(nupkg))
{
packageBuilder.Save(fs);
_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", _currentProject.Name, Path.GetFullPath(nupkg));
}

if (symbolPackageBuilder.Files.Any())
{
using (var fs = File.Create(symbolsNupkg))
{
symbolPackageBuilder.Save(fs);
_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", _currentProject.Name, Path.GetFullPath(symbolsNupkg));
}
}
}

WriteDiagnostics(packDiagnostics);
}
}
if (_currentProject.Files.PackInclude != null && _currentProject.Files.PackInclude.Any())
{
AddPackageFiles(_currentProject.ProjectDirectory, _currentProject.Files.PackInclude, packageBuilder, packDiagnostics);
}
success &= !packDiagnostics.HasErrors();
allDiagnostics.AddRange(packDiagnostics);

// Run post-build steps
foreach (var path in _currentProject.Files.SourceFiles)
{
var srcFile = new PhysicalPackageFile();
srcFile.SourcePath = path;
srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path));
symbolPackageBuilder.Files.Add(srcFile);
}

// Write the packages as long as we're still in a success state.
if (success)
{
if (!ScriptExecutor.Execute(_currentProject, "postbuild", GetScriptVariable))
using (var fs = File.Create(nupkg))
{
LogError(ScriptExecutor.ErrorMessage);
success = false;
packageBuilder.Save(fs);
_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", _currentProject.Name, Path.GetFullPath(nupkg));
}

if (_buildOptions.GeneratePackages &&
!ScriptExecutor.Execute(_currentProject, "postpack", GetScriptVariable))
if (symbolPackageBuilder.Files.Any())
{
LogError(ScriptExecutor.ErrorMessage);
success = false;
using (var fs = File.Create(symbolsNupkg))
{
symbolPackageBuilder.Save(fs);
_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", _currentProject.Name, Path.GetFullPath(symbolsNupkg));
}
}
}

sw.Stop();

if (projectDiagnostics.Any())
{
// Add a new line to separate the project diagnostics information from compilation diagnostics
_buildOptions.Reports.Information.WriteLine();

projectDiagnostics.ForEach(d => LogWarning(d.FormattedMessage));
}

allDiagnostics.AddRange(projectDiagnostics);
WriteSummary(allDiagnostics);

_buildOptions.Reports.Information.WriteLine("Time elapsed {0}", sw.Elapsed);
WriteDiagnostics(packDiagnostics);
return success;
}

Expand Down
Loading

0 comments on commit 3ee1b0d

Please sign in to comment.