Fixed copying output assets to the publish directory

This commit is contained in:
David Fowler 2016-01-27 20:35:43 -08:00
parent d4a8fa24db
commit 6edac85dce
7 changed files with 128 additions and 101 deletions

View file

@ -24,16 +24,16 @@ namespace Microsoft.DotNet.Cli.Utils
private static CommandSpec ResolveFromPath(string commandName, IEnumerable<string> args, bool useComSpec = false)
{
var commandPath = Env.GetCommandPath(commandName);
return commandPath == null
? null
return commandPath == null
? null
: CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.Path, useComSpec);
}
private static CommandSpec ResolveFromAppBase(string commandName, IEnumerable<string> args, bool useComSpec = false)
{
var commandPath = Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, commandName);
return commandPath == null
? null
return commandPath == null
? null
: CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.BaseDirectory, useComSpec);
}
@ -50,7 +50,7 @@ namespace Microsoft.DotNet.Cli.Utils
var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args);
return new CommandSpec(commandName, escapedArgs, CommandResolutionStrategy.Path);
}
}
return null;
@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Cli.Utils
if (commandPackage == null) return null;
var depsPath = GetDepsPath(projectContext, Constants.DefaultConfiguration);
var depsPath = projectContext.GetOutputPathCalculator().GetDepsPath(Constants.DefaultConfiguration);
return ConfigureCommandFromPackage(commandName, args, commandPackage, projectContext, depsPath, useComSpec);
}
@ -90,7 +90,7 @@ namespace Microsoft.DotNet.Cli.Utils
private static PackageDescription GetCommandPackage(ProjectContext projectContext, string commandName)
{
return projectContext.LibraryManager.GetLibraries()
.Where(l => l.GetType() == typeof (PackageDescription))
.Where(l => l.GetType() == typeof(PackageDescription))
.Select(l => l as PackageDescription)
.FirstOrDefault(p => p.Library.Files
.Select(Path.GetFileName)
@ -201,21 +201,13 @@ namespace Microsoft.DotNet.Cli.Utils
var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args);
return new CommandSpec(fileName, escapedArgs, CommandResolutionStrategy.NugetPackage);
}
}
private static string GetDepsPath(ProjectContext context, string buildConfiguration)
{
return Path.Combine(context.GetOutputPathCalculator().GetOutputDirectoryPath(buildConfiguration),
context.ProjectFile.Name + FileNameSuffixes.Deps);
}
private static CommandSpec CreateCommandSpecPreferringExe(
string commandName,
IEnumerable<string> args,
string commandName,
IEnumerable<string> args,
string commandPath,
CommandResolutionStrategy resolutionStrategy,
CommandResolutionStrategy resolutionStrategy,
bool useComSpec = false)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
@ -226,7 +218,7 @@ namespace Microsoft.DotNet.Cli.Utils
// Use cmd if we can't find an exe
if (preferredCommandPath == null)
{
useComSpec = true;
useComSpec = true;
}
else
{
@ -246,8 +238,8 @@ namespace Microsoft.DotNet.Cli.Utils
}
private static CommandSpec CreateComSpecCommandSpec(
string command,
IEnumerable<string> args,
string command,
IEnumerable<string> args,
CommandResolutionStrategy resolutionStrategy)
{
// To prevent Command Not Found, comspec gets passed in as

View file

@ -32,16 +32,18 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
}));
}
internal static IEnumerable<LibraryAsset> RuntimeAssets(this LibraryExport export)
internal static IEnumerable<string> RuntimeAssets(this LibraryExport export)
{
return export.RuntimeAssemblies.Union(export.NativeLibraries);
return export.RuntimeAssemblies.Union(export.NativeLibraries)
.Select(e => e.ResolvedPath)
.Union(export.RuntimeAssets);
}
internal static void CopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath)
internal static void CopyTo(this IEnumerable<string> assets, string destinationPath)
{
foreach (var asset in assets)
{
File.Copy(asset.ResolvedPath, Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath)),
File.Copy(asset, Path.Combine(destinationPath, Path.GetFileName(asset)),
overwrite: true);
}
}

View file

