Skip to content

Commit

Permalink
initial spike of compile, publish and run
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay committed Oct 6, 2015
1 parent f40dd3d commit ab8986e
Show file tree
Hide file tree
Showing 19 changed files with 3,407 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
10 changes: 10 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="AspNetCIDev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
44 changes: 44 additions & 0 deletions dotnet-cli.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1F391100-F011-4630-8C25-D1A5355E4F19}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5AB144A3-3D0A-4DC7-9EE8-19FDD2DF8735}"
ProjectSection(SolutionItems) = preProject
dotnet-compile.cmd = dotnet-compile.cmd
dotnet-run.cmd = dotnet-run.cmd
global.json = global.json
NuGet.Config = NuGet.Config
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{47858134-8A8D-4D5C-ABD5-E6630A66DA05}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestApp", "test\TestApp\TestApp.xproj", "{58808BBC-371E-47D6-A3D0-4902145EDA4E}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "DotNet.Tools.DependencyResolver", "src\DotNet.Tools.DependencyResolver\DotNet.Tools.DependencyResolver.xproj", "{A5D41198-209A-461B-A191-F48B9DBECD67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58808BBC-371E-47D6-A3D0-4902145EDA4E}.Release|Any CPU.Build.0 = Release|Any CPU
{A5D41198-209A-461B-A191-F48B9DBECD67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5D41198-209A-461B-A191-F48B9DBECD67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5D41198-209A-461B-A191-F48B9DBECD67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5D41198-209A-461B-A191-F48B9DBECD67}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{58808BBC-371E-47D6-A3D0-4902145EDA4E} = {47858134-8A8D-4D5C-ABD5-E6630A66DA05}
{A5D41198-209A-461B-A191-F48B9DBECD67} = {1F391100-F011-4630-8C25-D1A5355E4F19}
EndGlobalSection
EndGlobal
30 changes: 30 additions & 0 deletions dotnet-compile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$OutputName = Split-Path -Leaf (Get-Location)
$OutputPath = Join-Path (Get-Location) "bin"

if(!(Test-Path $OutputPath)) {
mkdir $OutputPath | Out-Null
}
$OutputPath = (Convert-Path $OutputPath)


# Resolve compilation dependencies
Write-Host "Resolving dependencies..."
$refs = dnx -p "$PSScriptRoot\src\DotNet.Tools.DependencyResolver" run --packages "$env:USERPROFILE\.dnx\packages" --target "DNXCore,Version=v5.0" --assets compile

# Resolve source files
Write-Host "Finding source files..."
$srcs = dnx -p "$PSScriptRoot\src\DotNet.Tools.SourceResolver" run

# Build csc response file
$resp = @($refs | foreach { "/r:$_" })
$resp += @($srcs | foreach { $_ })
$resp += @(
"/out:$OutputPath\$OutputName.dll"
"/nostdlib"
)

Write-Host "Compiling..."
$resp > "$OutputPath\csc.rsp"
csc "@$OutputPath\csc.rsp"

Write-Host " $OutputName -> $OutputPath\$OutputName.dll"
31 changes: 31 additions & 0 deletions dotnet-publish.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$OutputName = Split-Path -Leaf (Get-Location)
$OutputPath = Join-Path (Join-Path (Get-Location) "bin") "publish"

& $PSScriptRoot\dotnet-compile.ps1

if(Test-Path $OutputPath) {
del -Recurse -Force $OutputPath
}
mkdir $OutputPath | Out-Null
$OutputPath = (Convert-Path $OutputPath)

# Resolve runtime and native dependencies
Write-Host "Resolving dependencies..."
$refs = dnx -p "$PSScriptRoot\src\DotNet.Tools.DependencyResolver" run --packages "$env:USERPROFILE\.dnx\packages" --target "DNXCore,Version=v5.0/win7-x64" --assets runtime --assets native

# Copy everything to one directory
$refs | foreach {
Write-Host "Publishing $_ ..."
cp $_ $OutputPath
}

$ProjectBinary = (Join-Path (Get-Location) "bin\$OutputName.dll")
Write-Host "Publishing $ProjectBinary ..."
cp $ProjectBinary $OutputPath

# CoreConsole should have come along for the ride
$CoreConsolePath = Join-Path $OutputPath "CoreConsole.exe"
if(!(Test-Path $CoreConsolePath)) {
throw "Unable to locate CoreConsole.exe. You must have a dependency on Microsoft.NETCore.ConsoleHost (for now ;))"
}
mv $CoreConsolePath (Join-Path $OutputPath "$OutputName.exe")
6 changes: 6 additions & 0 deletions dotnet-run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$OutputName = Split-Path -Leaf (Get-Location)

& $PSScriptRoot\dotnet-compile.ps1

