From f2d1b75d1f135f04b0e9718ba28b9adfb640efa0 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 24 Dec 2023 22:46:30 +0100 Subject: [PATCH] Improve build tool api for deps modules --- .../Flax.Build/Deps/Dependencies/OpenAL.cs | 6 ++-- .../Flax.Build/Deps/Dependencies/astc.cs | 2 +- .../Flax.Build/Deps/Dependencies/freetype.cs | 8 ++--- .../Tools/Flax.Build/Deps/Dependencies/ogg.cs | 8 ++--- .../Flax.Build/Deps/Dependencies/vorbis.cs | 8 ++--- Source/Tools/Flax.Build/Deps/Dependency.cs | 36 ++++++++++++------- .../Tools/Flax.Build/Utilities/Utilities.cs | 5 +++ 7 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs index 96ef05dd8..d0390eff7 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs @@ -147,7 +147,7 @@ namespace Flax.Deps.Dependencies // Build RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); @@ -176,7 +176,7 @@ namespace Flax.Deps.Dependencies { SetupDirectory(buildDir, true); RunCmake(buildDir, platform, architecture, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, architecture); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); @@ -206,7 +206,7 @@ namespace Flax.Deps.Dependencies // Build for iOS SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_SYSTEM_NAME=iOS -DALSOFT_OSX_FRAMEWORK=ON -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/astc.cs b/Source/Tools/Flax.Build/Deps/Dependencies/astc.cs index adbc54438..f062cd91d 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/astc.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/astc.cs @@ -49,7 +49,7 @@ namespace Flax.Deps.Dependencies var lib = architecture == TargetArchitecture.ARM64 ? "libastcenc-neon-static.a" : "libastcenc-sse2-static.a"; SetupDirectory(buildDir, true); RunCmake(buildDir, platform, architecture, ".. -DCMAKE_BUILD_TYPE=Release -DASTCENC_UNIVERSAL_BUILD=OFF -DASTCENC_UNIVERSAL_BINARY=OFF " + isa); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, architecture); Utilities.FileCopy(Path.Combine(buildDir, "Source", lib), Path.Combine(depsFolder, "libastcenc.a")); } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs b/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs index d2d31a613..4efe4ed43 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs @@ -229,7 +229,7 @@ namespace Flax.Deps.Dependencies // Build for Android SetupDirectory(buildDir, true); RunCmake(buildDir, TargetPlatform.Android, TargetArchitecture.ARM64, ".. -DFT_WITH_BZIP2=OFF -DFT_WITH_ZLIB=OFF -DFT_WITH_PNG=OFF -DCMAKE_BUILD_TYPE=Release"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; @@ -239,7 +239,7 @@ namespace Flax.Deps.Dependencies // Build for Switch SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_BUILD_TYPE=Release"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; @@ -251,7 +251,7 @@ namespace Flax.Deps.Dependencies { SetupDirectory(buildDir, true); RunCmake(buildDir, platform, architecture, ".. -DCMAKE_BUILD_TYPE=Release"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, architecture); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); } @@ -268,7 +268,7 @@ namespace Flax.Deps.Dependencies // Build for iOS SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DIOS_PLATFORM=OS -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_BUILD_TYPE=Release -DFT_WITH_BZIP2=OFF -DFT_WITH_ZLIB=OFF -DFT_WITH_PNG=OFF"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs b/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs index eb02accef..1716ff08d 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs @@ -196,7 +196,7 @@ namespace Flax.Deps.Dependencies // Build for Android SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_BUILD_TYPE=Release"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; @@ -209,7 +209,7 @@ namespace Flax.Deps.Dependencies // Build for Switch SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_BUILD_TYPE=Release"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; @@ -221,7 +221,7 @@ namespace Flax.Deps.Dependencies { SetupDirectory(buildDir, true); RunCmake(buildDir, platform, architecture, ".. -DCMAKE_BUILD_TYPE=Release"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, architecture); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); } @@ -231,7 +231,7 @@ namespace Flax.Deps.Dependencies { SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_BUILD_TYPE=Release"); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs b/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs index c3a53ebd4..b6acc4bf9 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs @@ -331,7 +331,7 @@ namespace Flax.Deps.Dependencies Utilities.Run("cmake", "--build . --target install", null, oggBuildDir, Utilities.RunOptions.ConsoleLogOutput); SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, string.Format(".. -DCMAKE_BUILD_TYPE=Release -DOGG_INCLUDE_DIR=\"{0}/install/include\" -DOGG_LIBRARY=\"{0}/install/lib\"", oggRoot)); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var file in binariesToCopyUnix) Utilities.FileCopy(Path.Combine(buildDir, file.SrcFolder, file.Filename), Path.Combine(depsFolder, file.Filename)); @@ -358,7 +358,7 @@ namespace Flax.Deps.Dependencies Utilities.FileCopy(Path.Combine(GetBinariesFolder(options, platform), "ogg", "include", "ogg", "config_types.h"), Path.Combine(oggRoot, "install", "include", "ogg", "config_types.h")); SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, string.Format(".. -DCMAKE_BUILD_TYPE=Release -DOGG_INCLUDE_DIR=\"{0}/install/include\" -DOGG_LIBRARY=\"{0}/install/lib\"", oggRoot)); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var file in binariesToCopyUnix) Utilities.FileCopy(Path.Combine(buildDir, file.SrcFolder, file.Filename), Path.Combine(depsFolder, file.Filename)); @@ -383,7 +383,7 @@ namespace Flax.Deps.Dependencies Utilities.Run("cmake", "--build . --target install", null, oggBuildDir, Utilities.RunOptions.ConsoleLogOutput); SetupDirectory(buildDir, true); RunCmake(buildDir, platform, architecture, string.Format(".. -DCMAKE_BUILD_TYPE=Release -DOGG_INCLUDE_DIR=\"{0}/install/include\" -DOGG_LIBRARY=\"{0}/install/lib\"", oggRoot)); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, architecture); foreach (var file in binariesToCopyUnix) Utilities.FileCopy(Path.Combine(buildDir, file.SrcFolder, file.Filename), Path.Combine(depsFolder, file.Filename)); @@ -407,7 +407,7 @@ namespace Flax.Deps.Dependencies Utilities.Run("cmake", "--build . --target install", null, oggBuildDir, Utilities.RunOptions.ConsoleLogOutput); SetupDirectory(buildDir, true); RunCmake(buildDir, platform, TargetArchitecture.ARM64, string.Format(".. -DCMAKE_BUILD_TYPE=Release -DOGG_INCLUDE_DIR=\"{0}/install/include\" -DOGG_LIBRARY=\"{0}/install/lib\"", oggRoot)); - Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.ConsoleLogOutput); + BuildCmake(buildDir); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var file in binariesToCopyUnix) Utilities.FileCopy(Path.Combine(buildDir, file.SrcFolder, file.Filename), Path.Combine(depsFolder, file.Filename)); diff --git a/Source/Tools/Flax.Build/Deps/Dependency.cs b/Source/Tools/Flax.Build/Deps/Dependency.cs index e9b646a6b..db65289c4 100644 --- a/Source/Tools/Flax.Build/Deps/Dependency.cs +++ b/Source/Tools/Flax.Build/Deps/Dependency.cs @@ -136,14 +136,14 @@ namespace Flax.Deps if (submodules) cmdLine += " --recurse-submodules"; - Utilities.Run("git", cmdLine, null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", cmdLine, null, null, Utilities.RunOptions.DefaultTool); if (submodules) - Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.DefaultTool); } if (commit != null) { - Utilities.Run("git", string.Format("reset --hard {0}", commit), null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", string.Format("reset --hard {0}", commit), null, null, Utilities.RunOptions.DefaultTool); } } @@ -164,9 +164,9 @@ namespace Flax.Deps if (submodules) cmdLine += " --recurse-submodules"; - Utilities.Run("git", cmdLine, null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", cmdLine, null, null, Utilities.RunOptions.DefaultTool); if (submodules) - Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.DefaultTool); } } @@ -191,14 +191,14 @@ namespace Flax.Deps if (submodules) cmdLine += " --recurse-submodules"; - Utilities.Run("git", cmdLine, null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", cmdLine, null, null, Utilities.RunOptions.DefaultTool); if (submodules) - Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.DefaultTool); } if (commit != null) { - Utilities.Run("git", string.Format("reset --hard {0}", commit), null, path, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", string.Format("reset --hard {0}", commit), null, path, Utilities.RunOptions.DefaultTool); } } @@ -218,13 +218,13 @@ namespace Flax.Deps if (submodules) cmdLine += " --recurse-submodules"; - Utilities.Run("git", cmdLine, null, path, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", cmdLine, null, path, Utilities.RunOptions.DefaultTool); if (submodules) - Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", "submodule update --init --recursive", null, null, Utilities.RunOptions.DefaultTool); if (commit != null) { - Utilities.Run("git", string.Format("reset --hard {0}", commit), null, path, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", string.Format("reset --hard {0}", commit), null, path, Utilities.RunOptions.DefaultTool); } } @@ -234,7 +234,17 @@ namespace Flax.Deps /// The local path that contains git repository. public static void GitResetLocalChanges(string path) { - Utilities.Run("git", "reset --hard", null, path, Utilities.RunOptions.ConsoleLogOutput); + Utilities.Run("git", "reset --hard", null, path, Utilities.RunOptions.DefaultTool); + } + + /// + /// Builds the cmake project. + /// + /// The path. + /// Custom environment variables to pass to the child process. + public static void BuildCmake(string path, Dictionary envVars = null) + { + Utilities.Run("cmake", "--build .", null, path, Utilities.RunOptions.DefaultTool, envVars); } /// @@ -313,7 +323,7 @@ namespace Flax.Deps if (customArgs != null) cmdLine += " " + customArgs; - Utilities.Run("cmake", cmdLine, null, path, Utilities.RunOptions.ConsoleLogOutput, envVars); + Utilities.Run("cmake", cmdLine, null, path, Utilities.RunOptions.DefaultTool, envVars); } /// diff --git a/Source/Tools/Flax.Build/Utilities/Utilities.cs b/Source/Tools/Flax.Build/Utilities/Utilities.cs index b001eea3f..bf7c24e1a 100644 --- a/Source/Tools/Flax.Build/Utilities/Utilities.cs +++ b/Source/Tools/Flax.Build/Utilities/Utilities.cs @@ -324,6 +324,11 @@ namespace Flax.Build /// The default options. /// Default = AppMustExist, + + /// + /// The default options for tools execution in build tool. + /// + DefaultTool = ConsoleLogOutput | ThrowExceptionOnError, } private static void StdLogInfo(object sender, DataReceivedEventArgs e)