@ -19,6 +19,11 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
/// </summary>
public IEnumerable<LibraryAsset> RuntimeAssemblies { get; }
/// <summary>
/// Non assembly runtime assets.
/// </summary>
public IEnumerable<string> RuntimeAssets { get; }
/// <summary>
/// Gets a list of fully-qualified paths to native binaries required to run
/// </summary>
@ -33,26 +38,28 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
/// Gets a list of fully-qualified paths to source code file references
/// </summary>
public IEnumerable<string> SourceReferences { get; }
/// <summary>
/// Get a list of analyzers provided by this export.
/// </summary>
public IEnumerable<AnalyzerReference> AnalyzerReferences { get; }
public LibraryExport(LibraryDescription library,
IEnumerable<LibraryAsset> compileAssemblies,
IEnumerable<string> sourceReferences,
IEnumerable<LibraryAsset> runtimeAssemblies,
IEnumerable<LibraryAsset> nativeLibraries,
IEnumerable<AnalyzerReference> analyzers)
{
Library = library;
CompilationAssemblies = compileAssemblies;
SourceReferences = sourceReferences;
RuntimeAssemblies = runtimeAssemblies;
NativeLibraries = nativeLibraries;
AnalyzerReferences = analyzers;
}
/// <summary>
/// Get a list of analyzers provided by this export.
/// </summary>
public IEnumerable<AnalyzerReference> AnalyzerReferences { get; }
public LibraryExport(LibraryDescription library,
IEnumerable<LibraryAsset> compileAssemblies,
IEnumerable<string> sourceReferences,
IEnumerable<LibraryAsset> runtimeAssemblies,
IEnumerable<string> runtimeAssets,
IEnumerable<LibraryAsset> nativeLibraries,
IEnumerable<AnalyzerReference> analyzers)
{
Library = library;
CompilationAssemblies = compileAssemblies;
SourceReferences = sourceReferences;
RuntimeAssemblies = runtimeAssemblies;
RuntimeAssets = runtimeAssets;
NativeLibraries = nativeLibraries;
AnalyzerReferences = analyzers;
}
private string DebuggerDisplay => Library.Identity.ToString();
}

View file

