Skip to content

Commit 072d731

Browse files
authored
Merge pull request #8103 from dotnet/merges/master-to-release/dev16.5
Merge master to release/dev16.5
2 parents 50c6465 + 99c5a49 commit 072d731

26 files changed

+784
-203
lines changed

FSharpBuild.Directory.Build.targets

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<Project>
2+
23
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
34
<Import Project="eng\targets\Imports.targets" />
45
<Import Project="eng\targets\NuGet.targets" />
@@ -8,7 +9,7 @@
89
<Target Name="NoneSubstituteTextFiles"
910
Inputs="@(NoneSubstituteText)"
1011
Outputs="@(NoneSubstituteText->'$(IntermediateOutputPath)%(Filename)%(Extension)')"
11-
BeforeTargets="AssignTargetPaths;BeforeBuild">
12+
BeforeTargets="AssignTargetPaths;BeforeBuild;GenerateFSharpTextResources">
1213

1314
<PropertyGroup>
1415
<__TargetFilePath>@(NoneSubstituteText->'$(IntermediateOutputPath)%(Filename)%(Extension)')</__TargetFilePath>
@@ -20,16 +21,19 @@
2021

2122
<_CopyToOutputDirectory Condition="'%(NoneSubstituteText.CopyToOutputDirectory)' != ''">%(NoneSubstituteText.CopyToOutputDirectory)</_CopyToOutputDirectory>
2223
<_CopyToOutputDirectory Condition="'%(NoneSubstituteText.CopyToOutputDirectory)' == ''">Never</_CopyToOutputDirectory>
24+
25+
<_IncludeInVsix>false</_IncludeInVsix>
26+
<_IncludeInVsix Condition="'%(NoneSubstituteText.IncludeInVsix)' == 'true'">true</_IncludeInVsix>
2327
</PropertyGroup>
2428

2529
<MakeDir Directories="$(IntermediateOutputPath)"
2630
Condition="!Exists('$(IntermediateOutputPath)')" />
2731
<WriteLinesToFile File="$(__TargetFilePath)" Lines="$(_ReplacementText)" Overwrite="true" WriteOnlyWhenDifferent="true" />
2832

29-
<!-- Make sure it will get cleaned -->
30-
<ItemGroup >
33+
<ItemGroup>
3134
<None Include="$(__TargetFilePath)" CopyToOutputDirectory="$(_CopyToOutputDirectory)" />
3235
<FileWrites Include="$(__TargetFilePath)" Condition="'$(__TargetFileName)' != 'App.config'" />
36+
<Content Include="$(__TargetFilePath)" CopyToOutputDirectory="Always" IncludeInVsix="true" />
3337
</ItemGroup>
3438
</Target>
3539

@@ -61,4 +65,27 @@
6165
</ItemGroup>
6266
</Target>
6367

