Skip to content
Permalink
Browse files

Add ability to compile code from stdin (#41166)

  • Loading branch information
am11 committed Feb 13, 2020
1 parent 76bdeb8 commit f4f3aa7ce76f187713d121fff2c57fca98d955e1
Showing with 629 additions and 107 deletions.
  1. +9 −2 Compilers.sln
  2. +13 −2 src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
  3. +4 −1 src/Compilers/CSharp/Portable/CSharpResources.resx
  4. +25 −0 src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs
  5. +1 −1 src/Compilers/CSharp/Portable/CommandLine/CSharpCompiler.cs
  6. +2 −0 src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
  7. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
  8. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
  9. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
  10. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
  11. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
  12. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
  13. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
  14. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
  15. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
  16. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
  17. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
  18. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
  19. +6 −1 src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
  20. +169 −4 src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
  21. +10 −0 src/Compilers/CSharp/Test/CommandLine/Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests.csproj
  22. +1 −1 src/Compilers/Core/CodeAnalysisTest/Text/StringTextTest.cs
  23. +10 −2 src/Compilers/Core/Portable/CommandLine/CommandLineParser.cs
  24. +14 −13 src/Compilers/Core/Portable/CommandLine/CommandLineSourceFile.cs
  25. +8 −1 src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs
  26. +15 −12 src/Compilers/Core/Portable/EncodedStringText.cs
  27. +2 −0 src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
  28. +21 −11 src/Compilers/Core/Portable/Text/SourceText.cs
  29. +18 −0 src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCommandLineParser.vb
  30. +2 −0 src/Compilers/VisualBasic/Portable/Errors/Errors.vb
  31. +10 −1 src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
  32. +4 −1 src/Compilers/VisualBasic/Portable/VBResources.resx
  33. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf
  34. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf
  35. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf
  36. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf
  37. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf
  38. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf
  39. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf
  40. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf
  41. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf
  42. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf
  43. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf
  44. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf
  45. +6 −1 src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf
  46. +2 −2 src/Compilers/VisualBasic/Test/CommandLine/CommandLineTestResources.Designer.vb
  47. +123 −17 src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
  48. +1 −1 src/Compilers/VisualBasic/Test/CommandLine/My Project/Application.Designer.vb
  49. +2 −2 src/Compilers/VisualBasic/Test/CommandLine/My Project/Resources.Designer.vb
  50. +3 −3 src/Compilers/VisualBasic/Test/CommandLine/My Project/Settings.Designer.vb
  51. +1 −1 src/Scripting/VisualBasic/VisualBasicScriptCompiler.vb
  52. +3 −3 src/Test/Utilities/Portable/FX/ProcessUtilities.cs
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27102.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.UnitTests", "src\Compilers\Core\CodeAnalysisTest\Microsoft.CodeAnalysis.UnitTests.csproj", "{A4C99B85-765C-4C65-9C2A-BB609AAB09E6}"
EndProject
@@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildBoss", "src\Tools\Buil
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Net.Compilers.Toolset.Package", "src\NuGet\Microsoft.Net.Compilers.Toolset\Microsoft.Net.Compilers.Toolset.Package.csproj", "{6D407402-CC4A-4125-9B00-C70562A636A5}"
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "vbi", "src\Interactive\vbi\vbi.vbproj", "{706CFC25-B6E0-4DAA-BCC4-F6FAAFEEDF87}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
@@ -435,6 +437,10 @@ Global
{6D407402-CC4A-4125-9B00-C70562A636A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D407402-CC4A-4125-9B00-C70562A636A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D407402-CC4A-4125-9B00-C70562A636A5}.Release|Any CPU.Build.0 = Release|Any CPU
{706CFC25-B6E0-4DAA-BCC4-F6FAAFEEDF87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{706CFC25-B6E0-4DAA-BCC4-F6FAAFEEDF87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{706CFC25-B6E0-4DAA-BCC4-F6FAAFEEDF87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{706CFC25-B6E0-4DAA-BCC4-F6FAAFEEDF87}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -508,6 +514,7 @@ Global
{B446E771-AB52-41C9-ACFC-FDF8EACAF291} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC}
{8A02AFAF-F622-4E3E-9E1A-8CFDACC7C7E1} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC}
{6D407402-CC4A-4125-9B00-C70562A636A5} = {274B96B7-F815-47E3-9CA4-4024A57A478F}
{706CFC25-B6E0-4DAA-BCC4-F6FAAFEEDF87} = {3FF38FD4-DF16-44B0-924F-0D5AE155495B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6F599E08-A9EA-4FAA-897F-5D824B0210E6}

Some generated files are not rendered by default. Learn more.

@@ -5081,6 +5081,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_SwitchCaseSubsumed" xml:space="preserve">
<value>The switch case has already been handled by a previous case.</value>
</data>
<data name="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected" xml:space="preserve">
<value>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</value>
</data>
<data name="ERR_SwitchArmSubsumed" xml:space="preserve">
<value>The pattern has already been handled by a previous arm of the switch expression.</value>
</data>
@@ -5990,4 +5993,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_ImplicitRangeIndexerWithName" xml:space="preserve">
<value>Invocation of implicit Range Indexer cannot name the argument.</value>
</data>
</root>
</root>
@@ -224,6 +224,19 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
{
case "-": // csi -- script.csx
if (value != null) break;
if (arg == "-")
{
if (Console.IsInputRedirected)
{
sourceFiles.Add(new CommandLineSourceFile("-", isScript: true, isInputRedirected: true));
sourceFilesSpecified = true;
}
else
{
AddDiagnostic(diagnostics, ErrorCode.ERR_StdInOptionProvidedButConsoleInputIsNotRedirected);
}
continue;
}

// Indicates that the remaining arguments should not be treated as options.
optionsEnded = true;
@@ -1260,6 +1273,18 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
embeddedFiles.Add(ToCommandLineSourceFile(path));
}
continue;

case "-":
if (Console.IsInputRedirected)
{
sourceFiles.Add(new CommandLineSourceFile("-", isScript: false, isInputRedirected: true));
sourceFilesSpecified = true;
}
else
{
AddDiagnostic(diagnostics, ErrorCode.ERR_StdInOptionProvidedButConsoleInputIsNotRedirected);
}
continue;
}
}

