Repository navigation
Expand file tree
/
Copy pathBuildCompiler.fsx
More file actions
64 lines (50 loc) · 2.26 KB
/
Copy pathBuildCompiler.fsx
File metadata and controls
64 lines (50 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#r "nuget: FSharp.Data, 8.2.0"
open System.IO
open System.Xml.Linq
open System.Xml.XPath
open FSharp.Data
// Loaded by `build.fsx`, after `BuildCommon.fsx`. An error here saying BuildCommon is not defined
// means this file was run on its own; it is a library, so run a pipeline from build.fsx instead.
open BuildCommon
// Keeping the vendored FCS sources up to date: which upstream commit they came from, and fetching a
// file at that commit. `Fantomas.FCS` is a copy of the compiler, so this is how the copy moves.
let deps = repositoryRoot </> ".deps"
let fsharpCompilerHash =
let xDoc = XElement.Load(repositoryRoot </> "Directory.Build.props")
xDoc.XPathSelectElements("//FCSCommitHash") |> Seq.head |> (fun xe -> xe.Value)
let updateFileRaw (file: FileInfo) =
let lines = File.ReadAllLines file.FullName
let updatedLines =
lines
|> Array.map (fun line ->
if line.StartsWith("namespace FSharp.Build") then
line.Replace("namespace FSharp.Build", "namespace Fantomas.FCS.Build")
elif line.Contains("FSharp.Compiler") then
line.Replace("FSharp.Compiler", "Fantomas.FCS")
elif line.Contains("[<TailCall>]") then
line.Replace("[<TailCall>]", "[<Microsoft.FSharp.Core.TailCall>]")
else
line)
File.WriteAllLines(file.FullName, updatedLines)
let downloadCompilerFile commitHash relativePath =
async {
let file = FileInfo(deps </> commitHash </> relativePath)
if file.Exists && file.Length <> 0 then
return ()
else
file.Directory.Create()
let fs = file.Create()
let fileName = Path.GetFileName(relativePath)
let url =
$"https://raw.githubusercontent.com/dotnet/fsharp/{commitHash}/{relativePath}"
let! response =
Http.AsyncRequestStream(
url,
headers = [| "Content-Disposition", $"attachment; filename=\"{fileName}\"" |]
)
if response.StatusCode <> 200 then
printfn $"Could not download %s{relativePath}"
do! Async.AwaitTask(response.ResponseStream.CopyToAsync(fs))
fs.Close()
updateFileRaw file
}