From b1885eaa589bf2e888efa2cf2b7c4661adeebce8 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 17 Feb 2016 16:32:33 -0800 Subject: [PATCH] Cleanup all the Trims everywhere. csc is the only program which requires response files to have quotes. additional cleanup --- .../AssemblyInfoFileGenerator.cs | 2 +- .../commands/dotnet-compile-csc/Program.cs | 24 +++++++++++-------- .../commands/dotnet-compile-fsc/Program.cs | 9 +++---- .../commands/dotnet-compile/Compiler.cs | 10 ++++---- .../dotnet-compile/ManagedCompiler.cs | 12 +++++----- .../commands/dotnet-resgen/ResgenCommand.cs | 14 ++--------- 6 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index 96f07be9b..ab24413fb 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common var existingAttributes = new List(); foreach (var sourceFile in sourceFiles) { - var tree = CSharpSyntaxTree.ParseText(File.ReadAllText(sourceFile.Trim('"'))); + var tree = CSharpSyntaxTree.ParseText(File.ReadAllText(sourceFile)); var root = tree.GetRoot(); // assembly attributes can be only on first level diff --git a/src/dotnet/commands/dotnet-compile-csc/Program.cs b/src/dotnet/commands/dotnet-compile-csc/Program.cs index 07cae9fe4..0053649f8 100644 --- a/src/dotnet/commands/dotnet-compile-csc/Program.cs +++ b/src/dotnet/commands/dotnet-compile-csc/Program.cs @@ -82,29 +82,33 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc return returnCode; } - var translated = TranslateCommonOptions(commonOptions, outputName.Trim('"')); + var translated = TranslateCommonOptions(commonOptions, outputName); var allArgs = new List(translated); allArgs.AddRange(GetDefaultOptions()); // Generate assembly info - var tempOutputStrippedSpaces = tempOutDir.Trim('"'); - var assemblyInfo = Path.Combine(tempOutputStrippedSpaces, $"dotnet-compile.assemblyinfo.cs"); + var assemblyInfo = Path.Combine(tempOutDir, $"dotnet-compile.assemblyinfo.cs"); File.WriteAllText(assemblyInfo, AssemblyInfoFileGenerator.Generate(assemblyInfoOptions, sources)); allArgs.Add($"\"{assemblyInfo}\""); if (outputName != null) { - allArgs.Add($"-out:\"{outputName.Trim('"')}\""); + allArgs.Add($"-out:\"{outputName}\""); } - allArgs.AddRange(analyzers.Select(a => $"-a:\"{a.Trim('"')}\"")); - allArgs.AddRange(references.Select(r => $"-r:\"{r.Trim('"')}\"")); - allArgs.AddRange(resources.Select(resource => $"-resource:{resource}")); - allArgs.AddRange(sources.Select(s => $"\"{s.Trim('"')}\"")); + allArgs.AddRange(analyzers.Select(a => $"-a:\"{a}\"")); + allArgs.AddRange(references.Select(r => $"-r:\"{r}\"")); - var rsp = Path.Combine(tempOutputStrippedSpaces, "dotnet-compile-csc.rsp"); + // Resource has two parts separated by a comma + // Only the first should be quoted. This is handled + // in dotnet-compile where the information is present. + allArgs.AddRange(resources.Select(resource => $"-resource:{resource}")); + + allArgs.AddRange(sources.Select(s => $"\"{s}\"")); + + var rsp = Path.Combine(tempOutDir, "dotnet-compile-csc.rsp"); File.WriteAllLines(rsp, allArgs, Encoding.UTF8); @@ -204,7 +208,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc if (options.GenerateXmlDocumentation == true) { - commonArgs.Add($"-doc:\"{Path.ChangeExtension(outputName.Trim('"'), "xml")}\""); + commonArgs.Add($"-doc:{Path.ChangeExtension(outputName, "xml")}"); } if (options.EmitEntryPoint != true) diff --git a/src/dotnet/commands/dotnet-compile-fsc/Program.cs b/src/dotnet/commands/dotnet-compile-fsc/Program.cs index 3dfff1547..3ae5d8ed3 100644 --- a/src/dotnet/commands/dotnet-compile-fsc/Program.cs +++ b/src/dotnet/commands/dotnet-compile-fsc/Program.cs @@ -80,9 +80,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Fsc return returnCode; } - outputName = outputName.Trim('"'); - tempOutDir = tempOutDir.Trim('"'); - var translated = TranslateCommonOptions(commonOptions, outputName); var allArgs = new List(translated); @@ -115,9 +112,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Fsc allArgs.Add("--targetprofile:netcore"); } - allArgs.AddRange(references.Select(r => $"-r:{r.Trim('"')}")); - allArgs.AddRange(resources.Select(resource => $"--resource:{resource.Trim('"')}")); - allArgs.AddRange(sources.Select(s => $"{s.Trim('"')}")); + allArgs.AddRange(references.Select(r => $"-r:{r}")); + allArgs.AddRange(resources.Select(resource => $"--resource:{resource}")); + allArgs.AddRange(sources.Select(s => $"{s}")); var rsp = Path.Combine(tempOutDir, "dotnet-compile-fsc.rsp"); File.WriteAllLines(rsp, allArgs, Encoding.UTF8); diff --git a/src/dotnet/commands/dotnet-compile/Compiler.cs b/src/dotnet/commands/dotnet-compile/Compiler.cs index fbb10b0d6..95da10afc 100644 --- a/src/dotnet/commands/dotnet-compile/Compiler.cs +++ b/src/dotnet/commands/dotnet-compile/Compiler.cs @@ -56,8 +56,8 @@ namespace Microsoft.DotNet.Tools.Compiler { var arguments = new[] { - $"\"{resgenFile.InputFile}\"", - $"-o:\"{resgenFile.OutputFile}\"", + $"{resgenFile.InputFile}", + $"-o:{resgenFile.OutputFile}", $"-v:{project.Version.Version}" }; @@ -89,7 +89,7 @@ namespace Microsoft.DotNet.Tools.Compiler string outputPath) { var referencePaths = CompilerUtil.GetReferencePathsForCultureResgen(dependencies); - var resgenReferenceArgs = referencePaths.Select(path => $"-r:\"{path}\"").ToList(); + var resgenReferenceArgs = referencePaths.Select(path => $"-r:{path}").ToList(); var cultureResgenFiles = CompilerUtil.GetCultureResources(project, outputPath); foreach (var resgenFile in cultureResgenFiles) @@ -104,10 +104,10 @@ namespace Microsoft.DotNet.Tools.Compiler var arguments = new List(); arguments.AddRange(resgenReferenceArgs); - arguments.Add($"-o:\"{resgenFile.OutputFile}\""); + arguments.Add($"-o:{resgenFile.OutputFile}"); arguments.Add($"-c:{resgenFile.Culture}"); arguments.Add($"-v:{project.Version.Version}"); - arguments.AddRange(resgenFile.InputFileToMetadata.Select(fileToMetadata => $"\"{fileToMetadata.Key}\",{fileToMetadata.Value}")); + arguments.AddRange(resgenFile.InputFileToMetadata.Select(fileToMetadata => $"{fileToMetadata.Key},{fileToMetadata.Value}")); var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen.rsp"); File.WriteAllLines(rsp, arguments); diff --git a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs index e74f8df85..722f70382 100644 --- a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs +++ b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs @@ -72,8 +72,8 @@ namespace Microsoft.DotNet.Tools.Compiler // Assemble args var compilerArgs = new List() { - $"--temp-output:\"{intermediateOutputPath}\"", - $"--out:\"{outputName}\"" + $"--temp-output:{intermediateOutputPath}", + $"--out:{outputName}" }; var compilationOptions = CompilerUtil.ResolveCompilationOptions(context, args.ConfigValue); @@ -90,15 +90,15 @@ namespace Microsoft.DotNet.Tools.Compiler foreach (var dependency in dependencies) { references.AddRange(dependency.CompilationAssemblies.Select(r => r.ResolvedPath)); - compilerArgs.AddRange(dependency.SourceReferences.Select(s => $"\"{s}\"")); + compilerArgs.AddRange(dependency.SourceReferences.Select(s => $"{s}")); // Add analyzer references compilerArgs.AddRange(dependency.AnalyzerReferences .Where(a => a.AnalyzerLanguage == languageId) - .Select(a => $"--analyzer:\"{a.AssemblyPath}\"")); + .Select(a => $"--analyzer:{a.AssemblyPath}")); } - compilerArgs.AddRange(references.Select(r => $"--reference:\"{r}\"")); + compilerArgs.AddRange(references.Select(r => $"--reference:{r}")); if (compilationOptions.PreserveCompilationContext == true) { @@ -115,7 +115,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"); } if (!AddNonCultureResources(context.ProjectFile, compilerArgs, intermediateOutputPath)) diff --git a/src/dotnet/commands/dotnet-resgen/ResgenCommand.cs b/src/dotnet/commands/dotnet-resgen/ResgenCommand.cs index 702761536..594d51b2f 100644 --- a/src/dotnet/commands/dotnet-resgen/ResgenCommand.cs +++ b/src/dotnet/commands/dotnet-resgen/ResgenCommand.cs @@ -20,13 +20,7 @@ namespace Microsoft.DotNet.Tools.Resgen public int Execute() { var inputResourceFiles = Args.Select(ParseInputFile).ToArray(); - var outputResourceFile = ResourceFile.Create(OutputFileName.Trim('"')); - - var trimmedCompilationReferences = default(string[]); - if (CompilationReferences != null) - { - trimmedCompilationReferences = CompilationReferences.Select(r => r.Trim('"')).ToArray(); - } + var outputResourceFile = ResourceFile.Create(OutputFileName); switch (outputResourceFile.Type) { @@ -43,7 +37,7 @@ namespace Microsoft.DotNet.Tools.Resgen outputStream, metadata, Path.GetFileNameWithoutExtension(outputResourceFile.File.Name), - trimmedCompilationReferences + CompilationReferences.ToArray() ); } break; @@ -82,10 +76,6 @@ namespace Microsoft.DotNet.Tools.Resgen metadataName = arg; } - // Remove surrounding quotes - name = name.Trim('"'); - metadataName = metadataName.Trim('"'); - return new ResourceSource(ResourceFile.Create(name), metadataName); } }