Skip to content

Commit

Permalink
Migration to FAKE v5
Browse files Browse the repository at this point in the history
- Changed Fake build system from fsx script to fsproj.
  - see: https://fake.build/guide/getting-started.html#Different-ways-to-run-FAKE
  - this resolved compatibility issues that [Could not find a suitable .NET 6 runtime version matching SDK version: 7](fsprojects/FAKE#2719).
  • Loading branch information
SilkyFowl committed May 4, 2023
1 parent f04fb49 commit a7a41a1
Show file tree
Hide file tree
Showing 12 changed files with 695 additions and 392 deletions.
6 changes: 6 additions & 0 deletions Avalonia.FuncUI.LiveView.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{77D972B7
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Avalonia.FuncUI.LiveView.Core.Tests", "tests\Avalonia.FuncUI.LiveView.Core.Tests\Avalonia.FuncUI.LiveView.Core.Tests.fsproj", "{20DD3B4D-46C8-4F78-B114-6ED2CCAA1433}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "build", "build\build.fsproj", "{58DC7613-7B55-4C0C-929A-ACFD312E894B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,10 @@ Global
{20DD3B4D-46C8-4F78-B114-6ED2CCAA1433}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20DD3B4D-46C8-4F78-B114-6ED2CCAA1433}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20DD3B4D-46C8-4F78-B114-6ED2CCAA1433}.Release|Any CPU.Build.0 = Release|Any CPU
{58DC7613-7B55-4C0C-929A-ACFD312E894B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58DC7613-7B55-4C0C-929A-ACFD312E894B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58DC7613-7B55-4C0C-929A-ACFD312E894B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58DC7613-7B55-4C0C-929A-ACFD312E894B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AA59F86F-40EC-4935-928E-ACE854A73DE4} = {DB8DF710-E6E6-4722-99D4-514834AEEB16}
Expand Down
375 changes: 189 additions & 186 deletions build.fsx → build/build.fs
Original file line number Diff line number Diff line change
@@ -1,186 +1,189 @@
#if FAKE
#r "paket:
nuget Fake.Core.ReleaseNotes
nuget Fake.DotNet.Cli
nuget Fake.DotNet.Paket
nuget Fake.IO.FileSystem
nuget Fake.IO.Zip
nuget Fake.Core.Target //"
#endif
#r "System.Xml.XDocument.dll"
#r "System.IO.Compression.ZipFile.dll"
#load ".fake/build.fsx/intellisense.fsx"

open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators

// ****************************************************************************************************
// ------------------------------------------- Definitions -------------------------------------------
// ****************************************************************************************************

let srcPath = "./src"
let outputPath = "./dist"
let slnPath = "./Avalonia.FuncUI.LiveView.sln"
let localanalyzerPath = "./localanalyzers"

// properties
let projectDescription = [ "Live fs/fsx previewer for Avalonia.FuncUI." ]
let gitUserName = "SilkyFowl"
let authors = [ gitUserName ]
let projectUrl = $"https://github.com/{gitUserName}/Avalonia.FuncUI.LiveView"

let release = ReleaseNotes.load "RELEASE_NOTES.md"

type ProjSetting =
{ Name: string }
member this.Path = srcPath @@ this.Name
member this.PackageId = $"{gitUserName}.{this.Name}"

let analyzerProjSetting = { Name = "Avalonia.FuncUI.LiveView.Analyzer" }
let liveViewProjSetting = { Name = "Avalonia.FuncUI.LiveView" }

module Paket =
open PaketTemplate

let private baseParams =
{ DefaultPaketTemplateParams with
TemplateType = Project
Version = Some release.NugetVersion
ReleaseNotes = release.Notes
Description = projectDescription
Authors = authors
ProjectUrl = Some projectUrl
Files = [ Include(".." </> ".." </> "LICENSE.md", "") ] }

let settings =
let toTemplateFilePath projectPath = Some(projectPath @@ "paket.template")

[ {| projSetting = analyzerProjSetting
templateParams =
{ baseParams with
TemplateFilePath = toTemplateFilePath analyzerProjSetting.Path
Id = Some analyzerProjSetting.PackageId
Files =
baseParams.Files
@ [ Include("bin" </> "Release" </> "net6.0" </> "publish", "lib" </> "net6.0") ] } |}
{| projSetting = liveViewProjSetting
templateParams =
{ baseParams with
TemplateFilePath = toTemplateFilePath liveViewProjSetting.Path
Id = Some liveViewProjSetting.PackageId } |} ]

module Nuspec =
open System.Xml.Linq
open System.IO.Compression

let addLicense (proj: ProjSetting) =
let xn = XName.Get

let ns localName =
XName.Get(localName, "http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd")