@@ -109,7 +109,7 @@ protected CSharpCompiler(CSharpCommandLineParser parser, string responseFile, st
{
var normalizedFilePath = normalizedFilePaths[i];
Debug.Assert(normalizedFilePath != null);
Debug.Assert(PathUtilities.IsAbsolute(normalizedFilePath));
Debug.Assert(sourceFiles[i].IsInputRedirected || PathUtilities.IsAbsolute(normalizedFilePath));

if (!uniqueFilePaths.Add(normalizedFilePath))
{
@@ -1756,6 +1756,8 @@ internal enum ErrorCode

WRN_DoesNotReturnMismatch = 8770,

ERR_StdInOptionProvidedButConsoleInputIsNotRedirected = 8782,

// Note: you will need to re-generate compiler code after adding warnings (eng\generate-compiler-code.cmd)
}
}
@@ -432,6 +432,11 @@
<target state="translated">Statický člen {0} se nedá označit modifikátorem readonly.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">Tento vzor už zpracovala předchozí větev výrazu switch.</target>
@@ -9845,4 +9850,4 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">Der statische Member "{0}" kann nicht als "readonly" markiert werden.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">Das Muster wurde bereits durch einen vorherigen Zweig des switch-Ausdrucks verarbeitet.</target>
@@ -9845,4 +9850,4 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">El miembro estático "{0}" no se puede marcar como "readonly".</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">El patrón ya se ha controlado con una parte anterior de la expresión switch.</target>
@@ -9845,4 +9850,4 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">Le membre statique '{0}' ne peut pas être marqué 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">Le modèle a déjà été traité par un bras précédent de l'expression switch.</target>
@@ -9845,4 +9850,4 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">Il membro statico '{0}' non può essere contrassegnato come 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">Il criterio è già stato gestito da un elemento precedente dell'espressione switch.</target>
@@ -9845,4 +9850,4 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">静的メンバー '{0}' を 'readonly' とマークすることはできません。</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">このパターンは、switch 式の前の arm で既に処理されています。</target>
@@ -9845,4 +9850,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">정적 멤버 '{0}'을(를) 'readonly'로 표시할 수 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">패턴이 switch 식의 이전 arm에 의해 이미 처리되었습니다.</target>
@@ -9845,4 +9850,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">Składowa statyczna „{0}” nie może być oznaczona jako „readonly”.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">Wzorzec został już obsłużony przez poprzednie rozgałęzienie wyrażenia switch.</target>
@@ -9845,4 +9850,4 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">O membro estático '{0}' não pode ser marcado como 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">O padrão já foi manipulado por um braço anterior da expressão switch.</target>
@@ -9843,4 +9848,4 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">Статический член "{0}" не может быть помечен как readonly.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">Шаблон уже был обработан предыдущей стороной выражения switch.</target>
@@ -9845,4 +9850,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">'{0}' statik üyesi 'readonly' olarak işaretlenemez.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">Desen zaten switch deyiminin önceki bir kolu tarafından işlendi.</target>
@@ -9845,4 +9850,4 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T
</trans-unit>
</body>
</file>
</xliff>
</xliff>
@@ -432,6 +432,11 @@
<target state="translated">静态成员 "{0}" 不能标记为 "readonly"。</target>
<note />
</trans-unit>
<trans-unit id="ERR_StdInOptionProvidedButConsoleInputIsNotRedirected">
<source>stdin argument '-' is specified, but input has not been redirected from the standard input stream.</source>
<target state="new">stdin argument '-' is specified, but input has not been redirected from the standard input stream.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
<source>The pattern has already been handled by a previous arm of the switch expression.</source>
<target state="translated">该模式已由 switch 表达式的前一个 arm 处理。</target>
@@ -9845,4 +9850,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
</trans-unit>
</body>
</file>
</xliff>
</xliff>

0 comments on commit f4f3aa7

Please sign in to comment.
You can’t perform that action at this time.