Skip to content

Commit

Permalink
Refactor the templating engine and the command tool cache et al. (#615)
Browse files Browse the repository at this point in the history
* Use a more efficient implementation of the Common module functions.

Use an allocation-free implementation of the ParamKey type.
Fix formatting in BuildCommand.fs and syntax highlighting in _template.html.

* Rewrite the template engine to be more memory-efficient.

It uses spans. For the most of allocation savings, FSharp.Formatting.Common now targets .NET Standard 2.1 too but the package is not yet updated; only the command tool will take advantage of all improvements.

* Ignore files generated by the AssemblyInfo FAKE target.

Remove an unused source file.
And use LINQ-to-XML to generate version.props.

* Serialize the command tool cache with the data contract serializer.

The cache is both more secure and more compact (the cache's size for this project was reduced by a third, after using binary XML).
And use a more reliable way to install the command tools during documentation generation.

* Override ParamKey.ToString.
  • Loading branch information
teo-tsirpanis authored Oct 15, 2020
1 parent 420e4a4 commit 60cb2cf
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 464 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ _NCrunch_*
.ionide/
artifacts/
tests/FSharp.ApiDocs.Tests/output/
tmp
tmp
.idea/
*.binlog
version.props
src/Common/AssemblyInfo.?s
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<Import Project="version.props" />
<Import Condition="Exists('version.props')" Project="version.props" />
<PropertyGroup>
<!-- Include PDBs in Nuget package. -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>.pdb; $(AllowedOutputExtensionsInPackageBuildOutputFolder)</AllowedOutputExtensionsInPackageBuildOutputFolder>
Expand Down
43 changes: 21 additions & 22 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#endif

open System
open System.IO
open System.Xml.Linq
open Fake.Core
open Fake.Core.TargetOperators
open Fake.IO.Globbing.Operators
Expand Down Expand Up @@ -52,15 +52,14 @@ Target.create "AssemblyInfo" (fun _ ->

AssemblyInfoFile.createFSharp "src/Common/AssemblyInfo.fs" info
AssemblyInfoFile.createCSharp "src/Common/AssemblyInfo.cs" info
let releaseNotes = String.toLines release.Notes |> System.Net.WebUtility.HtmlEncode
File.WriteAllText("version.props", sprintf """<Project>
<PropertyGroup>
<Version>%s</Version>
<PackageReleaseNotes>
%s
</PackageReleaseNotes>
</PropertyGroup>
</Project>""" release.NugetVersion releaseNotes)
let versionProps =
XElement(XName.Get "Project",
XElement(XName.Get "PropertyGroup",
XElement(XName.Get "Version", release.NugetVersion),
XElement(XName.Get "PackageReleaseNotes", String.toLines release.Notes)
)
)
versionProps.Save("version.props")
)

// Clean build results
Expand Down Expand Up @@ -104,8 +103,8 @@ Target.create "Tests" (fun _ ->
Target.create "NuGet" (fun _ ->
DotNet.pack (fun pack ->
{ pack with
OutputPath = Some artifactsDir
Configuration = configuration
OutputPath = Some artifactsDir
Configuration = configuration
}) solutionFile
)

Expand All @@ -115,15 +114,15 @@ Target.create "NuGet" (fun _ ->
Target.create "GenerateDocs" (fun _ ->
Shell.cleanDir ".fsdocs"
Shell.cleanDir ".packages"
DotNet.exec id "tool" "uninstall --local FSharp.Formatting.CommandTool" |> ignore
// Use a local package store to avoid reuse of previous builds of the package with the same version
try
Environment.setEnvironVar "NUGET_PACKAGES" (__SOURCE_DIRECTORY__ + "/.packages")
DotNet.exec id "tool" ("install --local --no-cache --version " + release.NugetVersion + " --add-source " + artifactsDir + " FSharp.Formatting.CommandTool") |> ignore
finally
Environment.setEnvironVar "NUGET_PACKAGES" ""
DotNet.exec id "fsdocs" "build --strict --clean --property Configuration=Release" |> ignore
DotNet.exec id "tool" "uninstall --local FSharp.Formatting.CommandTool" |> ignore
// Τhe tool has been uninstalled when the
// artifacts folder was removed in the Clean target.
DotNet.exec id "tool" ("install --no-cache --version " + release.NugetVersion + " --add-source " + artifactsDir + " --tool-path " + artifactsDir + " FSharp.Formatting.CommandTool") |> ignore
CreateProcess.fromRawCommand (artifactsDir @@ "fsdocs") ["build"; "--strict"; "--clean"; "--property"; "Configuration=Release"]
|> CreateProcess.ensureExitCode
|> Proc.run
|> ignore
// DotNet.exec id "fsdocs" "build --strict --clean --property Configuration=Release" |> ignore
// DotNet.exec id "tool" "uninstall --local FSharp.Formatting.CommandTool" |> ignore
Shell.cleanDir ".packages"
)

Expand All @@ -146,7 +145,7 @@ Target.create "PublishNuget" (fun _ ->
let apikey = Environment.environVar "NUGET_KEY"
for artifact in !! (artifactsDir + "/*nupkg") do
let result = DotNet.exec id "nuget" (sprintf "push -s %s -k %s %s" source apikey artifact)
if not result.OK then failwith "failed to push packages"
if not result.OK then failwith "failed to push packages"
)

Target.create "CreateTag" (fun _ ->
Expand Down
2 changes: 1 addition & 1 deletion docs/_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3 class="muted"><a href="{{fsdocs-collection-name-link}}">{{fsdocs-collection-

<!-- BEGIN SEARCH BOX: this adds support for the search box -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/JavaScript-autoComplete/1.0.4/auto-complete.css" />
<script type="text/javascript">var fsdocs_search_baseurl = '{{root}}'</script>
<script type="text/javascript">var fsdocs_search_baseurl = '{{root}}';</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.8/lunr.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/JavaScript-autoComplete/1.0.4/auto-complete.min.js"></script>
<script type="text/javascript" src="{{root}}content/fsdocs-search.js"></script>
Expand Down
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nuget Dotnet.ProjInfo
nuget Dotnet.ProjInfo.Workspace
nuget Newtonsoft.Json
nuget Suave 2.1.1
nuget System.Memory

# Used to create notebook docs with mybinder links that work
# See https://github.com/dotnet/interactive/blob/master/docs/CreateBinder.md
Expand Down
Loading

0 comments on commit 60cb2cf

Please sign in to comment.