2016-01-04 12:49:13 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2016-01-04 23:12:40 -08:00
|
|
|
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
2016-01-04 12:49:13 -08:00
|
|
|
|
|
2016-01-04 23:12:40 -08:00
|
|
|
|
namespace Microsoft.DotNet.Cli.Compiler.Common
|
2016-01-04 12:49:13 -08:00
|
|
|
|
{
|
2016-01-06 02:27:16 -08:00
|
|
|
|
public static class LibraryExporterExtensions
|
2016-01-04 12:49:13 -08:00
|
|
|
|
{
|
2016-01-06 02:27:16 -08:00
|
|
|
|
public static void WriteDepsTo(this IEnumerable<LibraryExport> exports, string path)
|
2016-01-04 12:49:13 -08:00
|
|
|
|
{
|
2016-01-29 18:21:37 -08:00
|
|
|
|
CreateDirectoryIfNotExists(path);
|
|
|
|
|
|
2016-01-04 12:49:13 -08:00
|
|
|
|
File.WriteAllLines(path, exports.SelectMany(GenerateLines));
|
|
|
|
|
}
|
2016-01-29 18:21:37 -08:00
|
|
|
|
|
|
|
|
|
private static void CreateDirectoryIfNotExists(string path)
|
|
|
|
|
{
|
|
|
|
|
var depsFile = new FileInfo(path);
|
|
|
|
|
depsFile.Directory.Create();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-04 12:49:13 -08:00
|
|
|
|
private static IEnumerable<string> GenerateLines(LibraryExport export)
|
|
|
|
|
{
|
|
|
|
|
return GenerateLines(export, export.RuntimeAssemblies, "runtime")
|
|
|
|
|
.Union(GenerateLines(export, export.NativeLibraries, "native"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<string> GenerateLines(LibraryExport export, IEnumerable<LibraryAsset> items, string type)
|
|
|
|
|
{
|
2016-01-04 23:12:40 -08:00
|
|
|
|
return items.Select(i => DepsFormatter.EscapeRow(new[]
|
2016-01-04 12:49:13 -08:00
|
|
|
|
{
|
|
|
|
|
export.Library.Identity.Type.Value,
|
|
|
|
|
export.Library.Identity.Name,
|
|
|
|
|
export.Library.Identity.Version.ToNormalizedString(),
|
|
|
|
|
export.Library.Hash,
|
|
|
|
|
type,
|
|
|
|
|
i.Name,
|
|
|
|
|
i.RelativePath
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 20:35:43 -08:00
|
|
|
|
internal static IEnumerable<string> RuntimeAssets(this LibraryExport export)
|
2016-01-04 12:49:13 -08:00
|
|
|
|
{
|
2016-01-27 20:35:43 -08:00
|
|
|
|
return export.RuntimeAssemblies.Union(export.NativeLibraries)
|
|
|
|
|
.Select(e => e.ResolvedPath)
|
|
|
|
|
.Union(export.RuntimeAssets);
|
2016-01-04 12:49:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 20:35:43 -08:00
|
|
|
|
internal static void CopyTo(this IEnumerable<string> assets, string destinationPath)
|
2016-01-04 12:49:13 -08:00
|
|
|
|
{
|
|
|
|
|
foreach (var asset in assets)
|
|
|
|
|
{
|
2016-01-27 20:35:43 -08:00
|
|
|
|
File.Copy(asset, Path.Combine(destinationPath, Path.GetFileName(asset)),
|
2016-01-04 12:49:13 -08:00
|
|
|
|
overwrite: true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|