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

Rename kpm commands #1037

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 58 additions & 37 deletions src/Microsoft.Framework.PackageManager/Building/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public bool Build()
frameworks = new[] { _applicationEnvironment.RuntimeFramework };
}

if (_buildOptions.GeneratePackages &&
!ScriptExecutor.Execute(project, "prepack", GetScriptVariable))
{
WriteError(ScriptExecutor.ErrorMessage);
return false;
}

if (!ScriptExecutor.Execute(project, "prebuild", GetScriptVariable))
{
Expand All @@ -85,15 +91,20 @@ public bool Build()
var cacheContextAccessor = new CacheContextAccessor();
var cache = new Cache(cacheContextAccessor);

PackageBuilder packageBuilder = null;
PackageBuilder symbolPackageBuilder = null;

// Build all specified configurations
foreach (var configuration in configurations)
{
// Create a new builder per configuration
var packageBuilder = new PackageBuilder();
var symbolPackageBuilder = new PackageBuilder();

InitializeBuilder(project, packageBuilder);
InitializeBuilder(project, symbolPackageBuilder);
if (_buildOptions.GeneratePackages)
{
// Create a new builder per configuration
packageBuilder = new PackageBuilder();
symbolPackageBuilder = new PackageBuilder();
InitializeBuilder(project, packageBuilder);
InitializeBuilder(project, symbolPackageBuilder);
}

var configurationSuccess = true;

Expand All @@ -120,7 +131,7 @@ public bool Build()

context.Initialize(_buildOptions.Reports.Quiet);

if (context.Build(warnings, errors))
if (context.Build(warnings, errors) && _buildOptions.GeneratePackages)
{
context.PopulateDependencies(packageBuilder);
context.AddLibs(packageBuilder, "*.dll");
Expand All @@ -140,44 +151,47 @@ public bool Build()

success = success && configurationSuccess;

// Create a package per configuration
string nupkg = GetPackagePath(project, baseOutputPath);
string symbolsNupkg = GetPackagePath(project, baseOutputPath, symbols: true);

if (configurationSuccess)
if (_buildOptions.GeneratePackages)
{
foreach (var sharedFile in project.SharedFiles)
{
var file = new PhysicalPackageFile();
file.SourcePath = sharedFile;
file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile));
packageBuilder.Files.Add(file);
}

var root = project.ProjectDirectory;
// Create a package per configuration
string nupkg = GetPackagePath(project, baseOutputPath);
string symbolsNupkg = GetPackagePath(project, baseOutputPath, symbols: true);

foreach (var path in project.SourceFiles)
if (configurationSuccess)
{
var srcFile = new PhysicalPackageFile();
srcFile.SourcePath = path;
srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path));
symbolPackageBuilder.Files.Add(srcFile);
}
foreach (var sharedFile in project.SharedFiles)
{
var file = new PhysicalPackageFile();
file.SourcePath = sharedFile;
file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile));
packageBuilder.Files.Add(file);
}

using (var fs = File.Create(nupkg))
{
packageBuilder.Save(fs);
_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, nupkg);
}
var root = project.ProjectDirectory;

if (symbolPackageBuilder.Files.Any())
{
using (var fs = File.Create(symbolsNupkg))
foreach (var path in project.SourceFiles)
{
symbolPackageBuilder.Save(fs);
var srcFile = new PhysicalPackageFile();
srcFile.SourcePath = path;
srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path));
symbolPackageBuilder.Files.Add(srcFile);
}

_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, symbolsNupkg);
using (var fs = File.Create(nupkg))
{
packageBuilder.Save(fs);
_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, nupkg);
}

if (symbolPackageBuilder.Files.Any())
{
using (var fs = File.Create(symbolsNupkg))
{
symbolPackageBuilder.Save(fs);
}

_buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, symbolsNupkg);
}
}
}
}
Expand All @@ -188,6 +202,13 @@ public bool Build()
return false;
}

