command line interface clean-up
This commit is contained in:
parent
d39f492300
commit
b35fba863b
33 changed files with 1113 additions and 815 deletions
|
@ -66,7 +66,7 @@ echo Building stage1 dotnet-publish.exe ...
|
|||
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE1_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Publish"
|
||||
if errorlevel 1 goto fail
|
||||
|
||||
echo Building stage1 dotnet-publish.exe ...
|
||||
echo Building stage1 resgen.exe ...
|
||||
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE1_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Resgen"
|
||||
if errorlevel 1 goto fail
|
||||
|
||||
|
@ -103,7 +103,7 @@ echo Building stage2 dotnet-publish.exe ...
|
|||
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE2_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Publish"
|
||||
if errorlevel 1 goto fail
|
||||
|
||||
echo Building stage2 dotnet-publish.exe ...
|
||||
echo Building stage2 resgen.exe ...
|
||||
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE2_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Resgen"
|
||||
if errorlevel 1 goto fail
|
||||
|
||||
|
@ -132,7 +132,7 @@ REM Smoke-test the output
|
|||
set PATH=%STAGE2_DIR%;%START_PATH%
|
||||
|
||||
del "%REPOROOT%\test\TestApp\project.lock.json"
|
||||
dotnet restore "%REPOROOT%\test\TestApp" --runtime "%RID%" --quiet
|
||||
dotnet restore "%REPOROOT%\test\TestApp" --quiet
|
||||
dotnet compile "%REPOROOT%\test\TestApp" --output "%REPOROOT%\artifacts\%RID%\smoketest"
|
||||
|
||||
set CLRHOST_CLR_PATH=%STAGE2_DIR%
|
||||
|
|
|
@ -108,8 +108,8 @@ dotnet compile "$REPOROOT/test/TestApp" --output "$REPOROOT/artifacts/$RID/smoke
|
|||
|
||||
export CLRHOST_CLR_PATH=$STAGE2_DIR
|
||||
|
||||
OUTPUT=$($REPOROOT/artifacts/$RID/smoketest/TestApp)
|
||||
[ "$OUTPUT" == "This is a test app" ] || (error "Smoke test failed!" && exit 1)
|
||||
# set -e will abort if the exit code of this is non-zero
|
||||
$REPOROOT/artifacts/$RID/smoketest/TestApp
|
||||
|
||||
# Check that a compiler error is reported
|
||||
set +e
|
||||
|
|
19
scripts/dev-install.cmd
Normal file
19
scripts/dev-install.cmd
Normal file
|
@ -0,0 +1,19 @@
|
|||
@echo off
|
||||
|
||||
REM This trick gets the absolute path from a relative path
|
||||
pushd %~dp0..
|
||||
set REPOROOT=%CD%
|
||||
popd
|
||||
|
||||
set RID=win7-x64
|
||||
set STAGE2_DIR=%REPOROOT%\artifacts\%RID%\stage2
|
||||
set DESTINATION=%USERPROFILE%\.dotnet\sdks\dotnet-win-x64.0.0.1-dev
|
||||
|
||||
echo Junctioning %STAGE2_DIR% to %DESTINATION%
|
||||
|
||||
if not exist %DESTINATION% goto link
|
||||
echo Removing old junction %DESTINATION%
|
||||
rd /s /q %DESTINATION%
|
||||
|
||||
:link
|
||||
mklink /J %DESTINATION% %STAGE2_DIR%
|
|
@ -2,7 +2,7 @@
|
|||
SETLOCAL
|
||||
SET ERRORLEVEL=
|
||||
|
||||
"%~dp0dnx\dnx" "%~dp0dnx\lib\Microsoft.Dnx.Tooling\Microsoft.Dnx.Tooling.dll" restore --runtime "osx.10.10-x64" --runtime "ubuntu.14.04-x64" %*
|
||||
"%~dp0dnx\dnx" "%~dp0dnx\lib\Microsoft.Dnx.Tooling\Microsoft.Dnx.Tooling.dll" restore --runtime "osx.10.10-x64" --runtime "ubuntu.14.04-x64" --runtime "win7-x64" %*
|
||||
|
||||
exit /b %ERRORLEVEL%
|
||||
ENDLOCAL
|
||||
|
|
|
@ -16,12 +16,16 @@ if(![string]::IsNullOrEmpty($env:DOTNET_BUILD_VERSION)) {
|
|||
|
||||
$PackageName = Join-Path $PackageDir "dotnet-win-x64.$PackageVersion.zip"
|
||||
|
||||
if (Test-Path $PackageName)
|
||||
{
|
||||
del $PackageName
|
||||
}
|
||||
|
||||
Add-Type -Assembly System.IO.Compression.FileSystem
|
||||
[System.IO.Compression.ZipFile]::CreateFromDirectory($Stage2Dir, $PackageName, "Optimal", $false)
|
||||
|
||||
Write-Host "Packaged stage2 to $PackageName"
|
||||
|
||||
|
||||
$PublishScript = Join-Path $PSScriptRoot "publish.ps1"
|
||||
& $PublishScript -file $PackageName
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
|
@ -16,8 +17,8 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
private StringWriter _stdOutCapture;
|
||||
private StringWriter _stdErrCapture;
|
||||
|
||||
private TextWriter _stdOutForward;
|
||||
private TextWriter _stdErrForward;
|
||||
private Action<string> _stdOutForward;
|
||||
private Action<string> _stdErrForward;
|
||||
|
||||
private Action<string> _stdOutHandler;
|
||||
private Action<string> _stdErrHandler;
|
||||
|
@ -128,7 +129,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
#if DEBUG
|
||||
var sw = Stopwatch.StartNew();
|
||||
Reporter.Output.WriteLine($"> {FormatProcessInfo(_process.StartInfo)}".White());
|
||||
Reporter.Verbose.WriteLine($"> {FormatProcessInfo(_process.StartInfo)}".White());
|
||||
#endif
|
||||
_process.Start();
|
||||
_process.BeginOutputReadLine();
|
||||
|
@ -142,11 +143,11 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
var message = $"< {FormatProcessInfo(_process.StartInfo)} exited with {exitCode} in {sw.ElapsedMilliseconds} ms.";
|
||||
if (exitCode == 0)
|
||||
{
|
||||
Reporter.Output.WriteLine(message.Green());
|
||||
Reporter.Verbose.WriteLine(message.Green());
|
||||
}
|
||||
else
|
||||
{
|
||||
Reporter.Output.WriteLine(message.Red().Bold());
|
||||
Reporter.Verbose.WriteLine(message.Red().Bold());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -176,17 +177,37 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
return this;
|
||||
}
|
||||
|
||||
public Command ForwardStdOut(TextWriter to = null)
|
||||
public Command ForwardStdOut(TextWriter to = null, bool onlyIfVerbose = false)
|
||||
{
|
||||
ThrowIfRunning();
|
||||
_stdOutForward = to ?? Console.Out;
|
||||
if (!onlyIfVerbose || CommandContext.IsVerbose())
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
_stdOutForward = Reporter.Output.WriteLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
_stdOutForward = to.WriteLine;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command ForwardStdErr(TextWriter to = null)
|
||||
public Command ForwardStdErr(TextWriter to = null, bool onlyIfVerbose = false)
|
||||
{
|
||||
ThrowIfRunning();
|
||||
_stdErrForward = to ?? Console.Error;
|
||||
if (!onlyIfVerbose || CommandContext.IsVerbose())
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
_stdErrForward = Reporter.Error.WriteLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
_stdErrForward = to.WriteLine;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -230,7 +251,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
}
|
||||
}
|
||||
|
||||
private void ProcessData(string data, StringWriter capture, TextWriter forward, Action<string> handler)
|
||||
private void ProcessData(string data, StringWriter capture, Action<string> forward, Action<string> handler)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
|
@ -244,7 +265,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
if (forward != null)
|
||||
{
|
||||
forward.WriteLine(data);
|
||||
forward(data);
|
||||
}
|
||||
|
||||
if (handler != null)
|
||||
|
|
41
src/Microsoft.DotNet.Cli.Utils/CommandContext.cs
Normal file
41
src/Microsoft.DotNet.Cli.Utils/CommandContext.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
internal static class CommandContext
|
||||
{
|
||||
internal static class Variables
|
||||
{
|
||||
private static readonly string Prefix = "DOTNET_CLI_CONTEXT_";
|
||||
internal static readonly string Verbose = Prefix + "VERBOSE";
|
||||
internal static readonly string AnsiPassThru = Prefix + "ANSI_PASS_THRU";
|
||||
}
|
||||
|
||||
private static Lazy<bool> _verbose = new Lazy<bool>(() => GetBool(Variables.Verbose));
|
||||
private static Lazy<bool> _ansiPassThru = new Lazy<bool>(() => GetBool(Variables.AnsiPassThru));
|
||||
|
||||
public static bool IsVerbose()
|
||||
{
|
||||
return _verbose.Value;
|
||||
}
|
||||
|
||||
public static bool ShouldPassAnsiCodesThrough()
|
||||
{
|
||||
return _ansiPassThru.Value;
|
||||
}
|
||||
|
||||
private static bool GetBool(string name, bool defaultValue = false)
|
||||
{
|
||||
var str = Environment.GetEnvironmentVariable(name);
|
||||
bool value;
|
||||
if(string.IsNullOrEmpty(str) || !bool.TryParse(str, out value))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,54 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
// Stupid-simple console manager
|
||||
internal static class Reporter
|
||||
internal class Reporter
|
||||
{
|
||||
public static AnsiConsole Output { get; } = AnsiConsole.GetOutput(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
|
||||
public static AnsiConsole Error { get; } = AnsiConsole.GetError(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
|
||||
private static readonly Reporter Null = new Reporter(console: null);
|
||||
private static object _lock = new object();
|
||||
|
||||
private AnsiConsole _console;
|
||||
|
||||
private Reporter(AnsiConsole console)
|
||||
{
|
||||
_console = console;
|
||||
}
|
||||
|
||||
public static Reporter Output { get; } = Create(AnsiConsole.GetOutput);
|
||||
public static Reporter Error { get; } = Create(AnsiConsole.GetError);
|
||||
public static Reporter Verbose { get; } = CommandContext.IsVerbose() ? Create(AnsiConsole.GetError) : Null;
|
||||
|
||||
public static Reporter Create(Func<bool, AnsiConsole> getter)
|
||||
{
|
||||
return new Reporter(getter(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)));
|
||||
}
|
||||
|
||||
public void WriteLine(string message)
|
||||
{
|
||||
lock(_lock)
|
||||
{
|
||||
if (CommandContext.ShouldPassAnsiCodesThrough())
|
||||
{
|
||||
_console?.Writer?.WriteLine(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
_console?.WriteLine(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteLine()
|
||||
{
|
||||
lock(_lock)
|
||||
{
|
||||
_console?.Writer?.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private const string HelpText = @".NET Command Line Interface
|
||||
Usage: dotnet [common-options] [command] [arguments]
|
||||
|
||||
Arguments:
|
||||
[command] The command to execute
|
||||
[arguments] Arguments to pass to the command
|
||||
|
||||
Common Options (passed before the command):
|
||||
-v|--verbose Enable verbose output
|
||||
|
||||
Common Commands:
|
||||
compile Compiles a .NET project
|
||||
publish Publishes a .NET project for deployment
|
||||
run Compiles and immediately executes a .NET project";
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
// CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA.
|
||||
var verbose = false;
|
||||
var command = string.Empty;
|
||||
var lastArg = 0;
|
||||
|
||||
for (; lastArg < args.Length; lastArg++)
|
||||
{
|
||||
// Handle missing args
|
||||
PrintCommandList();
|
||||
return 1;
|
||||
if (IsArg(args[lastArg], "v", "verbose"))
|
||||
{
|
||||
verbose = true;
|
||||
}
|
||||
else if (args[lastArg].StartsWith("-"))
|
||||
{
|
||||
PrintHelp($"Unknown option: ${args[lastArg]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's the command, and we're done!
|
||||
command = args[lastArg];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (args[0].Equals("help", StringComparison.OrdinalIgnoreCase))
|
||||
var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray();
|
||||
|
||||
if (string.IsNullOrEmpty(command) || command.Equals("help", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (args.Length > 1)
|
||||
return RunHelpCommand(appArgs);
|
||||
}
|
||||
|
||||
return Command.Create("dotnet-" + command, appArgs)
|
||||
.EnvironmentVariable(CommandContext.Variables.Verbose, verbose.ToString())
|
||||
.EnvironmentVariable(CommandContext.Variables.AnsiPassThru, bool.TrueString)
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.Execute()
|
||||
.ExitCode;
|
||||
}
|
||||
|
||||
private static int RunHelpCommand(IEnumerable<string> appArgs)
|
||||
{
|
||||
return Command.Create("dotnet-" + args[1], "--help")
|
||||
if (appArgs.Any())
|
||||
{
|
||||
return Command.Create("dotnet-" + appArgs.First(), "--help")
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.Execute()
|
||||
|
@ -29,26 +79,23 @@ namespace Microsoft.DotNet.Cli
|
|||
}
|
||||
else
|
||||
{
|
||||
PrintCommandList();
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
private static void PrintHelp(string errorMessage = null)
|
||||
{
|
||||
return Command.Create("dotnet-" + args[0], args.Skip(1))
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.Execute()
|
||||
.ExitCode;
|
||||
if(!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
Reporter.Error.WriteLine(errorMessage.Red());
|
||||
}
|
||||
Reporter.Output.WriteLine(HelpText);
|
||||
}
|
||||
|
||||
private static void PrintCommandList()
|
||||
private static bool IsArg(string candidate, string shortName, string longName)
|
||||
{
|
||||
Console.WriteLine("Some dotnet Commands (use 'dotnet help <command>' to get help):");
|
||||
Console.WriteLine("* compile - Compiles code");
|
||||
Console.WriteLine("* publish - Publishes a project to a self-contained application");
|
||||
Console.WriteLine("* run - Publishes and immediately runs a project");
|
||||
return candidate.Equals("-" + shortName) || candidate.Equals("--" + longName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.Extensions.ProjectModel.Compilation
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class LibraryExport
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -39,5 +41,13 @@ namespace Microsoft.Extensions.ProjectModel.Compilation
|
|||
RuntimeAssemblies = runtimeAssemblies;
|
||||
NativeLibraries = nativeLibraries;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return Library.Identity.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,16 +32,33 @@ namespace Microsoft.Extensions.ProjectModel.Compilation
|
|||
|
||||
public LibraryManager LibraryManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the exports specified by this project, including the root project itself
|
||||
/// </summary>
|
||||
public IEnumerable<LibraryExport> GetAllExports()
|
||||
{
|
||||
// Export all but the main project
|
||||
return ExportLibraries(_ => true);
|
||||
}
|
||||
|
||||
public IEnumerable<LibraryExport> GetCompilationDependencies()
|
||||
/// <summary>
|
||||
/// Gets all exports required by the project, NOT including the project itself
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<LibraryExport> GetDependencies()
|
||||
{
|
||||
return GetDependencies(LibraryType.Unspecified);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all exports required by the project, of the specified <see cref="LibraryType"/>, NOT including the project itself
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<LibraryExport> GetDependencies(LibraryType type)
|
||||
{
|
||||
// Export all but the main project
|
||||
return ExportLibraries(library => library != _rootProject);
|
||||
return ExportLibraries(library =>
|
||||
library != _rootProject &&
|
||||
LibraryIsOfType(type, library));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -214,5 +231,11 @@ namespace Microsoft.Extensions.ProjectModel.Compilation
|
|||
Path.Combine(package.Path, assemblyPath)));
|
||||
}
|
||||
}
|
||||
|
||||
private static bool LibraryIsOfType(LibraryType type, LibraryDescription library)
|
||||
{
|
||||
return type.Equals(LibraryType.Unspecified) || // No type filter was requested
|
||||
library.Identity.Type.Equals(type); // OR, library type matches requested type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using Microsoft.DotNet.Cli.Utils;
|
|||
using Microsoft.DotNet.Tools.Common;
|
||||
using Microsoft.Extensions.ProjectModel;
|
||||
using Microsoft.Extensions.ProjectModel.Compilation;
|
||||
using Microsoft.Extensions.ProjectModel.Graph;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Compiler
|
||||
|
@ -106,8 +107,6 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
private static bool Compile(ProjectContext context, string configuration, string outputOptionValue, string intermediateOutputValue, bool buildProjectReferences)
|
||||
{
|
||||
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
|
||||
|
||||
// Set up Output Paths
|
||||
string outputPath = GetOutputPath(context, configuration, outputOptionValue);
|
||||
string intermediateOutputPath = GetIntermediateOutputPath(context, configuration, intermediateOutputValue, outputOptionValue);
|
||||
|
@ -124,7 +123,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
diagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
|
||||
|
||||
// Gather exports for the project
|
||||
var dependencies = exporter.GetCompilationDependencies().ToList();
|
||||
var dependencies = exporter.GetDependencies().ToList();
|
||||
|
||||
if (buildProjectReferences)
|
||||
{
|
||||
|
@ -158,6 +157,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
projects.Clear();
|
||||
}
|
||||
|
||||
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
|
||||
|
||||
// Dump dependency data
|
||||
// TODO: Turn on only if verbose, we can look at the response
|
||||
// file anyways
|
||||
|
@ -228,7 +229,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine(line);
|
||||
Reporter.Error.WriteLine(line);
|
||||
}
|
||||
})
|
||||
.OnOutputLine(line =>
|
||||
|
@ -241,7 +242,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.Out.WriteLine(line);
|
||||
Reporter.Output.WriteLine(line);
|
||||
}
|
||||
})
|
||||
.Execute();
|
||||
|
@ -339,7 +340,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
{
|
||||
Directory.Delete(path, recursive: true);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Unable to remove directory: " + path);
|
||||
Console.WriteLine(e.Message);
|
||||
|
@ -354,15 +355,9 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
if (runtimeContext.TargetFramework.IsDesktop())
|
||||
{
|
||||
// On desktop we need to copy dependencies since we don't own the host
|
||||
foreach (var export in exporter.GetAllExports())
|
||||
foreach (var export in exporter.GetDependencies())
|
||||
{
|
||||
if (export.Library == runtimeContext.RootProject)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CopyFiles(export.RuntimeAssemblies, outputPath);
|
||||
CopyFiles(export.NativeLibraries, outputPath);
|
||||
CopyExport(outputPath, export);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -371,16 +366,29 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
}
|
||||
}
|
||||
|
||||
private static void CopyExport(string outputPath, LibraryExport export)
|
||||
{
|
||||
CopyFiles(export.RuntimeAssemblies, outputPath);
|
||||
CopyFiles(export.NativeLibraries, outputPath);
|
||||
}
|
||||
|
||||
private static void EmitHost(ProjectContext runtimeContext, string outputPath, LibraryExporter exporter)
|
||||
{
|
||||
// Write the Host information file (basically a simplified form of the lock file)
|
||||
var lines = new List<string>();
|
||||
foreach(var export in exporter.GetAllExports())
|
||||
foreach (var export in exporter.GetAllExports())
|
||||
{
|
||||
if (export.Library is ProjectDescription)
|
||||
if (export.Library == runtimeContext.RootProject)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (export.Library is ProjectDescription)
|
||||
{
|
||||
// Copy project dependencies to the output folder
|
||||
CopyFiles(export.RuntimeAssemblies, outputPath);
|
||||
CopyFiles(export.NativeLibraries, outputPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.AddRange(GenerateLines(export, export.RuntimeAssemblies, "runtime"));
|
||||
|
@ -419,7 +427,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
private static void PrintSummary(bool success, List<DiagnosticMessage> diagnostics)
|
||||
{
|
||||
Reporter.Output.Writer.WriteLine();
|
||||
Reporter.Output.WriteLine();
|
||||
|
||||
var errorCount = diagnostics.Count(d => d.Severity == DiagnosticMessageSeverity.Error);
|
||||
var warningCount = diagnostics.Count(d => d.Severity == DiagnosticMessageSeverity.Warning);
|
||||
|
@ -436,7 +444,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
Reporter.Output.WriteLine($" {warningCount} Warning(s)");
|
||||
Reporter.Output.WriteLine($" {errorCount} Error(s)");
|
||||
|
||||
Reporter.Output.Writer.WriteLine();
|
||||
Reporter.Output.WriteLine();
|
||||
}
|
||||
|
||||
private static bool AddResources(Project project, List<string> compilerArgs, string intermediateOutputPath)
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
private static int Publish(ProjectContext context, string outputPath, string configuration)
|
||||
{
|
||||
Reporter.Output.WriteLine($"Publishing {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}/{context.RuntimeIdentifier}");
|
||||
Reporter.Output.WriteLine($"Publishing {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}/{context.RuntimeIdentifier.Yellow()}");
|
||||
|
||||
var options = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
||||
|
||||
|
@ -140,7 +140,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
continue;
|
||||
}
|
||||
|
||||
Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
|
||||
Reporter.Verbose.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
|
||||
|
||||
PublishFiles(export.RuntimeAssemblies, outputPath);
|
||||
PublishFiles(export.NativeLibraries, outputPath);
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
<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>0a309227-a9d8-4ddf-88dd-326b57b04378</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tools.Compiler</RootNamespace>
|
||||
<ProjectGuid>1c16108c-c786-482d-bb0a-36bdafe109ed</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tools.Run</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
|
@ -24,16 +24,16 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
|
||||
var framework = app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.MultipleValue);
|
||||
var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
|
||||
var preserveTemporaryOutput = app.Option("-p|--preserve-temporary", "Keep the output's temporary directory around", CommandOptionType.NoValue);
|
||||
var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");
|
||||
var preserveTemporaryOutput = app.Option("-t|--preserve-temporary", "Keep the output's temporary directory around", CommandOptionType.NoValue);
|
||||
var project = app.Option("-p|--project <PROJECT_PATH>", "The path to the project to run (defaults to the current directory)", CommandOptionType.SingleValue);
|
||||
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
// Locate the project and get the name and full path
|
||||
var path = project.Value;
|
||||
if (string.IsNullOrEmpty(path))
|
||||
var path = Directory.GetCurrentDirectory();
|
||||
if(project.HasValue())
|
||||
{
|
||||
path = Directory.GetCurrentDirectory();
|
||||
path = project.Value();
|
||||
}
|
||||
|
||||
var contexts = ProjectContext.CreateContextForEachFramework(path);
|
||||
|
@ -69,8 +69,8 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
|
||||
|
||||
// Compile to that directory
|
||||
var result = Command.Create($"dotnet-compile", $"--output \"{tempDir}\" --framework \"{context.TargetFramework}\" --configuration \"{configuration}\"")
|
||||
.ForwardStdOut()
|
||||
var result = Command.Create($"dotnet-compile", $"--output \"{tempDir}\" --framework \"{context.TargetFramework}\" --configuration \"{configuration}\" {context.ProjectFile.ProjectDirectory}")
|
||||
.ForwardStdOut(onlyIfVerbose: true)
|
||||
.ForwardStdErr()
|
||||
.Execute();
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
|
@ -60,6 +61,7 @@ namespace pal
|
|||
|
||||
typedef wchar_t char_t;
|
||||
typedef std::wstring string_t;
|
||||
typedef std::wstringstream stringstream_t;
|
||||
typedef std::ifstream ifstream_t;
|
||||
typedef HRESULT hresult_t;
|
||||
typedef HMODULE dll_t;
|
||||
|
@ -75,6 +77,7 @@ namespace pal
|
|||
#else
|
||||
typedef char char_t;
|
||||
typedef std::string string_t;
|
||||
typedef std::stringstream stringstream_t;
|
||||
typedef std::ifstream ifstream_t;
|
||||
typedef long hresult_t;
|
||||
typedef void* dll_t;
|
||||
|
|
|
@ -7,6 +7,7 @@ bool ends_with(const pal::string_t& value, const pal::string_t& suffix);
|
|||
pal::string_t get_executable(const pal::string_t& filename);
|
||||
pal::string_t get_directory(const pal::string_t& path);
|
||||
pal::string_t get_filename(const pal::string_t& path);
|
||||
bool find_coreclr(const pal::string_t& appbase, pal::string_t& recv);
|
||||
void append_path(pal::string_t& path1, const pal::char_t* path2);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
static pal::dll_t g_coreclr = nullptr;
|
||||
|
||||
// Prototype of the coreclr_initialize function from coreclr.dll
|
||||
typedef pal::hresult_t (*coreclr_initialize_fn)(
|
||||
typedef pal::hresult_t(*coreclr_initialize_fn)(
|
||||
const char* exePath,
|
||||
const char* appDomainFriendlyName,
|
||||
int propertyCount,
|
||||
|
@ -16,12 +16,12 @@ typedef pal::hresult_t (*coreclr_initialize_fn)(
|
|||
unsigned int* domainId);
|
||||
|
||||
// Prototype of the coreclr_shutdown function from coreclr.dll
|
||||
typedef pal::hresult_t (*coreclr_shutdown_fn)(
|
||||
typedef pal::hresult_t(*coreclr_shutdown_fn)(
|
||||
coreclr::host_handle_t hostHandle,
|
||||
unsigned int domainId);
|
||||
|
||||
// Prototype of the coreclr_execute_assembly function from coreclr.dll
|
||||
typedef pal::hresult_t (*coreclr_execute_assembly_fn)(
|
||||
typedef pal::hresult_t(*coreclr_execute_assembly_fn)(
|
||||
coreclr::host_handle_t hostHandle,
|
||||
unsigned int domainId,
|
||||
int argc,
|
||||
|
@ -40,7 +40,7 @@ bool coreclr::bind(const pal::string_t& libcoreclr_path)
|
|||
pal::string_t coreclr_dll_path(libcoreclr_path);
|
||||
append_path(coreclr_dll_path, LIBCORECLR_NAME);
|
||||
|
||||
if(!pal::load_library(coreclr_dll_path.c_str(), g_coreclr))
|
||||
if (!pal::load_library(coreclr_dll_path.c_str(), g_coreclr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -186,7 +186,11 @@ int main(const int argc, const pal::char_t* argv[])
|
|||
if (args.clr_path.empty())
|
||||
{
|
||||
// Use the directory containing the managed assembly
|
||||
args.clr_path = app_base;
|
||||
if (!find_coreclr(app_base, args.clr_path))
|
||||
{
|
||||
trace::error(_X("failed to locate CLR files"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pal::realpath(args.clr_path))
|
||||
|
@ -196,7 +200,6 @@ int main(const int argc, const pal::char_t* argv[])
|
|||
}
|
||||
|
||||
trace::info(_X("using CLR files from: %s"), args.clr_path.c_str());
|
||||
|
||||
trace::info(_X("preparing to launch: %s"), app_name.c_str());
|
||||
trace::info(_X("using app base: %s"), app_base.c_str());
|
||||
|
||||
|
|
|
@ -1,5 +1,44 @@
|
|||
#include "utils.h"
|
||||
|
||||
bool ends_with(const pal::string_t& value, const pal::string_t& suffix)
|
||||
{
|
||||
return (0 == value.compare(value.length() - suffix.length(), suffix.length(), suffix));
|
||||
}
|
||||
|
||||
bool find_coreclr(const pal::string_t& appbase, pal::string_t& recv)
|
||||
{
|
||||
pal::string_t candidate;
|
||||
// Check if it exists in the appbase
|
||||
candidate.assign(appbase);
|
||||
append_path(candidate, LIBCORECLR_NAME);
|
||||
if (pal::file_exists(candidate))
|
||||
{
|
||||
recv.assign(appbase);
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Have a cleaner search strategy that supports multiple versions
|
||||
// Search the PATH
|
||||
pal::string_t path;
|
||||
if (!pal::getenv(_X("PATH"), path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
pal::stringstream_t path_stream(path);
|
||||
pal::string_t entry;
|
||||
while (std::getline(path_stream, entry, PATH_SEPARATOR))
|
||||
{
|
||||
candidate.assign(entry);
|
||||
append_path(candidate, LIBCORECLR_NAME);
|
||||
if (pal::file_exists(candidate))
|
||||
{
|
||||
recv.assign(entry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void append_path(pal::string_t& path1, const pal::char_t* path2)
|
||||
{
|
||||
if (pal::is_path_rooted(path2))
|
||||
|
@ -29,11 +68,6 @@ pal::string_t get_executable(const pal::string_t& filename)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool ends_with(const pal::string_t& value, const pal::string_t& suffix)
|
||||
{
|
||||
return (0 == value.compare(value.length() - suffix.length(), suffix.length(), suffix));
|
||||
}
|
||||
|
||||
pal::string_t get_filename(const pal::string_t& path)
|
||||
{
|
||||
// Find the last dir separator
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace TestApp
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("This is a test app");
|
||||
Console.WriteLine(TestLibrary.Helper.GetMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
},
|
||||
|
||||
"dependencies": {
|
||||
"System.IO": "4.0.10-beta-23420",
|
||||
"TestLibrary": { "target": "project" },
|
||||
"System.IO": "4.0.11-beta-23420",
|
||||
"System.Console": "4.0.0-beta-23420",
|
||||
"System.Runtime": "4.0.20-beta-23420",
|
||||
"System.Runtime": "4.0.21-beta-23420",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23420",
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428"
|
||||
},
|
||||
|
|
12
test/TestLibrary/Helper.cs
Normal file
12
test/TestLibrary/Helper.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from the test library!";
|
||||
}
|
||||
}
|
||||
}
|
19
test/TestLibrary/TestLibrary.xproj
Normal file
19
test/TestLibrary/TestLibrary.xproj
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?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>947dd232-8d9b-4b78-9c6a-94f807d2dd58</ProjectGuid>
|
||||
<RootNamespace>TestLibrary</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>
|
11
test/TestLibrary/project.json
Normal file
11
test/TestLibrary/project.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {
|
||||
"System.Runtime": "4.0.21-beta-23420",
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue