Skip to content

Commit

Permalink
scripts: refactor to respect DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Oct 20, 2023
1 parent ff08275 commit e83032d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 62 deletions.
24 changes: 24 additions & 0 deletions scripts/fsxHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@ open System.IO
open Fsdk
open Fsdk.Process

type SolutionFile =
| Default
| Linux
| Mac

module FsxHelper =

let GetSolution (solType: SolutionFile) =
let solFileName =
match solType with
| Default ->
#if !LEGACY_FRAMEWORK
"gwallet.core.sln"
#else
"gwallet.core-legacy.sln"
#endif
| Linux -> "gwallet.linux-legacy.sln"
| Mac -> "gwallet.mac-legacy.sln"

let slnFile =
Path.Combine("src", solFileName)
|> FileInfo
if not slnFile.Exists then
raise <| FileNotFoundException("Solution file not found", slnFile.FullName)
slnFile

let ScriptsDir = __SOURCE_DIRECTORY__ |> DirectoryInfo
let RootDir = Path.Combine(ScriptsDir.FullName, "..") |> DirectoryInfo
let SourceDir = Path.Combine(ScriptsDir.FullName, "../src/") |> DirectoryInfo
Expand Down
52 changes: 15 additions & 37 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ open System.IO
open System.Linq
open System.Diagnostics

open System.Text
open System.Text.RegularExpressions
#r "System.Core.dll"
open System.Xml
#r "System.Xml.Linq.dll"
open System.Xml.Linq
open System.Xml.XPath

#if !LEGACY_FRAMEWORK
#r "nuget: Fsdk, Version=0.6.0--date20230818-1152.git-83d671b"
#else
Expand All @@ -34,25 +26,6 @@ let UNIX_NAME = "geewallet"
let CONSOLE_FRONTEND = "GWallet.Frontend.Console"
let GTK_FRONTEND = "GWallet.Frontend.XF.Gtk"

type SolutionFile =
| Default
| Linux
| Mac

let GetSolution (solType: SolutionFile) =
let solFileName =
match solType with
| Default ->
#if !LEGACY_FRAMEWORK
"gwallet.core.sln"
#else
"gwallet.core-legacy.sln"
#endif
| Linux -> "gwallet.linux-legacy.sln"
| Mac -> "gwallet.mac-legacy.sln"

Path.Combine("src", solFileName)

type ProjectFile =
| XFFrontend
| GtkFrontend
Expand All @@ -63,7 +36,12 @@ let GetProject (projFile: ProjectFile) =
| GtkFrontend -> Path.Combine("GWallet.Frontend.XF.Gtk", "GWallet.Frontend.XF.Gtk.fsproj")
| XFFrontend -> Path.Combine("GWallet.Frontend.XF", "GWallet.Frontend.XF.fsproj")

Path.Combine("src", projFileName)
let prjFile =
Path.Combine("src", projFileName)
|> FileInfo
if not prjFile.Exists then
raise <| FileNotFoundException("Project file not found", prjFile.FullName)
prjFile

let BACKEND = "GWallet.Backend"

Expand Down Expand Up @@ -154,11 +132,11 @@ FRONTEND_PATH="$DIR_OF_THIS_SCRIPT/../lib/$UNIX_NAME/$GWALLET_PROJECT.exe"
exec mono "$FRONTEND_PATH" "$@"
"""

let NugetRestore projectOrSolutionRelativePath =
let NugetRestore (projectOrSolution: FileInfo) =
let nugetArgs =
sprintf
"restore %s -DisableParallelProcessing -SolutionDirectory ."
projectOrSolutionRelativePath
projectOrSolution.FullName
let proc =
Network.RunNugetCommand
FsxHelper.NugetExe
Expand Down Expand Up @@ -194,13 +172,13 @@ let PrintNugetVersion () =

let BuildSolutionOrProject
(buildToolAndBuildArg: string*string)
(fileName: string)
(file: FileInfo)
(binaryConfig: BinaryConfig)
(maybeConstant: Option<string>)
(extraOptions: string)
=
#if LEGACY_FRAMEWORK
NugetRestore fileName
NugetRestore file
#endif

let buildTool,buildArg = buildToolAndBuildArg
Expand Down Expand Up @@ -255,7 +233,7 @@ let BuildSolutionOrProject
configOption
let buildArgs = sprintf "%s %s %s %s"
buildArg
fileName
file.FullName
configOptions
extraOptions
let buildProcess = Process.Execute ({ Command = buildTool; Arguments = buildArgs }, Echo.All)
Expand All @@ -273,7 +251,7 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
let maybeBuildTool = Map.tryFind "BuildTool" buildConfigContents
let maybeLegacyBuildTool = Map.tryFind "LegacyBuildTool" buildConfigContents

let solutionFileName = GetSolution SolutionFile.Default
let solutionFile = FsxHelper.GetSolution SolutionFile.Default
let getBuildToolAndArgs(buildTool: string) =
match buildTool with
| "dotnet" ->
Expand Down Expand Up @@ -307,7 +285,7 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
| None, Some buildTool ->
BuildSolutionOrProject
(getBuildToolAndArgs buildTool)
solutionFileName
solutionFile
binaryConfig
maybeConstant
String.Empty
Expand All @@ -328,7 +306,7 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
| Misc.Platform.Mac ->
//this is because building in release requires code signing keys
if binaryConfig = BinaryConfig.Debug then
let solution = GetSolution SolutionFile.Mac
let solution = FsxHelper.GetSolution SolutionFile.Mac
// somehow, msbuild doesn't restore the frontend dependencies (e.g. Xamarin.Forms) when targetting
// the {LINUX|MAC}_SOLUTION_FILE below, so we need this workaround. TODO: just finish migrating to MAUI(dotnet restore)
NugetRestore solution
Expand All @@ -337,7 +315,7 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
Frontend.Console
| Misc.Platform.Linux ->
if FsxHelper.AreGtkLibsPresent Echo.All then
let solution = GetSolution SolutionFile.Linux
let solution = FsxHelper.GetSolution SolutionFile.Linux
// somehow, msbuild doesn't restore the frontend dependencies (e.g. Xamarin.Forms) when targetting
// the {LINUX|MAC}_SOLUTION_FILE below, so we need this workaround. TODO: just finish migrating to MAUI(dotnet restore)
NugetRestore solution
Expand Down
34 changes: 9 additions & 25 deletions scripts/sanitycheck.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,42 +421,26 @@ let SanityCheckNugetPackages () =

//let solutions = Directory.GetCurrentDirectory() |> DirectoryInfo |> findSolutions
//NOTE: we hardcode the solutions rather than the line above, because e.g. Linux OS can't build/restore iOS proj
let solutionFileNames = [
Path.Combine(FsxHelper.SourceDir.FullName, "gwallet.linux-legacy.sln")
Path.Combine(FsxHelper.SourceDir.FullName, "gwallet.mac-legacy.sln")
Path.Combine(FsxHelper.SourceDir.FullName, "gwallet.core-legacy.sln")
Path.Combine(FsxHelper.SourceDir.FullName, "gwallet.core.sln")
]

let solutionFiles = solutionFileNames |> List.map FileInfo

let checkFilesExist (fileNames: List<FileInfo>) =
fileNames
|> List.map (fun fileName -> fileName.Exists)
|> List.fold (&&) true

let allFilesExist = checkFilesExist solutionFiles

if not allFilesExist then
failwith "Solution files were not found to do sanity check."

match Misc.GuessPlatform() with
let sol =
match Misc.GuessPlatform() with
// xbuild cannot build .NETStandard projects so we cannot build the non-Core parts:
| Misc.Platform.Linux when "dotnet" = Environment.GetEnvironmentVariable "BuildTool" ->
sanityCheckNugetPackagesFromSolution solutionFiles.[3]
FsxHelper.GetSolution SolutionFile.Default
| Misc.Platform.Linux when "msbuild" = Environment.GetEnvironmentVariable "LegacyBuildTool" ->
sanityCheckNugetPackagesFromSolution solutionFiles.[0]
FsxHelper.GetSolution SolutionFile.Linux
// .NET-only macOS only builds gwallet.core.sln
| Misc.Platform.Mac when "dotnet" = Environment.GetEnvironmentVariable "BuildTool"
&& Environment.GetEnvironmentVariable "LegacyBuildTool" = "" ->
sanityCheckNugetPackagesFromSolution solutionFiles.[3]
FsxHelper.GetSolution SolutionFile.Default
| Misc.Platform.Mac when "msbuild" = Environment.GetEnvironmentVariable "LegacyBuildTool" ->
sanityCheckNugetPackagesFromSolution solutionFiles.[1]
FsxHelper.GetSolution SolutionFile.Mac

| _ (* stockmono linux and windows *) ->

// TODO: have a windows solution file
sanityCheckNugetPackagesFromSolution solutionFiles.[2]
FsxHelper.GetSolution SolutionFile.Default

sanityCheckNugetPackagesFromSolution sol


FindOffendingPrintfUsage()
Expand Down

0 comments on commit e83032d

Please sign in to comment.