68+
<Target Name="BeforeResGen"
69+
Inputs="@(EmbeddedResource->'$(IntermediateOutputPath)%(Filename)%(Extension)')"
70+
Outputs="@(EmbeddedResource->'$(IntermediateOutputPath)resources\%(Filename)%(Extension)')"
71+
DependsOnTargets="CopyVsixResources"
72+
Condition="'$(Configuration)' != 'Proto' and '$(Language)'=='F#' and '$(DisableCompilerRedirection)' != 'true' ">
73+
74+
<SubstituteText EmbeddedResources="@(EmbeddedResource)">
75+
<Output TaskParameter="CopiedFiles" ItemName="CopiedFiles" />
76+
</SubstituteText>
77+
78+
<ItemGroup>
79+
<EmbeddedResource Remove="@(EmbeddedResource)"/>
80+
<EmbeddedResource Include="@(CopiedFiles)"/>
81+
</ItemGroup>
82+
83+
<MakeDir Directories="$(IntermediateOutputPath)" Condition="!Exists('$(IntermediateOutputPath)')" />
84+
<MakeDir Directories="$(IntermediateOutputPath)resources\" Condition="!Exists('$(IntermediateOutputPath)resources\')" />
85+
</Target>
86+
87+
<Target Name="CopyVsixResources">
88+
<Copy SourceFiles="@(CopyVsixResources)" DestinationFolder="$(IntermediateOutputPath)\resources\Resources" />
89+
</Target>
90+
6491
</Project>

fcs/build.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ Target.create "Build" (fun _ ->
6666
runDotnet __SOURCE_DIRECTORY__ "build" "../src/buildtools/buildtools.proj -v n -c Proto"
6767
let fslexPath = __SOURCE_DIRECTORY__ + "/../artifacts/bin/fslex/Proto/netcoreapp2.1/fslex.dll"
6868
let fsyaccPath = __SOURCE_DIRECTORY__ + "/../artifacts/bin/fsyacc/Proto/netcoreapp2.1/fsyacc.dll"
69-
runDotnet __SOURCE_DIRECTORY__ "build" (sprintf "FSharp.Compiler.Service.sln -v n -c Release /p:FsLexPath=%s /p:FsYaccPath=%s" fslexPath fsyaccPath)
69+
runDotnet __SOURCE_DIRECTORY__ "build" (sprintf "FSharp.Compiler.Service.sln -nodereuse:false -v n -c Release /p:DisableCompilerRedirection=true /p:FsLexPath=%s /p:FsYaccPath=%s" fslexPath fsyaccPath)
7070
)
7171

7272
Target.create "Test" (fun _ ->
7373
// This project file is used for the netcoreapp2.0 tests to work out reference sets
74-
runDotnet __SOURCE_DIRECTORY__ "build" "../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj -v n /restore /p:DisableCompilerRedirection=true"
74+
runDotnet __SOURCE_DIRECTORY__ "build" "../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj -nodereuse:false -v n /restore /p:DisableCompilerRedirection=true"
7575

7676
// Now run the tests
7777
let logFilePath = Path.Combine(__SOURCE_DIRECTORY__, "..", "artifacts", "TestResults", "Release", "FSharp.Compiler.Service.Test.xml")
78-
runDotnet __SOURCE_DIRECTORY__ "test" (sprintf "FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --no-restore --no-build -v n -c Release --test-adapter-path . --logger \"nunit;LogFilePath=%s\"" logFilePath)
78+
runDotnet __SOURCE_DIRECTORY__ "test" (sprintf "FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --no-restore --no-build -nodereuse:false -v n -c Release --test-adapter-path . --logger \"nunit;LogFilePath=%s\"" logFilePath)
7979
)
8080

8181
Target.create "NuGet" (fun _ ->

src/fsharp/FSharp.Build/FSharp.Build.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Compile Include="FSharpEmbedResXSource.fs" />
2727
<Compile Include="WriteCodeFragment.fs" />
2828
<Compile Include="CreateFSharpManifestResourceName.fs" />
29+
<Compile Include="SubstituteText.fs" />
2930
<None Include="Microsoft.FSharp.Targets" CopyToOutputDirectory="PreserveNewest" />
3031
<None Include="Microsoft.Portable.FSharp.Targets" CopyToOutputDirectory="PreserveNewest" />
3132
<None Include="Microsoft.FSharp.NetSdk.targets" CopyToOutputDirectory="PreserveNewest" />

src/fsharp/FSharp.Build/Microsoft.FSharp.Targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ this file.
2929
<UsingTask TaskName="CreateFSharpManifestResourceName" AssemblyFile="$(FSharpBuildAssemblyFile)" />
3030
<UsingTask TaskName="WriteCodeFragment" AssemblyFile="$(FSharpBuildAssemblyFile)" />
3131
<UsingTask TaskName="FSharpPlatformInformation" AssemblyFile="$(FSharpBuildAssemblyFile)" />
32+
<UsingTask TaskName="SubstituteText" AssemblyFile="$(FSharpBuildAssemblyFile)" />
3233

3334
<PropertyGroup>
3435
<ImportByWildcardBeforeMicrosoftFSharpTargets Condition="'$(ImportByWildcardBeforeMicrosoftFSharpTargets)' == ''">true</ImportByWildcardBeforeMicrosoftFSharpTargets>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Build
4+
5+
open System
6+
open System.Collections
7+
open System.IO
8+
open Microsoft.Build.Framework
9+
open Microsoft.Build.Utilities
10+
11+
type SubstituteText () =
12+
13+
let mutable _buildEngine : IBuildEngine = null
14+
let mutable _hostObject : ITaskHost = null
15+
16+
let mutable copiedFiles = new ResizeArray<ITaskItem>()
17+
let mutable embeddedResources : ITaskItem[] = [||]
18+
19+
[<Required>]
20+
member this.EmbeddedResources
21+
with get() = embeddedResources
22+
and set(value) = embeddedResources <- value
23+
24+
[<Output>]
25+
member this.CopiedFiles
26+
with get() = copiedFiles.ToArray()
27+
28+
interface ITask with
29+
member this.BuildEngine
30+
with get() = _buildEngine
31+
and set(value) = _buildEngine <- value
32+
33+
member this.HostObject
34+
with get() = _hostObject
35+
and set(value) = _hostObject <- value
36+
37+
member this.Execute() =
38+
copiedFiles.Clear()
39+
if not(isNull embeddedResources) then
40+
for item in embeddedResources do
41+
// Update ITaskItem metadata to point to new location
42+
let sourcePath = item.GetMetadata("FullPath")
43+
44+
let pattern1 = item.GetMetadata("Pattern1")
45+
let pattern2 = item.GetMetadata("Pattern2")
46+
47+
// Is there any replacement to do?
48+
if not (String.IsNullOrWhiteSpace(pattern1) && String.IsNullOrWhiteSpace(pattern2)) then
49+
if not(String.IsNullOrWhiteSpace(sourcePath)) then
50+
try
51+
let getTargetPathFrom key =
52+
let md = item.GetMetadata(key)
53+
let path = Path.GetDirectoryName(md)
54+
let filename = Path.GetFileName(md)
55+
let target = Path.Combine(path, @"..\resources", filename)
56+
target
57+
58+
// Copy from the location specified in Identity
59+
let sourcePath=item.GetMetadata("Identity")
60+
61+
// Copy to the location specified in TargetPath unless no TargetPath is provided, then use Identity
62+
let targetPath=
63+
let identityPath = getTargetPathFrom "Identity"
64+
let intermediateTargetPath = item.GetMetadata("IntermediateTargetPath")
65+
if not (String.IsNullOrWhiteSpace(intermediateTargetPath)) then
66+
let filename = Path.GetFileName(identityPath)
67+
let target = Path.Combine(intermediateTargetPath, filename)
68+
target
69+
else
70+
identityPath
71+
72+
item.ItemSpec <- targetPath
73+
74+
// Transform file
75+
let mutable contents = File.ReadAllText(sourcePath)
76+
if not (String.IsNullOrWhiteSpace(pattern1)) then
77+
let replacement = item.GetMetadata("Replacement1")
78+
contents <- contents.Replace(pattern1, replacement)
79+
if not (String.IsNullOrWhiteSpace(pattern2)) then
80+
let replacement = item.GetMetadata("Replacement2")
81+
contents <- contents.Replace(pattern2, replacement)
82+
83+
let directory = Path.GetDirectoryName(targetPath)
84+
if not(Directory.Exists(directory)) then
85+
Directory.CreateDirectory(directory) |>ignore
86+
87+
File.WriteAllText(targetPath, contents)
88+
with
89+
| _ -> ()
90+
91+
copiedFiles.Add(item)
92+
true

0 commit comments

Comments
 (0)