From 0d89428bce7d546a02be744cc6eb776870683895 Mon Sep 17 00:00:00 2001 From: Enrico Sada Date: Thu, 25 May 2017 01:42:52 +0200 Subject: [PATCH 1/3] add failing test --- .../WriteCodeFragment_Tests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Tasks.UnitTests/WriteCodeFragment_Tests.cs b/src/Tasks.UnitTests/WriteCodeFragment_Tests.cs index 67028d33b09..d21605d2f94 100644 --- a/src/Tasks.UnitTests/WriteCodeFragment_Tests.cs +++ b/src/Tasks.UnitTests/WriteCodeFragment_Tests.cs @@ -641,6 +641,32 @@ public void OneAttributePositionalAndNamedParamsVisualBasic() File.Delete(task.OutputFile.ItemSpec); } + /// + /// Test with the VB language + /// + [Fact] + [Trait("Category", "mono-osx-failing")] + [Trait("Category", "fsharp")] + public void OneAttributeNoParamsFSharp() + { + WriteCodeFragment task = new WriteCodeFragment(); + MockEngine engine = new MockEngine(true); + task.BuildEngine = engine; + TaskItem attribute = new TaskItem("System.AssemblyTrademarkAttribute"); + task.AssemblyAttributes = new TaskItem[] { attribute }; + task.Language = "f#"; + task.OutputDirectory = new TaskItem(Path.GetTempPath()); + bool result = task.Execute(); + + Assert.Equal(true, result); + + string content = File.ReadAllText(task.OutputFile.ItemSpec); + Console.WriteLine(content); + + CheckContentFSharp(content, "[]"); + } + + private static void CheckContentCSharp(string actualContent, params string[] expectedAttributes) { CheckContent( @@ -663,6 +689,16 @@ private static void CheckContentVB(string actualContent, params string[] expecte "Imports System.Reflection"); } + private static void CheckContentFSharp(string actualContent, params string[] expectedAttributes) + { + CheckContent( + actualContent, + expectedAttributes, + "//", + "open System", + "open System.Reflection"); + } + private static void CheckContent(string actualContent, string[] expectedAttributes, string commentStart, params string[] expectedHeader) { string expectedContent = string.Join(Environment.NewLine, expectedHeader.Concat(expectedAttributes)); From b847b7022219434502e46daf4483bebb63f80d79 Mon Sep 17 00:00:00 2001 From: Enrico Sada Date: Thu, 25 May 2017 01:57:06 +0200 Subject: [PATCH 2/3] no codedom for F#, fallback to coreclr codegen --- src/Tasks/WriteCodeFragment.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Tasks/WriteCodeFragment.cs b/src/Tasks/WriteCodeFragment.cs index d55298099a8..10f64c1f601 100644 --- a/src/Tasks/WriteCodeFragment.cs +++ b/src/Tasks/WriteCodeFragment.cs @@ -152,6 +152,12 @@ public override bool Execute() [SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.IO.StringWriter.#ctor(System.Text.StringBuilder)", Justification = "Reads fine to me")] private string GenerateCode(out string extension) { + if (Language.ToLowerInvariant() == "f#") + { + //no codedoom for F#, fallback to coreclr version + return GenerateCodeCoreClr(out extension); + } + extension = null; bool haveGeneratedContent = false; From 9e94c65275d3f5c683b9158725226de2acc26d4e Mon Sep 17 00:00:00 2001 From: Enrico Sada Date: Thu, 25 May 2017 02:03:21 +0200 Subject: [PATCH 3/3] add f# codegen --- src/Tasks/WriteCodeFragment.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Tasks/WriteCodeFragment.cs b/src/Tasks/WriteCodeFragment.cs index 10f64c1f601..2d85d5fe4bf 100644 --- a/src/Tasks/WriteCodeFragment.cs +++ b/src/Tasks/WriteCodeFragment.cs @@ -339,6 +339,32 @@ private string GenerateCodeCoreClr(out string extension) code.AppendLine(string.Format($"")); haveGeneratedContent = true; } + break; + case "f#": + if (AssemblyAttributes == null) return string.Empty; + + extension = "fs"; + code.AppendLine("// " + ResourceUtilities.FormatResourceString("WriteCodeFragment.Comment")); + code.AppendLine(); + code.AppendLine("open System"); + code.AppendLine("open System.Reflection"); + code.AppendLine(); + + foreach (ITaskItem attributeItem in AssemblyAttributes) + { + string args = GetAttributeArguments(attributeItem, "=", QuoteSnippetStringCSharp); + if (args == null) return null; + + code.AppendLine(string.Format($"[]")); + haveGeneratedContent = true; + } + + if (haveGeneratedContent) + { + code.AppendLine("()"); + code.AppendLine(); + } + break; default: Log.LogErrorWithCodeFromResources("WriteCodeFragment.CouldNotCreateProvider", Language, string.Empty);