From 47537432be2f7439d72451d73c1dec108a951608 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sun, 13 Aug 2023 10:50:58 +0800 Subject: [PATCH] build: Remove Nuget.Restore.targets This was kzu's project[1] which had a very interesting goal: make nuget restore be part of the build process itself (kind of like a PreBuild target so that your IDE did the restore before building, regardless if the IDE had nuget support or not). Now, there's several reasons to remove it (ordered by level of importance): 1. We're moving soon to dotnet v6 and newer, where a restore is always assumed by the IDEs and command-line builds (the command is even called "dotnet restore" itself, no need to specify "nuget" anymore, as the term 'restore' has become part of the dotnet jargon already). 2. Looking back, I introduced it in 2017 [2] but I kinda regret doing it because of all the hacks (such as needing to generate the special file 'before.$solutionFileName.targets before the build) required to make it work, the ugliness of its code (not really blaming the author here, maybe MSBuild's XML syntax is generally unreadable), and: 3. The fact that despite the use of it, there were certain sccenarios that needed an explicit restore of other solutions/projects to make the build work with Xamarin.Forms. So as there were explicit restores happening in make.fsx anyway, let's make nuget restore explicitly handled now in all cases by make.fsx (this quirk will not live very long anyway, just as long as the Xamarin.Forms frontend lives, which is getting replaced by MAUI soon). [1] https://github.com/kzu/Nuget.Restore [2] 9804b653a63266c8560c7e8143f9ec644f05a334 --- .gitignore | 3 - NuGet.Restore.targets | 170 ------------------------------------------ scripts/configure.fsx | 13 +--- scripts/make.fsx | 61 +++++++++------ 4 files changed, 38 insertions(+), 209 deletions(-) delete mode 100644 NuGet.Restore.targets diff --git a/.gitignore b/.gitignore index f1d54e208..8c6982c30 100644 --- a/.gitignore +++ b/.gitignore @@ -22,9 +22,6 @@ TestResult.xml # backup files of some editors such as nano *~ -# autogenerated file by configure.sh -before.gwallet.core-legacy.sln.targets - # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 diff --git a/NuGet.Restore.targets b/NuGet.Restore.targets deleted file mode 100644 index f6755a9c2..000000000 --- a/NuGet.Restore.targets +++ /dev/null @@ -1,170 +0,0 @@ - - - - $(MSBuildThisFileDirectory).nuget - https://dist.nuget.org/win-x86-commandline/v5.4.0/nuget.exe - $(NuGetPath)\nuget.exe - mono - $(TMPDIR) - - https://raw.githubusercontent.com/kzu/NuGet.Restore/master/ - $(BaseUrl)curl.exe - -k -f -L - "$(TEMP)\curl.exe" $(CurlArgs) - curl $(CurlArgs) - %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe - - - ErrorAndStop - - quiet - normal - $(MSBuildThisFilename)$(MSBuildThisFileExtension) - - - - - - - - - - Restore - -verbosity $(RestoreLoggingVerbosity) - - - - - - - - - - - - - $([System.IO.Path]::GetDirectoryName('$(SolutionPath)')) - - - - <_NuGet>$(NuGet) - <_RestoreDir>$(RestoreDir) - <_RestoreDir Condition="'$(_RestoreDir)' == ''">%(RestoreSolution.RootDir)%(RestoreSolution.Directory) - - <_NuGet Condition=" '$(RestoreDir)' != ''">$(_NuGet.Replace('$(RestoreDir)', '').TrimStart('/').TrimStart('\')) - - - - - - - - - - - - - - - - - <_RestoreSolution Condition=" '$(OS)' != 'Unix' And '$(_RestoreDir)' != ''">$(_RestoreSolution.Replace('$(_RestoreDir)', '').TrimStart('/').TrimStart('\')) - <_RestoreOutput Condition=" '$(OS)' != 'Unix' And '$(_RestoreOutput)' != '' And '$(_RestoreDir)' != ''">$(_RestoreOutput.Replace('$(_RestoreDir)', '').TrimStart('/').TrimStart('\')) - - <_RestoreCommand Condition=" '$(_RestoreCommand)' == '' ">Restore - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @(ETag) - $(ETag.Substring(5).Trim().TrimStart('"').TrimEnd('"')) - - <Namespace Prefix='msb' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/> - $(MSBuildThisFileFullPath) - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - 1D1D4F4E2A49280 - - - diff --git a/scripts/configure.fsx b/scripts/configure.fsx index 5cec296c5..a5f34c3ec 100755 --- a/scripts/configure.fsx +++ b/scripts/configure.fsx @@ -51,7 +51,7 @@ let initialConfigFile, buildTool, areGtkLibsAbsentOrDoesNotApply = Process.ConfigCommandCheck ["mono"] true true |> ignore Process.ConfigCommandCheck ["fsharpc"] true true |> ignore - // needed by NuGet.Restore.targets & the "update-servers" Makefile target + // needed by the "update-servers" Makefile target? Process.ConfigCommandCheck ["curl"] true true |> ignore @@ -118,17 +118,6 @@ let initialConfigFile, buildTool, areGtkLibsAbsentOrDoesNotApply = Map.empty.Add("MonoPkgConfigVersion", monoVersion), buildTool, areGtkLibsAbsentOrDoesNotApply -#if LEGACY_FRAMEWORK -let targetsFileToExecuteNugetBeforeBuild = """ - - - -""" -File.WriteAllText(Path.Combine(rootDir.FullName, "before.gwallet.core-legacy.sln.targets"), - targetsFileToExecuteNugetBeforeBuild) -#endif - let prefix = DirectoryInfo(Misc.GatherOrGetDefaultPrefix(Misc.FsxOnlyArguments(), false, None)) if not (prefix.Exists) then diff --git a/scripts/make.fsx b/scripts/make.fsx index c55468a39..9d4f3a210 100644 --- a/scripts/make.fsx +++ b/scripts/make.fsx @@ -33,7 +33,12 @@ open GWallet.Scripting let UNIX_NAME = "geewallet" let CONSOLE_FRONTEND = "GWallet.Frontend.Console" let GTK_FRONTEND = "GWallet.Frontend.XF.Gtk" -let DEFAULT_SOLUTION_FILE = "gwallet.core.sln" +let DEFAULT_SOLUTION_FILE = +#if !LEGACY_FRAMEWORK + "gwallet.core.sln" +#else + "gwallet.core-legacy.sln" +#endif let LINUX_SOLUTION_FILE = "gwallet.linux-legacy.sln" let MAC_SOLUTION_FILE = "gwallet.mac-legacy.sln" let BACKEND = "GWallet.Backend" @@ -126,6 +131,18 @@ exec mono "$FRONTEND_PATH" "$@" """ #if LEGACY_FRAMEWORK +let NugetRestore projectOrSolutionRelativePath = + let nugetArgs = + sprintf + "restore %s -SolutionDirectory ." + projectOrSolutionRelativePath + Network.RunNugetCommand + FsxHelper.NugetExe + nugetArgs + Echo.All + true + |> ignore + let PrintNugetVersion () = if not (FsxHelper.NugetExe.Exists) then false @@ -157,6 +174,10 @@ let BuildSolution (maybeConstant: Option) (extraOptions: string) = +#if LEGACY_FRAMEWORK + NugetRestore solutionFileName +#endif + let buildTool,buildArg = buildToolAndBuildArg let configOption = @@ -223,8 +244,8 @@ let BuildSolution let JustBuild binaryConfig maybeConstant: Frontend*FileInfo = let maybeBuildTool = Map.tryFind "BuildTool" buildConfigContents - let mainSolution = DEFAULT_SOLUTION_FILE - let buildTool,buildArg,solutionFileName = + let solutionFileName = DEFAULT_SOLUTION_FILE + let buildTool,buildArg = match maybeBuildTool with | None -> failwith "A BuildTool should have been chosen by the configure script, please report this bug" @@ -232,7 +253,7 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo = #if LEGACY_FRAMEWORK failwith "'dotnet' shouldn't be the build tool when using legacy framework, please report this bug" #endif - "dotnet", "build", mainSolution + "dotnet", "build" | Some otherBuildTool -> #if LEGACY_FRAMEWORK let nugetConfig = @@ -247,9 +268,9 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo = |> FileInfo File.Copy(legacyNugetConfig.FullName, nugetConfig.FullName, true) - otherBuildTool, String.Empty, "gwallet.core-legacy.sln" + otherBuildTool, String.Empty #else - otherBuildTool, String.Empty, mainSolution + otherBuildTool, String.Empty #endif Console.WriteLine (sprintf "Building in %s mode..." (binaryConfig.ToString())) @@ -265,22 +286,6 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo = // older mono versions (which only have xbuild, not msbuild) can't compile .NET Standard assemblies if buildTool = "msbuild" then -#if LEGACY_FRAMEWORK - // 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: report this bug - let ExplicitRestore projectOrSolutionRelativePath = - let nugetWorkaroundArgs = - sprintf - "restore %s -SolutionDirectory ." - projectOrSolutionRelativePath - Network.RunNugetCommand - FsxHelper.NugetExe - nugetWorkaroundArgs - Echo.All - true - |> ignore -#endif - let MSBuildRestoreAndBuild solutionFile = BuildSolution ("msbuild",buildArg) solutionFile binaryConfig maybeConstant "/t:Restore" // TODO: report as a bug the fact that /t:Restore;Build doesn't work while /t:Restore and later /t:Build does @@ -293,7 +298,9 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo = if binaryConfig = BinaryConfig.Debug then let solution = MAC_SOLUTION_FILE #if LEGACY_FRAMEWORK - ExplicitRestore solution + // 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 #endif MSBuildRestoreAndBuild solution @@ -302,7 +309,9 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo = if FsxHelper.AreGtkLibsPresent Echo.All then let solution = LINUX_SOLUTION_FILE #if LEGACY_FRAMEWORK - ExplicitRestore solution + // 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 #endif MSBuildRestoreAndBuild solution @@ -367,6 +376,10 @@ let GetPathToBackend () = Path.Combine (FsxHelper.RootDir.FullName, "src", BACKEND) let MakeAll (maybeConstant: Option) = +#if LEGACY_FRAMEWORK + if not FsxHelper.NugetExe.Exists then + Network.DownloadNugetExe FsxHelper.NugetExe +#endif let buildConfig = BinaryConfig.Debug let frontend,_ = JustBuild buildConfig maybeConstant frontend,buildConfig