Changes to fix publish tests
This commit is contained in:
parent
9c5e520285
commit
d1d23944df
12 changed files with 124 additions and 140 deletions
|
@ -20,30 +20,9 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static string EscapeAndConcatenateArgArray(IEnumerable<string> args, bool cmd=false)
|
||||
public static string EscapeAndConcatenateArgArray(IEnumerable<string> args)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var first = false;
|
||||
|
||||
foreach (var arg in args)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(' ');
|
||||
}
|
||||
sb.Append(EscapeArg(arg, cmd));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string EscapeAndConcatenateArgArrayForBash(IEnumerable<string> args)
|
||||
{
|
||||
return EscapeAndConcatenateArgArray(EscapeArgArrayForBash(args));
|
||||
return string.Join(" ", EscapeArgArray(args));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -57,7 +36,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
/// <returns></returns>
|
||||
public static string EscapeAndConcatenateArgArrayForCmd(IEnumerable<string> args)
|
||||
{
|
||||
return EscapeAndConcatenateArgArray(EscapeArgArrayForCmd(args), true);
|
||||
return string.Join(" ", EscapeArgArrayForCmd(args));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -81,18 +60,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
return escapedArgs;
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EscapeArgArrayForBash(IEnumerable<string> arguments)
|
||||
{
|
||||
var escapedArgs = new List<string>();
|
||||
|
||||
foreach (var arg in arguments)
|
||||
{
|
||||
escapedArgs.Add(EscapeArgForBash(arg));
|
||||
}
|
||||
|
||||
return escapedArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This prefixes every character with the '^' character to force cmd to
|
||||
/// interpret the argument string literally. An alternative option would
|
||||
|
@ -115,16 +82,13 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
return escapedArgs;
|
||||
}
|
||||
|
||||
private static string EscapeArg(string arg, bool cmd=false)
|
||||
private static string EscapeArg(string arg)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// Always quote beginning and end to account for possible spaces
|
||||
if (cmd) sb.Append('^');
|
||||
sb.Append('"');
|
||||
var quoted = ShouldSurroundWithQuotes(arg);
|
||||
if (quoted) sb.Append("\"");
|
||||
|
||||
if (!cmd)
|
||||
{
|
||||
for (int i = 0; i < arg.Length; ++i)
|
||||
{
|
||||
var backslashCount = 0;
|
||||
|
@ -158,35 +122,12 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
sb.Append(arg[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < arg.Length; ++i)
|
||||
{
|
||||
if (arg[i] == '"')
|
||||
{
|
||||
sb.Append('"');
|
||||
sb.Append('^');
|
||||
sb.Append(arg[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(arg[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd) sb.Append('^');
|
||||
sb.Append('"');
|
||||
if (quoted) sb.Append("\"");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static string EscapeArgForBash(string arguments)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepare as single argument to
|
||||
/// roundtrip properly through cmd.
|
||||
|
@ -200,17 +141,66 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
private static string EscapeArgForCmd(string arguments)
|
||||
private static string EscapeArgForCmd(string argument)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
foreach (var character in arguments)
|
||||
var quoted = ShouldSurroundWithQuotes(argument);
|
||||
|
||||
if (quoted) sb.Append("^\"");
|
||||
|
||||
foreach (var character in argument)
|
||||
{
|
||||
|
||||
if (character == '"')
|
||||
{
|
||||
|
||||
sb.Append('^');
|
||||
sb.Append('"');
|
||||
sb.Append('^');
|
||||
sb.Append(character);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("^");
|
||||
sb.Append(character);
|
||||
}
|
||||
}
|
||||
|
||||
if (quoted) sb.Append("^\"");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepare as single argument to
|
||||
/// roundtrip properly through cmd.
|
||||
///
|
||||
/// This prefixes every character with the '^' character to force cmd to
|
||||
/// interpret the argument string literally. An alternative option would
|
||||
/// be to do this only for cmd metacharacters.
|
||||
///
|
||||
/// See here for more info:
|
||||
/// http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool ShouldSurroundWithQuotes(string argument)
|
||||
{
|
||||
// Don't quote already quoted strings
|
||||
if (argument.StartsWith("\"", StringComparison.Ordinal) &&
|
||||
argument.EndsWith("\"", StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only quote if whitespace exists in the string
|
||||
if (argument.Contains(" ") || argument.Contains("\t") || argument.Contains("\n"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
private static CommandSpec ResolveFromPath(string commandName, IEnumerable<string> args, bool useComSpec = false)
|
||||
{
|
||||
var commandPath = Env.GetCommandPath(commandName);
|
||||
if (commandPath != null) Console.WriteLine("path?");
|
||||
return commandPath == null
|
||||
? null
|
||||
: CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.Path, useComSpec);
|
||||
|
@ -33,7 +32,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
private static CommandSpec ResolveFromAppBase(string commandName, IEnumerable<string> args, bool useComSpec = false)
|
||||
{
|
||||
var commandPath = Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, commandName);
|
||||
if (commandPath != null) Console.WriteLine("appbase?");
|
||||
return commandPath == null
|
||||
? null
|
||||
: CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.BaseDirectory, useComSpec);
|
||||
|
@ -43,8 +41,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
{
|
||||
if (Path.IsPathRooted(commandName))
|
||||
{
|
||||
Console.WriteLine("rooted?");
|
||||
|
||||
if (useComSpec)
|
||||
{
|
||||
return CreateComSpecCommandSpec(commandName, args, CommandResolutionStrategy.Path);
|
||||
|
@ -196,8 +192,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
fileName = Path.Combine(packageDir, commandPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (useComSpec)
|
||||
{
|
||||
return CreateComSpecCommandSpec(fileName, args, CommandResolutionStrategy.NugetPackage);
|
||||
|
@ -256,7 +250,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
IEnumerable<string> args,
|
||||
CommandResolutionStrategy resolutionStrategy)
|
||||
{
|
||||
|
||||
// To prevent Command Not Found, comspec gets passed in as
|
||||
// the command already in some cases
|
||||
var comSpec = Environment.GetEnvironmentVariable("ComSpec");
|
||||
|
@ -266,7 +259,13 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
args = args.Skip(1);
|
||||
}
|
||||
var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmd(args);
|
||||
var escapedArgString = $"/s /c \"\"{command}\" {cmdEscapedArgs}\"";
|
||||
|
||||
if (ArgumentEscaper.ShouldSurroundWithQuotes(command))
|
||||
{
|
||||
command = $"\"{command}\"";
|
||||
}
|
||||
|
||||
var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\"";
|
||||
|
||||
return new CommandSpec(comSpec, escapedArgString, resolutionStrategy);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
var scriptArguments = CommandGrammar.Process(
|
||||
scriptCommandLine,
|
||||
GetScriptVariable(project, getVariable),
|
||||
preserveSurroundingQuotes: false);
|
||||
preserveSurroundingQuotes: true);
|
||||
|
||||
// Ensure the array won't be empty and the elements won't be null or empty strings.
|
||||
scriptArguments = scriptArguments.Where(argument => !string.IsNullOrEmpty(argument)).ToArray();
|
||||
|
@ -59,12 +59,14 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
else
|
||||
{
|
||||
// Special-case a script name that, perhaps with added .sh, matches an existing file.
|
||||
var surroundWithQuotes = false;
|
||||
var scriptCandidate = scriptArguments[0];
|
||||
if (scriptCandidate.StartsWith("\"", StringComparison.Ordinal) &&
|
||||
scriptCandidate.EndsWith("\"", StringComparison.Ordinal))
|
||||
{
|
||||
// Strip surrounding quotes; they were required in project.json to keep the script name
|
||||
// together but confuse File.Exists() e.g. "My Script", lacking ./ prefix and .sh suffix.
|
||||
surroundWithQuotes = true;
|
||||
scriptCandidate = scriptCandidate.Substring(1, scriptCandidate.Length - 2);
|
||||
}
|
||||
|
||||
|
@ -78,22 +80,16 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
// scriptCandidate may be a path relative to the project root. If so, likely will not be found
|
||||
// in the $PATH; add ./ to let bash know where to look.
|
||||
var prefix = Path.IsPathRooted(scriptCandidate) ? string.Empty : "./";
|
||||
scriptArguments[0] = $"{prefix}{scriptCandidate}";
|
||||
var quote = surroundWithQuotes ? "\"" : string.Empty;
|
||||
scriptArguments[0] = $"{ quote }{ prefix }{ scriptCandidate }{ quote }";
|
||||
}
|
||||
|
||||
// Always use /usr/bin/env bash -c in order to support redirection and so on; similar to Windows case.
|
||||
// Unlike Windows, must escape quotation marks within the newly-quoted string.
|
||||
|
||||
// TODO change this back to original, not doing anything special for bash
|
||||
var bashArgs = ArgumentEscaper.EscapeArgArrayForBash(scriptArguments);
|
||||
|
||||
List<string> concatenatedArgs = new List<string>();
|
||||
concatenatedArgs.Add("/usr/bin/env");
|
||||
concatenatedArgs.Add("bash");
|
||||
concatenatedArgs.Add("-c");
|
||||
concatenatedArgs.AddRange(bashArgs);
|
||||
|
||||
scriptArguments = concatenatedArgs.ToArray();
|
||||
scriptArguments = new[] { "/usr/bin/env", "bash", "-c", "\"" }
|
||||
.Concat(scriptArguments.Select(argument => argument.Replace("\"", "\\\"")))
|
||||
.Concat(new[] { "\"" })
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
return Command.Create(scriptArguments.FirstOrDefault(), scriptArguments.Skip(1), useComSpec: useComSpec)
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
var existingAttributes = new List<Type>();
|
||||
foreach (var sourceFile in sourceFiles)
|
||||
{
|
||||
var tree = CSharpSyntaxTree.ParseText(File.ReadAllText(sourceFile));
|
||||
var tree = CSharpSyntaxTree.ParseText(File.ReadAllText(sourceFile.Trim('"')));
|
||||
var root = tree.GetRoot();
|
||||
|
||||
// assembly attributes can be only on first level
|
||||
|
|
|
@ -125,7 +125,7 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
|
||||
if (!newInputs.Any())
|
||||
{
|
||||
Reporter.Output.WriteLine($"\nProject {project.ProjectName()} was previoulsy compiled. Skipping compilation.");
|
||||
Reporter.Output.WriteLine($"\nProject {project.ProjectName()} was previously compiled. Skipping compilation.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,26 +79,28 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
|||
return returnCode;
|
||||
}
|
||||
|
||||
var translated = TranslateCommonOptions(commonOptions, outputName);
|
||||
var translated = TranslateCommonOptions(commonOptions, outputName.Trim('"'));
|
||||
|
||||
var allArgs = new List<string>(translated);
|
||||
allArgs.AddRange(GetDefaultOptions());
|
||||
|
||||
// Generate assembly info
|
||||
var assemblyInfo = Path.Combine(tempOutDir, $"dotnet-compile.assemblyinfo.cs");
|
||||
var tempOutputStrippedSpaces = tempOutDir.Trim('"');
|
||||
var assemblyInfo = Path.Combine(tempOutputStrippedSpaces, $"dotnet-compile.assemblyinfo.cs");
|
||||
|
||||
File.WriteAllText(assemblyInfo, AssemblyInfoFileGenerator.Generate(assemblyInfoOptions, sources));
|
||||
allArgs.Add($"\"{assemblyInfo}\"");
|
||||
|
||||
if (outputName != null)
|
||||
{
|
||||
allArgs.Add($"-out:\"{outputName}\"");
|
||||
allArgs.Add($"-out:\"{outputName.Trim('"')}\"");
|
||||
}
|
||||
|
||||
allArgs.AddRange(references.Select(r => $"-r:\"{r.Trim('"')}\""));
|
||||
allArgs.AddRange(resources.Select(resource => $"-resource:{resource.Trim('"')}"));
|
||||
allArgs.AddRange(sources.Select(s => $"\"{s.Trim('"')}\""));
|
||||
|
||||
var rsp = Path.Combine(tempOutDir, "dotnet-compile-csc.rsp");
|
||||
var rsp = Path.Combine(tempOutputStrippedSpaces, "dotnet-compile-csc.rsp");
|
||||
|
||||
File.WriteAllLines(rsp, allArgs, Encoding.UTF8);
|
||||
|
||||
|
@ -192,7 +194,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
|||
|
||||
if (options.GenerateXmlDocumentation == true)
|
||||
{
|
||||
commonArgs.Add($"-doc:{Path.ChangeExtension(outputName, "xml")}");
|
||||
commonArgs.Add($"-doc:\"{Path.ChangeExtension(outputName.Trim('"'), "xml")}\"");
|
||||
}
|
||||
|
||||
if (options.EmitEntryPoint != true)
|
||||
|
|
|
@ -207,8 +207,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
// Assemble args
|
||||
var compilerArgs = new List<string>()
|
||||
{
|
||||
$"--temp-output:{intermediateOutputPath}",
|
||||
$"--out:{outputName}"
|
||||
$"--temp-output:\"{intermediateOutputPath}\"",
|
||||
$"--out:\"{outputName}\""
|
||||
};
|
||||
|
||||
var compilationOptions = CompilerUtil.ResolveCompilationOptions(context, args.ConfigValue);
|
||||
|
@ -258,7 +258,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
writer.Write(dependencyContext, fileStream);
|
||||
}
|
||||
|
||||
compilerArgs.Add($"--resource:\"{depsJsonFile}\",{context.ProjectFile.Name}.deps.json");
|
||||
compilerArgs.Add($"--resource:\"{depsJsonFile},{context.ProjectFile.Name}.deps.json\"");
|
||||
|
||||
var refsFolder = Path.Combine(outputPath, "refs");
|
||||
if (Directory.Exists(refsFolder))
|
||||
|
@ -440,11 +440,11 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
return false;
|
||||
}
|
||||
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.OutputFile}\",{Path.GetFileName(resgenFile.MetadataName)}");
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.OutputFile},{Path.GetFileName(resgenFile.MetadataName)}\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.InputFile}\",{Path.GetFileName(resgenFile.MetadataName)}");
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.InputFile},{Path.GetFileName(resgenFile.MetadataName)}\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"dependencies": {
|
||||
"Newtonsoft.Json": "7.0.1",
|
||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-16023",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-16011",
|
||||
"NETStandard.Library": "1.0.0-rc2-23704",
|
||||
"System.Resources.ResourceManager": "4.0.1-rc2-23704",
|
||||
"System.Runtime.Serialization.Primitives": "4.1.0-rc2-23704"
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"Microsoft.FSharp.Core.netcore": "1.0.0-alpha-151221",
|
||||
"Microsoft.NETCore.ConsoleHost": "1.0.0-23428",
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-23428",
|
||||
"System.Console": "4.0.0-beta-23109"
|
||||
"Microsoft.NETCore.ConsoleHost": "1.0.0-rc2-23704",
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-rc2-23704",
|
||||
"System.Console": "4.0.0-rc2-23704"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
|
||||
protected static void AssertProjectSkipped(string skippedProject, CommandResult buildResult)
|
||||
{
|
||||
Assert.Contains($"Project {skippedProject} was previoulsy compiled. Skipping compilation.", buildResult.StdOut, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains($"Project {skippedProject} was previously compiled. Skipping compilation.", buildResult.StdOut, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
protected static void AssertProjectCompiled(string rebuiltProject, CommandResult buildResult)
|
||||
|
|
|
@ -45,9 +45,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
var commandPath = Env.GetCommandPath(_command, ".exe", ".cmd", "") ??
|
||||
Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, _command, ".exe", ".cmd", "");
|
||||
|
||||
Console.Write("command");
|
||||
Console.WriteLine(commandPath);
|
||||
|
||||
var stdOut = new StreamForwarder();
|
||||
var stdErr = new StreamForwarder();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
},
|
||||
|
||||
"dependencies": {
|
||||
"TestLibrary": "1.0.0-*",
|
||||
"TestLibrary": { "target":"project"},
|
||||
|
||||
"NETStandard.Library": "1.0.0-rc2-23704",
|
||||
"Microsoft.NETCore.Platforms": "1.0.1-rc2-23704"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue