Skip to content

Commit 60cb2cf

Browse files
Refactor the templating engine and the command tool cache et al. (#615)
* 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.
1 parent 420e4a4 commit 60cb2cf

File tree

17 files changed

+414
-464
lines changed

17 files changed

+414
-464
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ _NCrunch_*
3838
.ionide/
3939
artifacts/
4040
tests/FSharp.ApiDocs.Tests/output/
41-
tmp
41+
tmp
42+
.idea/
43+
*.binlog
44+
version.props
45+
src/Common/AssemblyInfo.?s

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
2-
<Import Project="version.props" />
2+
<Import Condition="Exists('version.props')" Project="version.props" />
33
<PropertyGroup>
44
<!-- Include PDBs in Nuget package. -->
55
<AllowedOutputExtensionsInPackageBuildOutputFolder>.pdb; $(AllowedOutputExtensionsInPackageBuildOutputFolder)</AllowedOutputExtensionsInPackageBuildOutputFolder>

build.fsx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#endif
1010

1111
open System
12-
open System.IO
12+
open System.Xml.Linq
1313
open Fake.Core
1414
open Fake.Core.TargetOperators
1515
open Fake.IO.Globbing.Operators
@@ -52,15 +52,14 @@ Target.create "AssemblyInfo" (fun _ ->
5252

5353
AssemblyInfoFile.createFSharp "src/Common/AssemblyInfo.fs" info
5454
AssemblyInfoFile.createCSharp "src/Common/AssemblyInfo.cs" info
55-
let releaseNotes = String.toLines release.Notes |> System.Net.WebUtility.HtmlEncode
56-
File.WriteAllText("version.props", sprintf """<Project>
57-
<PropertyGroup>
58-
<Version>%s</Version>
59-
<PackageReleaseNotes>
60-
%s
61-
</PackageReleaseNotes>
62-
</PropertyGroup>
63-
</Project>""" release.NugetVersion releaseNotes)
55+
let versionProps =
56+
XElement(XName.Get "Project",
57+
XElement(XName.Get "PropertyGroup",
58+
XElement(XName.Get "Version", release.NugetVersion),
59+
XElement(XName.Get "PackageReleaseNotes", String.toLines release.Notes)
60+
)
61+
)
62+
versionProps.Save("version.props")
6463
)
6564

6665
// Clean build results
@@ -104,8 +103,8 @@ Target.create "Tests" (fun _ ->
104103
Target.create "NuGet" (fun _ ->
105104
DotNet.pack (fun pack ->
106105
{ pack with
107-
OutputPath = Some artifactsDir
108-
Configuration = configuration
106+
OutputPath = Some artifactsDir
107+
Configuration = configuration
109108
}) solutionFile
110109
)
111110

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

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

152151
Target.create "CreateTag" (fun _ ->

docs/_template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ <h3 class="muted"><a href="{{fsdocs-collection-name-link}}">{{fsdocs-collection-
7171

7272
<!-- BEGIN SEARCH BOX: this adds support for the search box -->
7373
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/JavaScript-autoComplete/1.0.4/auto-complete.css" />
74-
<script type="text/javascript">var fsdocs_search_baseurl = '{{root}}'</script>
74+
<script type="text/javascript">var fsdocs_search_baseurl = '{{root}}';</script>
7575
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.8/lunr.min.js"></script>
7676
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/JavaScript-autoComplete/1.0.4/auto-complete.min.js"></script>
7777
<script type="text/javascript" src="{{root}}content/fsdocs-search.js"></script>

paket.dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ nuget Dotnet.ProjInfo
1010
nuget Dotnet.ProjInfo.Workspace
1111
nuget Newtonsoft.Json
1212
nuget Suave 2.1.1
13+
nuget System.Memory
1314

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

0 commit comments

Comments
 (0)