@ -81,7 +81,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
var sourceReferences = new List<string>();
var analyzerReferences = new List<AnalyzerReference>();
var libraryExport = GetExport(library);
// We need to filter out source references from non-root libraries,
// so we rebuild the library export
@ -100,8 +100,13 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
analyzerReferences.AddRange(libraryExport.AnalyzerReferences);
}
yield return new LibraryExport(library, compilationAssemblies, sourceReferences,
libraryExport.RuntimeAssemblies, libraryExport.NativeLibraries, analyzerReferences);
yield return new LibraryExport(library,
compilationAssemblies,
sourceReferences,
libraryExport.RuntimeAssemblies,
libraryExport.RuntimeAssets,
libraryExport.NativeLibraries,
analyzerReferences);
}
}
@ -142,17 +147,17 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
{
sourceReferences.Add(sharedSource);
}
var analyzers = GetAnalyzerReferences(package);
return new LibraryExport(package, compileAssemblies,
sourceReferences, runtimeAssemblies, nativeLibraries, analyzers);
sourceReferences, runtimeAssemblies, Array.Empty<string>(), nativeLibraries, analyzers);
}
private LibraryExport ExportProject(ProjectDescription project)
{
var compileAssemblies = new List<LibraryAsset>();
var runtimeAssemblies = new List<LibraryAsset>();
var runtimeAssets = new List<string>();
var sourceReferences = new List<string>();
if (!string.IsNullOrEmpty(project.TargetFrameworkInfo?.AssemblyPath))
@ -160,38 +165,29 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
// Project specifies a pre-compiled binary. We're done!
var assemblyPath = ResolvePath(project.Project, _configuration, project.TargetFrameworkInfo.AssemblyPath);
var pdbPath = Path.ChangeExtension(assemblyPath, "pdb");
var compileAsset = new LibraryAsset(
project.Project.Name,
null,
Path.GetFullPath(Path.Combine(project.Project.ProjectDirectory, assemblyPath)));
var pdbAsset = new LibraryAsset(
project.Project.Name + "/pdb",
null,
Path.GetFullPath(Path.Combine(project.Project.ProjectDirectory, pdbPath)));
compileAssemblies.Add(compileAsset);
runtimeAssemblies.Add(compileAsset);
runtimeAssemblies.Add(pdbAsset);
runtimeAssets.Add(pdbPath);
}
else
{
var outputCalculator = project.GetOutputPathCalculator();
var assemblyPath = outputCalculator.GetAssemblyPath(_configuration);
compileAssemblies.Add(new LibraryAsset(project.Identity.Name, null, assemblyPath));
foreach (var path in outputCalculator.GetBuildOutputs(_configuration))
{
var assetName = project.Identity.Name;
if (Path.GetFileNameWithoutExtension(path) != project.Identity.Name)
if (string.Equals(assemblyPath, path))
{
assetName += "/" + Path.GetExtension(path).Substring(1);
continue;
}
// We're going to call this asset
runtimeAssemblies.Add(new LibraryAsset(assetName, null, path));
runtimeAssets.Add(path);
}
}
@ -205,7 +201,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
// just the same as compileAssemblies and nativeLibraries are empty
// Also no support for analyzer projects
return new LibraryExport(project, compileAssemblies, sourceReferences,
runtimeAssemblies, Array.Empty<LibraryAsset>(), Array.Empty<AnalyzerReference>());
compileAssemblies, runtimeAssets, Array.Empty<LibraryAsset>(), Array.Empty<AnalyzerReference>());
}
private static string ResolvePath(Project project, string configuration, string path)
@ -233,6 +229,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
new[] { new LibraryAsset(library.Identity.Name, library.Path, library.Path) },
Array.Empty<string>(),
Array.Empty<LibraryAsset>(),
Array.Empty<string>(),
Array.Empty<LibraryAsset>(),
Array.Empty<AnalyzerReference>());
}
@ -245,7 +242,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
.Where(path => path.StartsWith("shared" + Path.DirectorySeparatorChar))
.Select(path => Path.Combine(package.Path, path));
}
private IEnumerable<AnalyzerReference> GetAnalyzerReferences(PackageDescription package)
{
var analyzers = package
@ -253,16 +250,16 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
.Files
.Where(path => path.StartsWith("analyzers" + Path.DirectorySeparatorChar) &&
path.EndsWith(".dll"));
var analyzerRefs = new List<AnalyzerReference>();
// See https://docs.nuget.org/create/analyzers-conventions for the analyzer
// NuGet specification
foreach (var analyzer in analyzers)
{
var specifiers = analyzer.Split(Path.DirectorySeparatorChar);
var assemblyPath = Path.Combine(package.Path, analyzer);
// $/analyzers/{Framework Name}{Version}/{Supported Architecture}/{Supported Programming Language}/{Analyzer}.dll
switch (specifiers.Length)
{
@ -275,7 +272,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
runtimeIdentifier: null
));
break;
// $/analyzers/{framework}/{analyzer}.dll
case 3:
analyzerRefs.Add(new AnalyzerReference(
@ -285,7 +282,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
runtimeIdentifier: null
));
break;
// $/analyzers/{framework}/{language}/{analyzer}.dll
case 4:
analyzerRefs.Add(new AnalyzerReference(
@ -295,7 +292,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
runtimeIdentifier: null
));
break;
// $/analyzers/{framework}/{runtime}/{language}/{analyzer}.dll
case 5:
analyzerRefs.Add(new AnalyzerReference(
@ -305,10 +302,10 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
runtimeIdentifier: specifiers[2]
));
break;
// Anything less than 2 specifiers or more than 4 is
// illegal according to the specification and will be
// ignored
// Anything less than 2 specifiers or more than 4 is
// illegal according to the specification and will be
// ignored
}
}
return analyzerRefs;

