Skip to content

Commit f59d988

Browse files
authored
Add sum/hash match functionality to dev CLI setup subcommand (#953)
* 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`. * Update workflows to use --ignore-sum flag on setup
1 parent 350f824 commit f59d988

8 files changed

Lines changed: 45 additions & 16 deletions

File tree

.github/workflows/linux.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
sudo apt-get install libvlc-dev libvlccore-dev
3737
- name: Installing/Updating libraries
3838
run: |
39-
haxe -cp commandline -D analyzer-optimize --run Main setup -s
39+
haxe -cp commandline -D analyzer-optimize --run Main setup -si
4040
- name: Building the game
4141
run: |
4242
haxelib run lime build linux -DCOMPILE_EXPERIMENTAL
@@ -108,7 +108,7 @@ jobs:
108108
sudo apt-get install libvlc-dev libvlccore-dev
109109
- name: Installing/Updating libraries
110110
run: |
111-
haxe -cp commandline -D analyzer-optimize --run Main setup -s
111+
haxe -cp commandline -D analyzer-optimize --run Main setup -si
112112
- name: Building the game
113113
run: |
114114
haxelib run lime build linux -debug

.github/workflows/macos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
export/release/macos/obj/
3434
- name: Installing/Updating libraries
3535
run: |
36-
haxe -cp commandline -D analyzer-optimize --run Main setup -s
36+
haxe -cp commandline -D analyzer-optimize --run Main setup -si
3737
- name: Building the game
3838
run: |
3939
arch -x86_64 haxelib run lime build mac -DCOMPILE_EXPERIMENTAL
@@ -102,7 +102,7 @@ jobs:
102102
export/debug/macos/obj/
103103
- name: Installing/Updating libraries
104104
run: |
105-
haxe -cp commandline -D analyzer-optimize --run Main setup -s
105+
haxe -cp commandline -D analyzer-optimize --run Main setup -si
106106
- name: Building the game
107107
run: |
108108
arch -x86_64 haxelib run lime build mac -debug

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
export/release/windows/obj/
3434
- name: Installing/Updating libraries
3535
run: |
36-
haxe -cp commandline -D analyzer-optimize --run Main setup -s --no-vscheck
36+
haxe -cp commandline -D analyzer-optimize --run Main setup -si --no-vscheck
3737
- name: Building the game
3838
run: |
3939
haxelib run lime build windows -DCOMPILE_EXPERIMENTAL
@@ -100,7 +100,7 @@ jobs:
100100
export/debug/windows/obj/
101101
- name: Installing/Updating libraries
102102
run: |
103-
haxe -cp commandline -D analyzer-optimize --run Main setup -s --no-vscheck
103+
haxe -cp commandline -D analyzer-optimize --run Main setup -si --no-vscheck
104104
- name: Building the game
105105
run: |
106106
haxelib run lime build windows -debug

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ addons/*
1313
addons/*
1414
!addons/readme.txt
1515
dev-libs/
16-
.vs/
16+
*.sum
17+
.vs/

building/setup-unix.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env sh
22
cd "$(dirname "$0")/.."
3-
haxe -cp commandline -D analyzer-optimize --run Main setup
3+
haxe -cp commandline -D analyzer-optimize --run Main setup $@

building/setup-windows.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
cd /d "%~dp0.."
2-
@haxe -cp commandline -D analyzer-optimize --run Main setup
2+
@haxe -cp commandline -D analyzer-optimize --run Main setup %*

commandline/Main.hx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ class Main {
1616
dDoc: [
1717
"Usage: setup",
1818
"",
19-
"This command runs through all libraries in building/libs.xml, and install them.",
20-
"If they're already installed, they will be updated.",
19+
"This command runs through all libraries in building/libs.xml, and installs them.",
20+
"This will generate a sum file; if the building/libs.xml file has remained unchanged,",
21+
"then the setup process will not start. This may be avoided by using --ignore-sum.",
2122
"",
22-
"--all : Reinstall all libraries.",
23+
"--all | --reinstall : Reinstall all libraries. This enforces --ignore-sum.",
2324
"--no-vscheck : Don't check if Visual Studio is installed.",
24-
"-s | --silent | --silent-progress : Don't show download progress."
25+
"-s | --silent | --silent-progress : Don't show download progress.",
26+
"-i | --ignore-sum : Ignore the library sum file, proceeding with the setup process anyway."
2527
].join("\n")
2628
},
2729
{

commandline/commands/Setup.hx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package commands;
22

3+
import haxe.crypto.Sha256;
34
import haxe.xml.Access;
45
import haxe.Json;
56
import sys.io.File;
@@ -36,12 +37,15 @@ class Setup {
3637
var args = ArgParser.parse(args, [
3738
"s" => "silent-progress",
3839
"S" => "silent-progress",
40+
"all" => "reinstall",
3941
"silent" => "silent-progress",
4042
"f" => "fast",
41-
"F" => "fast"
43+
"F" => "fast",
44+
"i" => "ignore-sum"
4245
]);
4346
var CHECK_VSTUDIO = !args.existsOption("no-vscheck");
4447
var REINSTALL_ALL = args.existsOption("reinstall");
48+
var IGNORE_SUM = REINSTALL_ALL || args.existsOption("ignore-sum");
4549
var SILENT = args.existsOption("silent-progress");
4650
var FAST = args.existsOption("fast");
4751
// TODO: add only install missing libs
@@ -68,8 +72,28 @@ class Setup {
6872
return;
6973
}
7074

75+
var libFileContents = File.getContent(libFile);
76+
var libSum = Sha256.encode(libFileContents);
77+
78+
var libSumFile = libFile + ".sum";
79+
var libSumToCompare = "";
80+
try {
81+
var libSumFileContents = File.getContent(libSumFile);
82+
if (!IGNORE_SUM && libSum == libSumFileContents) {
83+
// Multiline strings are already awkward as-is in Haxe, so this just uses a buffer to emulate them.
84+
var multiline = new StringBuf();
85+
multiline.add('libs.xml has remained unchanged since the last time the setup subcommand was run.\n');
86+
multiline.add('If you want to force a reinstall of the currently installed libraries, then please pass the --ignore-sum flag,\n');
87+
multiline.add('or delete the generated ');
88+
multiline.add(libSumFile);
89+
multiline.add(' file.');
90+
Sys.println(multiline);
91+
return;
92+
}
93+
} catch (_) {}
94+
7195
final events:Array<Event> = [];
72-
final libsXML:Access = new Access(Xml.parse(File.getContent(libFile)).firstElement());
96+
final libsXML:Access = new Access(Xml.parse(libFileContents).firstElement());
7397

7498
function handleLib(libNode:Access) {
7599
switch(libNode.name) {
@@ -267,6 +291,8 @@ class Setup {
267291
}
268292
}
269293
}
294+
295+
try File.saveContent(libSumFile, libSum) catch (_) {}
270296

271297
// 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
272298
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) {
347373
var INSTALL = 0;
348374
var CMD = 1;
349375
var PRINT = 2;
350-
}
376+
}

0 commit comments

Comments
 (0)