let unzipedPath =
outputPath
</> $"{proj.PackageId}.{release.NugetVersion}"

let nupkgPath = $"{unzipedPath}.nupkg"

let nuspecPath = unzipedPath </> $"{proj.PackageId}.nuspec"

Zip.unzip unzipedPath nupkgPath

let nupkgDoc = XDocument.Load nuspecPath

nupkgDoc.Descendants(ns "authors")
|> Seq.iter (fun metadata ->
metadata.AddAfterSelf(
XElement(ns "requireLicenseAcceptance", "false"),
XElement(ns "license", XAttribute(xn "type", "file"), "LICENSE.md"),
XElement(ns "licenseUrl", "https://aka.ms/deprecateLicenseUrl")
))

if proj = analyzerProjSetting then
nupkgDoc.Descendants(ns "dependency")
|> Seq.filter (fun dependency -> dependency.Attribute(xn "id").Value <> "FSharp.Analyzers.SDK")
|> Seq.toList
|> List.iter (fun dependency -> dependency.Remove())

nupkgDoc.Save nuspecPath
Shell.rm nupkgPath

ZipFile.CreateFromDirectory(unzipedPath, nupkgPath)
Shell.deleteDir unzipedPath

Target.initEnvironment ()

// ****************************************************************************************************
// --------------------------------------------- Targets ---------------------------------------------
// ****************************************************************************************************

Target.create "CleanDebug" (fun _ -> !! "src/**/Debug" ++ outputPath |> Shell.cleanDirs)

Target.create "CleanRelease" (fun _ ->
!! "src/**/Release" ++ outputPath
|> Shell.cleanDirs)


Target.create "BuildDebug" (fun _ ->
slnPath
|> DotNet.build (fun setParams -> { setParams with Configuration = DotNet.Debug }))

Target.create "BuildRelease" (fun _ ->
slnPath
|> DotNet.build (fun setParams -> { setParams with Configuration = DotNet.Release }))

Target.create "Pack" (fun _ ->
for setting in Paket.settings do

PaketTemplate.create (fun _ -> setting.templateParams)

setting.projSetting.Path
|> DotNet.publish (fun opts ->
{ opts with
Configuration = DotNet.Release
SelfContained = Some false
Framework = Some "net6.0" })

Paket.pack (fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
TemplateFile = Option.toObj setting.templateParams.TemplateFilePath
OutputPath = outputPath
MinimumFromLockFile = true
IncludeReferencedProjects = true })

Nuspec.addLicense setting.projSetting)

Target.create "ClearLocalAnalyzer" (fun _ ->
!!outputPath ++ localanalyzerPath
|> Shell.cleanDirs)

Target.create "SetLocalAnalyzer" (fun _ ->
let analyzerId = analyzerProjSetting.PackageId

outputPath
|> Directory.findFirstMatchingFile $"{analyzerId}.*"
|> Zip.unzip (localanalyzerPath </> analyzerId))

Target.create "Default" ignore

// ****************************************************************************************************
// --------------------------------------- Targets Dependencies ---------------------------------------
// ****************************************************************************************************

"CleanDebug" ==> "BuildDebug" ==> "Default"

"CleanRelease"
==> "ClearLocalAnalyzer"
==> "BuildRelease"
==> "Pack"
==> "SetLocalAnalyzer"

Target.runOrDefault "Default"
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators

// ****************************************************************************************************
// ------------------------------------------- Definitions -------------------------------------------
// ****************************************************************************************************

let srcPath = "./src"
let outputPath = "./dist"
let slnPath = "./Avalonia.FuncUI.LiveView.sln"
let localanalyzerPath = "./localanalyzers"

// properties
let projectDescription = [ "Live fs/fsx previewer for Avalonia.FuncUI." ]
let gitUserName = "SilkyFowl"
let authors = [ gitUserName ]
let projectUrl = $"https://github.com/{gitUserName}/Avalonia.FuncUI.LiveView"

let release = ReleaseNotes.load "RELEASE_NOTES.md"

type ProjSetting =
{ Name: string }
member this.Path = srcPath @@ this.Name
member this.PackageId = $"{gitUserName}.{this.Name}"

let analyzerProjSetting = { Name = "Avalonia.FuncUI.LiveView.Analyzer" }
let liveViewProjSetting = { Name = "Avalonia.FuncUI.LiveView" }

module Paket =
open PaketTemplate

let private baseParams =
{ DefaultPaketTemplateParams with
TemplateType = Project
Version = Some release.NugetVersion
ReleaseNotes = release.Notes
Description = projectDescription
Authors = authors
ProjectUrl = Some projectUrl
Files = [ Include(".." </> ".." </> "LICENSE.md", "") ] }

