Skip to content

Commit

Permalink
scripts/configure.fsx: put Frontend in cfg summary
Browse files Browse the repository at this point in the history
To be able to reuse the way of checking for GTK via pkg-config
in both configure and Makefile we had to put it in fsxHelper.fs,
which in turn required me to convert a tuple into a function
(and add one more case to its potential error msg).
  • Loading branch information
knocte committed Aug 11, 2023
1 parent 93e2c74 commit d71e19d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
43 changes: 38 additions & 5 deletions scripts/configure.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ open System.Configuration
open Fsdk
open Fsdk.Process

#load "fsxHelper.fs"
open GWallet.Scripting

let rootDir = DirectoryInfo(Path.Combine(__SOURCE_DIRECTORY__, ".."))

let initialConfigFile, buildTool =
let initialConfigFile, buildTool, isGtkPresent =
match Misc.GuessPlatform() with
| Misc.Platform.Windows ->
let buildTool=
Expand All @@ -27,13 +29,13 @@ let initialConfigFile, buildTool =
| None ->
Process.VsWhere "MSBuild\\**\\Bin\\MSBuild.exe"

Map.empty, buildTool
Map.empty, buildTool, false
| platform (* Unix *) ->

Process.ConfigCommandCheck ["make"] true true |> ignore

match Process.ConfigCommandCheck ["dotnet"] false true with
| Some _ -> Map.empty, "dotnet"
| Some _ -> Map.empty, "dotnet", false
| None ->

Process.ConfigCommandCheck ["mono"] true true |> ignore
Expand All @@ -45,7 +47,7 @@ let initialConfigFile, buildTool =

if platform = Misc.Platform.Mac then
match Process.ConfigCommandCheck [ "msbuild"; "xbuild" ] true true with
| Some theBuildTool -> Map.empty, theBuildTool
| Some theBuildTool -> Map.empty, theBuildTool, false
| _ -> failwith "unreachable"
else
let buildTool =
Expand Down Expand Up @@ -90,7 +92,15 @@ let initialConfigFile, buildTool =
(stableVersionOfMono.ToString()))
Environment.Exit 1
Console.WriteLine "found"
Map.empty.Add("MonoPkgConfigVersion", monoVersion), buildTool

Console.Write "checking for GTK (libs)... "
let isGtkPresent = FsxHelper.IsGtkPresent()
if isGtkPresent then
Console.WriteLine "found"
else
Console.WriteLine "not found"

Map.empty.Add("MonoPkgConfigVersion", monoVersion), buildTool, isGtkPresent

#if LEGACY_FRAMEWORK
let targetsFileToExecuteNugetBeforeBuild = """<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -148,6 +158,26 @@ let version = Misc.GetCurrentVersion(rootDir)

let repoInfo = Git.GetRepoInfo()

let frontend =
match buildTool, Misc.GuessPlatform() with

// NOTE: 'dotnet build' cannot build Xamarin.Forms, and make.fsx doesn't support yet building
// with both dotnet & msbuild yet
| "dotnet", _ -> "Console"

| _, Misc.Platform.Linux ->
if isGtkPresent then
"Xamarin.Forms"
else
"Console"

// NOTE: even though Windows has msbuild too, its buildTool value contains full path so it won't
// match with the case below (and this is on purpose, since we don't build WinUI/UWP frontend yet)
| "msbuild", _ ->
"Xamarin.Forms"

| _ -> "Console"

Console.WriteLine()
Console.WriteLine(sprintf
"\tConfiguration summary for geewallet %s %s"
Expand All @@ -162,6 +192,9 @@ Console.WriteLine(sprintf
Console.WriteLine(sprintf
"\t* .NET build tool: %s"
(if buildTool = "dotnet" then "dotnet build" else buildTool))
Console.WriteLine(sprintf
"\t* Frontend: %s"
frontend)
Console.WriteLine()

Console.WriteLine "Configuration succeeded, you can now run `make`"
18 changes: 16 additions & 2 deletions scripts/fsxHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

open Fsdk
open Fsdk.Process

module FsxHelper =

Expand All @@ -19,7 +20,16 @@ module FsxHelper =
|> ignore
dir

let FsxRunnerBin,FsxRunnerArg =
let IsGtkPresent() =
if Misc.GuessPlatform() <> Misc.Platform.Linux then
failwith "Gtk is only supported in Linux"

let pkgConfigForGtkProc = Process.Execute({ Command = "pkg-config"; Arguments = "gtk-sharp-2.0" }, Echo.All)
match pkgConfigForGtkProc.Result with
| Error _ -> false
| _ -> true

let FsxRunnerInfo() =
match Misc.GuessPlatform() with
| Misc.Platform.Windows ->
#if !LEGACY_FRAMEWORK
Expand All @@ -34,6 +44,10 @@ module FsxHelper =
let msg = "FsxRunnerBin env var not found, it should have been sourced from build.config file"
let msgFull =
msg + Environment.NewLine +
"(maybe you meant to run a Makefile target rather than this script directly; or there is a .sh wrapper script for your .fsx script)"
(sprintf "(maybe you 1. %s, or 2. %s, or 3. %s)"
"called this from configure.fsx (which is not supported, just use this func from make.fsx or sanitycheck.fsx)"
"you meant to run a Makefile target rather than this script directly?"
"there is a .sh wrapper script for your .fsx script"
)
failwith msgFull
fsxRunnerBinEnvVar, fsxRunnerArgEnvVar
13 changes: 4 additions & 9 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,7 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =

Frontend.Console
| Misc.Platform.Linux ->
let pkgConfigForGtkProc = Process.Execute({ Command = "pkg-config"; Arguments = "gtk-sharp-2.0" }, Echo.All)
let isGtkPresent =
match pkgConfigForGtkProc.Result with
| Error _ -> false
| _ -> true

if isGtkPresent then
if FsxHelper.IsGtkPresent() then
let solution = LINUX_SOLUTION_FILE
#if LEGACY_FRAMEWORK
ExplicitRestore solution
Expand Down Expand Up @@ -615,10 +609,11 @@ match maybeTarget with
#endif

let sanityCheckScript = Path.Combine(FsxHelper.ScriptsDir.FullName, "sanitycheck.fsx")
let fsxRunnerBin,fsxRunnerArg = FsxHelper.FsxRunnerInfo()
Process.Execute(
{
Command = FsxHelper.FsxRunnerBin
Arguments = sprintf "%s %s" FsxHelper.FsxRunnerArg sanityCheckScript
Command = fsxRunnerBin
Arguments = sprintf "%s %s" fsxRunnerArg sanityCheckScript
},
Echo.All
).UnwrapDefault() |> ignore<string>
Expand Down
5 changes: 3 additions & 2 deletions scripts/sanitycheck.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ let FindOffendingPrintfUsage () =
Path.DirectorySeparatorChar
)

let fsxRunnerBin, fsxRunnerArg = FsxHelper.FsxRunnerInfo()
let proc =
{
Command = FsxHelper.FsxRunnerBin
Command = fsxRunnerBin
Arguments = sprintf "%s %s --exclude=%s %s"
FsxHelper.FsxRunnerArg
fsxRunnerArg
findScript
excludeFolders
"printf failwithf"
Expand Down

0 comments on commit d71e19d

Please sign in to comment.