# Still need to use DNX, but it just boots CoreCLR, no runtime involved.
dnx run bin\$OutputName.exe
3 changes: 3 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projects": [ "src", "test" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>a5d41198-209a-461b-a191-f48b9dbecd67</ProjectGuid>
<RootNamespace>DotNet.Tools.DependencyResolver</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
54 changes: 54 additions & 0 deletions src/DotNet.Tools.DependencyResolver/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.IO;
using Microsoft.Dnx.Runtime.Common.CommandLine;

namespace DotNet.Tools.DependencyResolver
{
public class Program
{
public void Main(string[] args)
{
var app = new CommandLineApplication();
app.HelpOption("-h|--help");
app.Description = "Resolves the absolute path of all dependencies for a project";

var packages = app.Option("-p|--packages <PACKAGES_DIRECTORY>", "Path to the directories containing packages to resolve.", CommandOptionType.MultipleValue);
var target = app.Option("-t|--target <TARGET_IDENTIFIER>", "The target to resolve dependencies for.", CommandOptionType.SingleValue);
var output = app.Option("-o|--output <OUTPUT_FILE>", "The path in which to write the output file (formatted as text with one line per dependency)", CommandOptionType.SingleValue);
var assetType = app.Option("-a|--assets <ASSET_TYPE>", "The type of assets to resolve (common values include: compile, runtime, native)", CommandOptionType.MultipleValue);
var project = app.Argument("PROJECT", "The project to resolve. A directory or a path to a project.lock.json may be used. Defaults to the current directory");

app.OnExecute(() =>
{
// Check required args
if(!packages.HasValue())
{
Console.Error.WriteLine("Missing required argument: --packages");
app.ShowHelp();
return 1;
}
if(!target.HasValue())
{
Console.Error.WriteLine("Missing required argument: --target");
app.ShowHelp();
return 1;
}
if(!assetType.HasValue())
{
Console.Error.WriteLine("Missing required argument: --assets");
app.ShowHelp();
return 1;
}

var path = project.Value ?? Directory.GetCurrentDirectory();
if (!path.EndsWith("project.lock.json"))
{
path = Path.Combine(path, "project.lock.json");
}
return Resolver.Execute(packages.Values, target.Value(), output.Value(), assetType.Values, path);
});

app.Execute(args);
}
}
}
84 changes: 84 additions & 0 deletions src/DotNet.Tools.DependencyResolver/Resolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace DotNet.Tools.DependencyResolver
{
public static class Resolver
{
public static int Execute(IEnumerable<string> packageDirectories, string targetName, string output, IEnumerable<string> assetTypes, string lockFilePath)
{
// Open the lock file
var lockFile = JObject.Parse(File.ReadAllText(lockFilePath));

// Locate the target
var target = lockFile["targets"][targetName] as JObject;
if (target == null)
{
Console.Error.WriteLine($"Could not find target in lock file: {target}");
return 1;
}

// Iterate over each package and prepare the dependency data
bool success = true;
List<string> files = new List<string>();
foreach (var dependency in target)
{
// Parse the input string
var splat = dependency.Key.Split('/');
var id = splat[0];
var version = splat[1];

string packageRoot = null;
foreach (var dir in packageDirectories)
{
var candidate = Path.Combine(dir, id, version);
if (Directory.Exists(candidate))
{
packageRoot = candidate;
break;
}
}

if (packageRoot == null)
{
Console.Error.WriteLine($"WARNING: Unable to locate {id} {version}");
success = false;
}

// Locate all the assets
foreach (var assetType in assetTypes)
{
var assetList = dependency.Value[assetType] as JObject;
if (assetList != null)
{
foreach (var asset in assetList)
{
var pathified = Path.Combine(asset.Key.Split('/'));
if (!Path.GetFileName(pathified).Equals("_._", StringComparison.Ordinal))
{
var file = Path.Combine(packageRoot, pathified);
if (!File.Exists(file))
{
Console.Error.WriteLine($"WARNING: Missing asset: {file}");
success = false;
}
files.Add(file);
Console.WriteLine(file);
}
}
}
}
}

if (!string.IsNullOrEmpty(output))
{
File.WriteAllLines(output, files);
}

return success ? 0 : 1;
}
}
}
24 changes: 24 additions & 0 deletions src/DotNet.Tools.DependencyResolver/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "1.0.0-*",

"dependencies": {
"System.Collections": "4.0.10-beta-*",
"System.Console": "4.0.0-beta-*",
"System.Linq": "4.0.0-beta-*",
"System.Threading": "4.0.10-beta-*",
"System.IO.FileSystem": "4.0.1-beta-*",

"Microsoft.CSharp": "4.0.0-beta-23109",
"Microsoft.Framework.CommandLineUtils.Sources": "1.0.0-*",

"Newtonsoft.Json": "7.0.1"
},

"commands": {
"dotnet-resolve-dependencies": ""
},

"frameworks": {
"dnxcore50": { }
}
}
Loading

0 comments on commit ab8986e

Please sign in to comment.