From bae93cdc1af994ecfd4d91ac8b891e11ecdb267f Mon Sep 17 00:00:00 2001 From: r6915ee Date: Mon, 6 Apr 2026 14:54:25 -0700 Subject: [PATCH] Add sum calculation functionality to dev CLI setup subcommand The subcommand uses this feature to compare the sha256 sums of the previous and current building/libs.xml files in order to decide whether or not to initiate the setup process. It adds an `--ignore-sum` flag to immediately pass the check used for this. This also clears up the help message for the subcommand in question, updates both `setup-` scripts to allow for variable arguments, and adds `--all` as an alias for `--reinstall`. --- .gitignore | 1 + building/setup-unix.sh | 2 +- building/setup-windows.bat | 2 +- commandline/Main.hx | 10 ++++++---- commandline/commands/Setup.hx | 32 +++++++++++++++++++++++++++++--- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 77035890a7..91cf20647c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ addons/* addons/* !addons/readme.txt dev-libs/ +*.sum diff --git a/building/setup-unix.sh b/building/setup-unix.sh index fbbffe5222..4a58b7b173 100755 --- a/building/setup-unix.sh +++ b/building/setup-unix.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh cd "$(dirname "$0")/.." -haxe -cp commandline -D analyzer-optimize --run Main setup \ No newline at end of file +haxe -cp commandline -D analyzer-optimize --run Main setup $@ diff --git a/building/setup-windows.bat b/building/setup-windows.bat index 2057fdc0e6..d7c9dc98c7 100644 --- a/building/setup-windows.bat +++ b/building/setup-windows.bat @@ -1,2 +1,2 @@ cd /d "%~dp0.." -@haxe -cp commandline -D analyzer-optimize --run Main setup \ No newline at end of file +@haxe -cp commandline -D analyzer-optimize --run Main setup %* diff --git a/commandline/Main.hx b/commandline/Main.hx index fe847ee51e..8cdb8ba99f 100644 --- a/commandline/Main.hx +++ b/commandline/Main.hx @@ -16,12 +16,14 @@ class Main { dDoc: [ "Usage: setup", "", - "This command runs through all libraries in building/libs.xml, and install them.", - "If they're already installed, they will be updated.", + "This command runs through all libraries in building/libs.xml, and installs them.", + "This will generate a sum file; if the building/libs.xml file has remained unchanged,", + "then the setup process will not start. This may be avoided by using --ignore-sum.", "", - "--all : Reinstall all libraries.", + "--all | --reinstall : Reinstall all libraries. This enforces --ignore-sum.", "--no-vscheck : Don't check if Visual Studio is installed.", - "-s | --silent | --silent-progress : Don't show download progress." + "-s | --silent | --silent-progress : Don't show download progress.", + "-i | --ignore-sum : Ignore the library sum file, proceeding with the setup process anyway." ].join("\n") }, { diff --git a/commandline/commands/Setup.hx b/commandline/commands/Setup.hx index 50b3a6a02f..bdc061663c 100644 --- a/commandline/commands/Setup.hx +++ b/commandline/commands/Setup.hx @@ -1,5 +1,6 @@ package commands; +import haxe.crypto.Sha256; import haxe.xml.Access; import haxe.Json; import sys.io.File; @@ -36,12 +37,15 @@ class Setup { var args = ArgParser.parse(args, [ "s" => "silent-progress", "S" => "silent-progress", + "all" => "reinstall", "silent" => "silent-progress", "f" => "fast", - "F" => "fast" + "F" => "fast", + "i" => "ignore-sum" ]); var CHECK_VSTUDIO = !args.existsOption("no-vscheck"); var REINSTALL_ALL = args.existsOption("reinstall"); + var IGNORE_SUM = REINSTALL_ALL || args.existsOption("ignore-sum"); var SILENT = args.existsOption("silent-progress"); var FAST = args.existsOption("fast"); // TODO: add only install missing libs @@ -68,8 +72,28 @@ class Setup { return; } + var libFileContents = File.getContent(libFile); + var libSum = Sha256.encode(libFileContents); + + var libSumFile = libFile + ".sum"; + var libSumToCompare = ""; + try { + var libSumFileContents = File.getContent(libSumFile); + if (!IGNORE_SUM && libSum == libSumFileContents) { + // Multiline strings are already awkward as-is in Haxe, so this just uses a buffer to emulate them. + var multiline = new StringBuf(); + multiline.add('libs.xml has remained unchanged since the last time the setup subcommand was run.\n'); + multiline.add('If you want to force a reinstall of the currently installed libraries, then please pass the --ignore-sum flag,\n'); + multiline.add('or delete the generated '); + multiline.add(libSumFile); + multiline.add(' file.'); + Sys.println(multiline); + return; + } + } catch (_) {} + final events:Array = []; - final libsXML:Access = new Access(Xml.parse(File.getContent(libFile)).firstElement()); + final libsXML:Access = new Access(Xml.parse(libFileContents).firstElement()); function handleLib(libNode:Access) { switch(libNode.name) { @@ -267,6 +291,8 @@ class Setup { } } } + + try File.saveContent(libSumFile, libSum) catch (_) {} // vswhere.exe is used to find any visual studio related installations on the system, including full visual studio ide installations, visual studio build tools installations, and other related components - Nex if (CHECK_VSTUDIO && Compiler.getBuildTarget().toLowerCase() == "windows" && new Process('"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -requires Microsoft.VisualStudio.Component.Windows10SDK.19041 -property installationPath').exitCode(true) != 0) { @@ -347,4 +373,4 @@ enum abstract EventType(Int) { var INSTALL = 0; var CMD = 1; var PRINT = 2; -} \ No newline at end of file +}