Skip to content

Commit

Permalink
Beforecompile (#17057)
Browse files Browse the repository at this point in the history
* corebeforeafter

* depends

* temp

* temp

* tweak

* tweak

* typo
  • Loading branch information
KevinRansom committed Apr 26, 2024
1 parent f4bd54c commit 7e1b266
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
32 changes: 27 additions & 5 deletions src/FSharp.Build/Microsoft.FSharp.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ this file.
</FSharpEmbedResXSource>

<ItemGroup>
<CompileBefore Include="@(_FsGeneratedResXSource)" />
<Compile Include="@(_FsGeneratedResXSource)" CompileOrder="CompileBefore" />
<FsGeneratedSource Include="@(_FsGeneratedResXSource)" />
<FileWrites Include="@(_FsGeneratedResXSource)" />
</ItemGroup>
Expand All @@ -247,14 +247,35 @@ this file.
</FSharpEmbedResourceText>

<ItemGroup>
<CompileBefore Include="@(_FsGeneratedTxtSource)" />
<Compile Include="@(_FsGeneratedTxtSource)" CompileOrder="CompileBefore" />
<FsGeneratedSource Include="@(_FsGeneratedTxtSource)" />
<EmbeddedResource Include="@(_FsGeneratedResx)" />
<FileWrites Include="@(_FsGeneratedTxtSource)" />
<FileWrites Include="@(_FsGeneratedResx)" />
</ItemGroup>
</Target>

<Target Name="FSharpSourceCodeCompileOrder">
<!-- implement <CompileOrder>CompileBefore</CompileOrder> -->
<ItemGroup>
<__Sources Remove="@(__Sources)" />
<__Sources Include="@(Compile->WithMetadataValue('CompileOrder', 'CompileFirst'))" />
<__Sources Include="@(CompileBefore)" />
<__Sources Include="@(Compile->WithMetadataValue('CompileOrder', 'CompileBefore'))" />
<__Sources Include="@(Compile->WithMetadataValue('CompileOrder', ''))" />
<__Sources Include="@(Compile->WithMetadataValue('CompileOrder', 'CompileAfter'))" />
<__Sources Include="@(CompileAfter)" />
<__Sources Include="@(Compile->WithMetadataValue('CompileOrder', 'CompileLast'))" />
</ItemGroup>
<ItemGroup>
<Compile Remove="@(Compile)" />
<CompileBefore Remove="@(CompileBefore)" />
<CompileAfter Remove="@(CompileAfter)" />
<Compile Include="@(__Sources)" />
</ItemGroup>
<Message Importance="low" Text="FSharpSourceCodeCompileOrder:Sources: '@(__Sources)'" />
</Target>

<Target
Name="CoreCompile"
Inputs="$(MSBuildAllProjects);
Expand Down Expand Up @@ -284,7 +305,7 @@ this file.
$(NonExistentFile);
@(CustomAdditionalCompileOutputs)"
Returns="@(FscCommandLineArgs)"
DependsOnTargets="$(CoreCompileDependsOn)"
DependsOnTargets="$(CoreCompileDependsOn);FSharpSourceCodeCompileOrder"
>

<Error
Expand Down Expand Up @@ -321,6 +342,7 @@ this file.
<EmbeddedFiles Include="@(FsGeneratedSource)" KeepDuplicates="false" Condition="'$(SourceLink)'!='' or '$(EmbeddedFiles)'!='' or '$(EmbedAllSources)'!=''" />
</ItemGroup>


<!-- Dotnet SDK requires SimpleResolution to be true Legacy project system build not -->
<PropertyGroup>
<FscOtherFlags Condition="'$(SimpleResolution)' == 'true'">--simpleresolution $(OtherFlags)</FscOtherFlags>
Expand Down Expand Up @@ -371,7 +393,7 @@ this file.
Resources="@(ActualEmbeddedResources)"
SkipCompilerExecution="$(SkipCompilerExecution)"
SourceLink="$(SourceLink)"
Sources="@(CompileBefore);@(Compile);@(CompileAfter)"
Sources="@(Compile)"
SubsystemVersion="$(SubsystemVersion)"
Tailcalls="$(Tailcalls)"
TargetType="$(OutputType)"
Expand Down Expand Up @@ -434,7 +456,7 @@ this file.
Overwrite="true"/>

<ItemGroup Condition="'$(AdditionalSourcesText)' != ''">
<CompileBefore Include="$(TargetFrameworkMonikerAssemblyAttributesPath)" />
<Compile Include="$(TargetFrameworkMonikerAssemblyAttributesPath)"><CompileOrder>CompileBefore</CompileOrder></Compile>
<_FsGeneratedTfmAttributesSource Include="$(TargetFrameworkMonikerAssemblyAttributesPath)" />
</ItemGroup>
</Target>
Expand Down
13 changes: 13 additions & 0 deletions src/FSharp.Core/FSharp.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,25 @@
</EmbeddedResource>
<EmbeddedResource Include="ILLink.LinkAttributes.xml" LogicalName="ILLink.LinkAttributes.xml" />
<EmbeddedResource Include="ILLink.Substitutions.xml" LogicalName="ILLink.Substitutions.xml" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Proto'">
<!-- This can be removed once CompileBefore support is shipped in an rtm relase -->
<CompileBefore Include="prim-types-prelude.fsi">
<Link>Primitives/prim-types-prelude.fsi</Link>
</CompileBefore>
<CompileBefore Include="prim-types-prelude.fs">
<Link>Primitives/prim-types-prelude.fs</Link>
</CompileBefore>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' != 'Proto'">
<Compile Include="prim-types-prelude.fsi" CompileOrder="CompileFirst">
<Link>Primitives/prim-types-prelude.fsi</Link>
</Compile>
<Compile Include="prim-types-prelude.fs" CompileOrder="CompileFirst">
<Link>Primitives/prim-types-prelude.fs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="prim-types.fsi">
<Link>Primitives/prim-types.fsi</Link>
</Compile>
Expand Down
42 changes: 42 additions & 0 deletions tests/fsharp/SDKTests/tests/CompileOrder - BeforeAndAfter.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project ToolsVersion="4.0" DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Initialize Variables -->
<PropertyGroup>
<FSharpCompilerPath></FSharpCompilerPath>
</PropertyGroup>

<!-- Expected Values -->
<PropertyGroup>
<ExpectedFSharpShimPresent>true</ExpectedFSharpShimPresent>
<ExpectedFSharpCompilerPath>/Common7/IDE/CommonExtensions/Microsoft/FSharp/Tools/</ExpectedFSharpCompilerPath>
<ExpectedFscToolExe>fscAnyCpu.exe</ExpectedFscToolExe>
<ExpectedFscToolPath>_VsInstallRoot_/Common7/IDE/CommonExtensions/Microsoft/FSharp/Tools/</ExpectedFscToolPath>
<ExpectedDotnetFscCompilerPath></ExpectedDotnetFscCompilerPath>
<ExpectedCompile>One;Two;Three;Four;Five;Six;Seven;Eight;Nine;Ten;Eleven;Twelve;Thirteen;Fourteen</ExpectedCompile>
</PropertyGroup>

<Import Project="ToolsTest.props" />

<PropertyGroup>
</PropertyGroup>

<ItemGroup>
<CompileAfter Include="Eleven" />
<Compile Include="Thirteen" CompileOrder="CompileLast" />
<CompileBefore Include="Three" />
<CompileAfter Include="Twelve" />
<CompileBefore Include="Four" />
<Compile Include="Seven" />
<Compile Include="Eight" />
<Compile Include="Five" CompileOrder="CompileBefore" />
<Compile Include="One" CompileOrder="CompileFirst" />
<Compile Include="Nine" CompileOrder="CompileAfter" />
<Compile Include="Fourteen" CompileOrder="CompileLast" />
<Compile Include="Ten" CompileOrder="CompileAfter" />
<Compile Include="Two" CompileOrder="CompileFirst" />
<Compile Include="Six" CompileOrder="CompileBefore" />
</ItemGroup>

<Import Project="ToolsTest.targets" />

</Project>
5 changes: 4 additions & 1 deletion tests/fsharp/SDKTests/tests/ToolsTest.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

<Import Project="$(TargetsDirectory)\Microsoft.FSharp.targets" />

<Target Name="Test">
<Target Name="Test" DependsOnTargets="FSharpSourceCodeCompileOrder">
<Message Importance="High" Text="===========================================================================================================" />
<Message Importance="High" Text="Testing : $(MSBuildProjectName)" />


<!-- check for expected settings -->
<Error Condition="'$(ExpectedFSharpShimPresent)' != '$(FSharp_Shim_Present)'" Text="FSharp_Shim_Present expected:'$(ExpectedFSharpShimPresent)' actual: '$(FSharp_Shim_Present)'" />

Expand All @@ -17,6 +18,8 @@

<Error Condition="'$(ExpectedFscToolPath)' != '$(FscToolPath)'" Text="FscToolPath: expected:'$(ExpectedFscToolPath)' actual:'$(FscToolPath)'" />

<Error Condition="'$(ExpectedCompile)' != '' and '$(ExpectedCompile)' != '@(Compile)'" Text="ExpectedCompile: expected:'$(ExpectedCompile)' actual:'@(Compile)'" />

<Error Condition="'$(ExpectedDotnetFscCompilerPath)' == '' and '$(DotnetFscCompilerPath)' != ''" Text="DotnetFscCompilerPath expected to be empty actual:'$(DotnetFscCompilerPath)'" />

<Error Condition="'$(ExpectedDotnetFscCompilerPath)' != '' and $([System.String]::new('$(DotnetFscCompilerPath)').EndsWith('$(ExpectedDotnetFscCompilerPath)')) == true" Text="DotnetFscCompilerPath expected to end with: '$(ExpectedDotnetFscCompilerPath)' actual:'$(DotnetFscCompilerPath)'" />
Expand Down

0 comments on commit 7e1b266

Please sign in to comment.