let settings =
let toTemplateFilePath projectPath = Some(projectPath @@ "paket.template")

[ {| projSetting = analyzerProjSetting
templateParams =
{ baseParams with
TemplateFilePath = toTemplateFilePath analyzerProjSetting.Path
Id = Some analyzerProjSetting.PackageId
Files =
baseParams.Files
@ [ Include("bin" </> "Release" </> "net6.0" </> "publish", "lib" </> "net6.0") ] } |}
{| projSetting = liveViewProjSetting
templateParams =
{ baseParams with
TemplateFilePath = toTemplateFilePath liveViewProjSetting.Path
Id = Some liveViewProjSetting.PackageId } |} ]

module Nuspec =
open System.Xml.Linq
open System.IO.Compression

let addLicense (proj: ProjSetting) =
let xn = XName.Get

let ns localName =
XName.Get(localName, "http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd")

let unzipedPath =
outputPath
</> $"{proj.PackageId}.{release.NugetVersion}"

let nupkgPath = $"{unzipedPath}.nupkg"

let nuspecPath = unzipedPath </> $"{proj.PackageId}.nuspec"

Zip.unzip unzipedPath nupkgPath

let nupkgDoc = XDocument.Load nuspecPath

nupkgDoc.Descendants(ns "authors")
|> Seq.iter (fun metadata ->
metadata.AddAfterSelf(
XElement(ns "requireLicenseAcceptance", "false"),
XElement(ns "license", XAttribute(xn "type", "file"), "LICENSE.md"),
XElement(ns "licenseUrl", "https://aka.ms/deprecateLicenseUrl")
))

if proj = analyzerProjSetting then
nupkgDoc.Descendants(ns "dependency")
|> Seq.filter (fun dependency -> dependency.Attribute(xn "id").Value <> "FSharp.Analyzers.SDK")
|> Seq.toList
|> List.iter (fun dependency -> dependency.Remove())

nupkgDoc.Save nuspecPath
Shell.rm nupkgPath

ZipFile.CreateFromDirectory(unzipedPath, nupkgPath)
Shell.deleteDir unzipedPath

#nowarn "20"
let initTargets () =
Target.initEnvironment ()

// ****************************************************************************************************
// --------------------------------------------- Targets ---------------------------------------------
// ****************************************************************************************************

Target.create "CleanDebug" (fun _ -> !! "src/**/Debug" ++ outputPath |> Shell.cleanDirs)

Target.create "CleanRelease" (fun _ ->
!! "src/**/Release" ++ outputPath
|> Shell.cleanDirs)


Target.create "BuildDebug" (fun _ ->
slnPath
|> DotNet.build (fun setParams -> { setParams with Configuration = DotNet.Debug }))

Target.create "BuildRelease" (fun _ ->
slnPath
|> DotNet.build (fun setParams -> { setParams with Configuration = DotNet.Release }))

Target.create "Pack" (fun _ ->
for setting in Paket.settings do

PaketTemplate.create (fun _ -> setting.templateParams)

setting.projSetting.Path
|> DotNet.publish (fun opts ->
{ opts with
Configuration = DotNet.Release
SelfContained = Some false
Framework = Some "net6.0" })

Paket.pack (fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
TemplateFile = Option.toObj setting.templateParams.TemplateFilePath
OutputPath = outputPath
MinimumFromLockFile = true
IncludeReferencedProjects = true })

Nuspec.addLicense setting.projSetting)

Target.create "ClearLocalAnalyzer" (fun _ ->
!!outputPath ++ localanalyzerPath
|> Shell.cleanDirs)

Target.create "SetLocalAnalyzer" (fun _ ->
let analyzerId = analyzerProjSetting.PackageId

outputPath
|> Directory.findFirstMatchingFile $"{analyzerId}.*"
|> Zip.unzip (localanalyzerPath </> analyzerId))

Target.create "Default" ignore

// ****************************************************************************************************
// --------------------------------------- Targets Dependencies ---------------------------------------
// ****************************************************************************************************

"CleanDebug" ==> "BuildDebug" ==> "Default"

"CleanRelease"
==> "ClearLocalAnalyzer"
==> "BuildRelease"
==> "Pack"
==> "SetLocalAnalyzer"

//-----------------------------------------------------------------------------
// Target Start
//-----------------------------------------------------------------------------

[<EntryPoint>]
let main argv =
argv
|> Array.toList
|> Context.FakeExecutionContext.Create false "build.fsx"
|> Context.RuntimeContext.Fake
|> Context.setExecutionContext
initTargets ()
Target.runOrDefaultWithArguments "Default"

0 // return an integer exit code
Loading

0 comments on commit a7a41a1

Please sign in to comment.