if (_buildOptions.GeneratePackages &&
!ScriptExecutor.Execute(project, "postpack", GetScriptVariable))
{
WriteError(ScriptExecutor.ErrorMessage);
return false;
}

sw.Stop();

WriteSummary(allWarnings, allErrors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class BuildOptions

public IList<string> TargetFrameworks { get;set; }

public bool GeneratePackages { get; set; }

public Reports Reports { get; set; }

public BuildOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
using System.Runtime.Versioning;
using Microsoft.Framework.Runtime;

namespace Microsoft.Framework.PackageManager.Packing
namespace Microsoft.Framework.PackageManager.Bundle
{
public class PackManager
public class BundleManager
{
private readonly IServiceProvider _hostServices;
private readonly PackOptions _options;
private readonly BundleOptions _options;

public PackManager(IServiceProvider hostServices, PackOptions options)
public BundleManager(IServiceProvider hostServices, BundleOptions options)
{
_hostServices = hostServices;
_options = options;
Expand All @@ -39,7 +39,7 @@ private static string Normalize(string projectDir)
return Path.GetFullPath(projectDir.TrimEnd(Path.DirectorySeparatorChar));
}

public bool Package()
public bool Bundle()
{
Runtime.Project project;
if (!Runtime.Project.TryGetProject(_options.ProjectDir, out project))
Expand Down Expand Up @@ -67,11 +67,11 @@ public bool Package()
return false;
}

if (string.Equals(_options.WwwRootOut, PackRoot.AppRootName, StringComparison.OrdinalIgnoreCase))
if (string.Equals(_options.WwwRootOut, BundleRoot.AppRootName, StringComparison.OrdinalIgnoreCase))
{
_options.Reports.Error.WriteLine(
"'{0}' is a reserved folder name. Please choose another name for the wwwroot-out folder.".Red(),
PackRoot.AppRootName);
BundleRoot.AppRootName);
return false;
}

Expand All @@ -83,7 +83,7 @@ public bool Package()

var frameworkContexts = new Dictionary<FrameworkName, DependencyContext>();

var root = new PackRoot(project, outputPath, _hostServices, _options.Reports)
var root = new BundleRoot(project, outputPath, _hostServices, _options.Reports)
{
Overwrite = _options.Overwrite,
Configuration = _options.Configuration,
Expand All @@ -101,7 +101,7 @@ public bool Package()
return false;
}

if (!ScriptExecutor.Execute(project, "prepack", getVariable))
if (!ScriptExecutor.Execute(project, "prebundle", getVariable))
{
_options.Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
return false;
Expand Down Expand Up @@ -163,7 +163,7 @@ public bool Package()
if (!project.GetTargetFrameworks().Any(x => x.FrameworkName == frameworkName))
{
_options.Reports.Error.WriteLine(
string.Format("'{0}' is not a target framework of the project being packed",
string.Format("'{0}' is not a target framework of the project being bundled",
frameworkName.ToString().Red().Bold()));
return false;
}
Expand All @@ -175,7 +175,7 @@ public bool Package()
}

// If there is no target framework filter specified with '--runtime',
// the packed output targets all frameworks specified in project.json
// the bundled output targets all frameworks specified in project.json
if (!_options.Runtimes.Any())
{
foreach (var frameworkInfo in project.GetTargetFrameworks())
Expand Down Expand Up @@ -214,7 +214,7 @@ public bool Package()
IList<DependencyContext> contexts;
if (!root.LibraryDependencyContexts.TryGetValue(libraryDescription.Identity, out contexts))
{
root.Packages.Add(new PackPackage(libraryDescription));
root.Packages.Add(new BundlePackage(libraryDescription));
contexts = new List<DependencyContext>();
root.LibraryDependencyContexts[libraryDescription.Identity] = contexts;
}
Expand All @@ -225,17 +225,17 @@ public bool Package()
{
if (!root.Projects.Any(p => p.Name == libraryDescription.Identity.Name))
{
var packProject = new PackProject(
var bundleProject = new BundleProject(
dependencyContext.ProjectReferenceDependencyProvider,
dependencyContext.ProjectResolver,
libraryDescription);

if (packProject.Name == project.Name)
if (bundleProject.Name == project.Name)
{
packProject.WwwRoot = _options.WwwRoot;
packProject.WwwRootOut = _options.WwwRootOut;
bundleProject.WwwRoot = _options.WwwRoot;
bundleProject.WwwRootOut = _options.WwwRootOut;
}
root.Projects.Add(packProject);
root.Projects.Add(bundleProject);
}
}
}
Expand All @@ -253,7 +253,7 @@ public bool Package()

root.Emit();

if (!ScriptExecutor.Execute(project, "postpack", getVariable))
if (!ScriptExecutor.Execute(project, "postbundle", getVariable))
{
_options.Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
return false;
Expand All @@ -271,7 +271,7 @@ public bool Package()
return !anyUnresolvedDependency;
}

bool TryAddRuntime(PackRoot root, FrameworkName frameworkName, string krePath)
bool TryAddRuntime(BundleRoot root, FrameworkName frameworkName, string krePath)
{
if (!Directory.Exists(krePath))
{
Expand All @@ -285,7 +285,7 @@ bool TryAddRuntime(PackRoot root, FrameworkName frameworkName, string krePath)
return false;
}

root.Runtimes.Add(new PackRuntime(root, frameworkName, kreNupkgPath));
root.Runtimes.Add(new BundleRuntime(root, frameworkName, kreNupkgPath));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using System.Linq;
using NuGet;

namespace Microsoft.Framework.PackageManager.Packing
namespace Microsoft.Framework.PackageManager.Bundle
{
public class PackOperations
public class BundleOperations
{
public void Delete(string folderPath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.Collections.Generic;
using System.Runtime.Versioning;

namespace Microsoft.Framework.PackageManager.Packing
namespace Microsoft.Framework.PackageManager.Bundle
{
public class PackOptions
public class BundleOptions
{
public string OutputDir { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
using Microsoft.Framework.Runtime;
using NuGet;

namespace Microsoft.Framework.PackageManager.Packing
namespace Microsoft.Framework.PackageManager.Bundle
{
public class PackPackage
public class BundlePackage
{
private readonly LibraryDescription _libraryDescription;

public PackPackage(LibraryDescription libraryDescription)
public BundlePackage(LibraryDescription libraryDescription)
{
_libraryDescription = libraryDescription;
}
Expand All @@ -21,7 +21,7 @@ public PackPackage(LibraryDescription libraryDescription)

public string TargetPath { get; private set; }

public void Emit(PackRoot root)
public void Emit(BundleRoot root)
{
root.Reports.Quiet.WriteLine("Using {0} dependency {1}", _libraryDescription.Type, Library);
foreach (var context in root.LibraryDependencyContexts[Library])
Expand All @@ -33,7 +33,7 @@ public void Emit(PackRoot root)
}
}

private void Emit(PackRoot root, IEnumerable<PackageAssembly> assemblies)
private void Emit(BundleRoot root, IEnumerable<PackageAssembly> assemblies)
{
var resolver = new DefaultPackagePathResolver(root.TargetPackagesPath);

Expand Down Expand Up @@ -68,7 +68,7 @@ private void Emit(PackRoot root, IEnumerable<PackageAssembly> assemblies)
}
}

private void CopyFolder(PackRoot root, string srcFolder, string targetFolder)
private void CopyFolder(BundleRoot root, string srcFolder, string targetFolder)
{
if (!Directory.Exists(srcFolder))
{
Expand All @@ -92,7 +92,7 @@ private void CopyFolder(PackRoot root, string srcFolder, string targetFolder)
root.Operations.Copy(srcFolder, targetFolder);
}

private void CopyFile(PackRoot root, string srcPath, string targetPath, bool overwrite)
private void CopyFile(BundleRoot root, string srcPath, string targetPath, bool overwrite)
{
var targetFolder = Path.GetDirectoryName(targetPath);
Directory.CreateDirectory(targetFolder);
Expand Down
Loading