View file

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
@ -74,7 +75,7 @@ namespace Microsoft.DotNet.ProjectModel
return intermediateOutputPath;
}
public string GetAssemblyPath(string buildConfiguration)
{
var compilationOptions = _project.GetCompilerOptions(_framework, buildConfiguration);
@ -89,22 +90,43 @@ namespace Microsoft.DotNet.ProjectModel
GetOutputDirectoryPath(buildConfiguration),
_project.Name + outputExtension);
}
public IEnumerable<string> GetBuildOutputs(string buildConfiguration)
{
var assemblyPath = GetAssemblyPath(buildConfiguration);
yield return assemblyPath;
yield return Path.ChangeExtension(assemblyPath, "pdb");
var compilationOptions = _project.GetCompilerOptions(_framework, buildConfiguration);
if (compilationOptions.GenerateXmlDocumentation == true)
{
yield return Path.ChangeExtension(assemblyPath, "xml");
}
// This should only exist in desktop framework
var configFile = assemblyPath + ".config";
if (File.Exists(configFile))
{
yield return configFile;
}
// Deps file
var depsFile = GetDepsPath(buildConfiguration);
if (File.Exists(depsFile))
{
yield return depsFile;
}
}
public string GetDepsPath(string buildConfiguration)
{
return Path.Combine(GetOutputDirectoryPath(buildConfiguration), _project.Name + FileNameSuffixes.Deps);
}
public string GetExecutablePath(string buildConfiguration)
{
var extension = FileNameSuffixes.CurrentPlatform.Exe;
@ -115,7 +137,7 @@ namespace Microsoft.DotNet.ProjectModel
{
extension = FileNameSuffixes.DotNet.Exe;
}
return Path.Combine(
GetOutputDirectoryPath(buildConfiguration),
_project.Name + extension);

View file

@ -57,7 +57,7 @@ namespace Microsoft.DotNet.Tools.Compiler
}
private static bool CompileNative(
ProjectContext context,
ProjectContext context,
CompilerCommandApp args)
{
var outputPathCalculator = context.GetOutputPathCalculator(args.OutputValue);
@ -71,7 +71,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, args.ConfigValue);
var managedOutput = outputPathCalculator.GetAssemblyPath(args.ConfigValue);
var nativeArgs = new List<string>();
// Input Assembly
@ -82,8 +82,8 @@ namespace Microsoft.DotNet.Tools.Compiler
{
nativeArgs.Add("--ilcargs");
nativeArgs.Add($"{args.IlcArgsValue}");
}
}
// ILC Path
if (!string.IsNullOrWhiteSpace(args.IlcPathValue))
{
@ -106,7 +106,7 @@ namespace Microsoft.DotNet.Tools.Compiler
}
// CodeGen Mode
if(args.IsCppModeValue)
if (args.IsCppModeValue)
{
nativeArgs.Add("--mode");
nativeArgs.Add("cpp");
@ -138,7 +138,7 @@ namespace Microsoft.DotNet.Tools.Compiler
// Output Path
nativeArgs.Add("--output");
nativeArgs.Add($"{nativeOutputPath}");
nativeArgs.Add($"{nativeOutputPath}");
// Write Response File
var rsp = Path.Combine(nativeIntermediateOutputPath, $"dotnet-compile-native.{context.ProjectFile.Name}.rsp");
@ -288,7 +288,7 @@ namespace Microsoft.DotNet.Tools.Compiler
};
RunScripts(context, ScriptNames.PreCompile, contextVariables);
var result = Command.Create($"dotnet-compile-{compilerName}", new [] {"@" + $"{rsp}" })
var result = Command.Create($"dotnet-compile-{compilerName}", new[] { "@" + $"{rsp}" })
.OnErrorLine(line =>
{
var diagnostic = ParseDiagnostic(context.ProjectDirectory, line);
@ -344,12 +344,16 @@ namespace Microsoft.DotNet.Tools.Compiler
generateBindingRedirects = true;
var projectContext =
ProjectContext.Create(context.ProjectDirectory, context.TargetFramework,
new[] { PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier()});
new[] { PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() });
projectContext
.CreateExporter(args.ConfigValue)
.GetDependencies(LibraryType.Package)
.WriteDepsTo(Path.Combine(outputPath, projectContext.ProjectFile.Name + FileNameSuffixes.Deps));
// Don't generate a deps file if we're on desktop
if (!context.TargetFramework.IsDesktop())
{
projectContext
.CreateExporter(args.ConfigValue)
.GetDependencies(LibraryType.Package)
.WriteDepsTo(Path.Combine(outputPath, projectContext.ProjectFile.Name + FileNameSuffixes.Deps));
}
}
if (generateBindingRedirects && context.TargetFramework.IsDesktop())
@ -372,12 +376,6 @@ namespace Microsoft.DotNet.Tools.Compiler
.Execute();
}
}
private static void CopyExport(string outputPath, LibraryExport export)
{
CopyFiles(export.RuntimeAssemblies, outputPath);
CopyFiles(export.NativeLibraries, outputPath);
}
private static bool PrintSummary(List<DiagnosticMessage> diagnostics, Stopwatch sw, bool success = true)
{

View file

@ -132,6 +132,7 @@ namespace Microsoft.DotNet.Tools.Publish
PublishFiles(export.RuntimeAssemblies, outputPath, nativeSubdirectories: false);
PublishFiles(export.NativeLibraries, outputPath, nativeSubdirectories);
PublishFiles(export.RuntimeAssets, outputPath);
}
CopyContents(context, outputPath);
@ -174,6 +175,14 @@ namespace Microsoft.DotNet.Tools.Publish
return 0;
}
private static void PublishFiles(IEnumerable<string> files, string outputPath)
{
foreach (var file in files)
{
var targetPath = Path.Combine(outputPath, Path.GetFileName(file));
File.Copy(file, targetPath, overwrite: true);
}
}
private static void PublishFiles(IEnumerable<LibraryAsset> files, string outputPath, bool nativeSubdirectories)
{