Skip to content

Commit fe829aa

Browse files
Update state serialization (#962)
* Update state serialization * Use `Scratch` instead of `MutableArtifacts.toml` * Add tests to ensure that the state is serialized faithfully * Update wizard.jl * Only compare serializeable fields in a WizardState * Call `Wizard.load_wizard_state` non-interactively in tests * Allow JLD2 v0.2 Co-authored-by: Mosè Giordano <[email protected]>
1 parent 6d069e2 commit fe829aa

File tree

5 files changed

+75
-30
lines changed

5 files changed

+75
-30
lines changed

Manifest.toml

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
2828

2929
[[BinaryBuilderBase]]
3030
deps = ["CodecZlib", "Downloads", "InteractiveUtils", "JSON", "LibGit2", "Libdl", "Logging", "OutputCollectors", "Pkg", "Random", "SHA", "Scratch", "SimpleBufferStream", "TOML", "Tar", "UUIDs", "p7zip_jll", "pigz_jll"]
31-
git-tree-sha1 = "ba037f06ff8be240fcbd33c4ec4a397ebb9a9329"
31+
git-tree-sha1 = "0642b01b5f9a13170beb12f1dc5f35153029b104"
3232
repo-rev = "master"
3333
repo-url = "https://github.com/JuliaPackaging/BinaryBuilderBase.jl.git"
3434
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
@@ -40,16 +40,22 @@ git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da"
4040
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
4141
version = "0.7.0"
4242

43+
[[Compat]]
44+
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
45+
git-tree-sha1 = "919c7f3151e79ff196add81d7f4e45d91bbf420b"
46+
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
47+
version = "3.25.0"
48+
4349
[[DataAPI]]
44-
git-tree-sha1 = "6d64b28d291cb94a0d84e6e41081fb081e7f717f"
50+
git-tree-sha1 = "8ab70b4de35bb3b8cc19654f6b893cf5164f8ee8"
4551
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
46-
version = "1.5.0"
52+
version = "1.5.1"
4753

4854
[[DataStructures]]
49-
deps = ["InteractiveUtils", "OrderedCollections"]
50-
git-tree-sha1 = "88d48e133e6d3dd68183309877eac74393daa7eb"
55+
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
56+
git-tree-sha1 = "4437b64df1e0adccc3e5d1adbc3ac741095e4677"
5157
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
52-
version = "0.17.20"
58+
version = "0.18.9"
5359

5460
[[DataValueInterfaces]]
5561
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
@@ -60,6 +66,10 @@ version = "1.0.0"
6066
deps = ["Printf"]
6167
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
6268

69+
[[DelimitedFiles]]
70+
deps = ["Mmap"]
71+
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
72+
6373
[[Distributed]]
6474
deps = ["Random", "Serialization", "Sockets"]
6575
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
@@ -68,12 +78,6 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
6878
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
6979
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
7080

71-
[[FileIO]]
72-
deps = ["Pkg"]
73-
git-tree-sha1 = "fee8955b9dfa7bec67117ef48085fb2b559b9c22"
74-
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
75-
version = "1.4.5"
76-
7781
[[FileWatching]]
7882
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
7983

@@ -117,10 +121,10 @@ uuid = "82899510-4779-5014-852e-03e436cf321d"
117121
version = "1.0.0"
118122

119123
[[JLD2]]
120-
deps = ["CodecZlib", "DataStructures", "FileIO", "Mmap", "Pkg", "Printf", "UUIDs"]
121-
git-tree-sha1 = "9353b717ee4e27beab4e902c92a06bb5f160d2cf"
124+
deps = ["CodecZlib", "DataStructures", "MacroTools", "Mmap", "Pkg", "Printf", "Requires", "UUIDs"]
125+
git-tree-sha1 = "1b8168c14939e43c7c4d2c9e8f0ddd8718965430"
122126
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
123-
version = "0.1.14"
127+
version = "0.2.4"
124128

125129
[[JLLWrappers]]
126130
git-tree-sha1 = "a431f5f2ca3f4feef3bd7a5e94b8b8d4f2f647a0"
@@ -167,9 +171,9 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
167171

168172
[[LoggingExtras]]
169173
deps = ["Dates"]
170-
git-tree-sha1 = "70518b2cce1fea30c5e9dd0c44407a90f394de47"
174+
git-tree-sha1 = "95e675246b58a7cb1199a90cd50a25850ff215c7"
171175
uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36"
172-
version = "0.4.4"
176+
version = "0.4.5"
173177

174178
[[MacroTools]]
175179
deps = ["Markdown", "Random"]
@@ -286,6 +290,12 @@ git-tree-sha1 = "60522125b10a3b71b07677302c3aedd0b4363835"
286290
uuid = "d1eb7eb1-105f-429d-abf5-b0f65cb9e2c4"
287291
version = "1.5.3"
288292

293+
[[Requires]]
294+
deps = ["UUIDs"]
295+
git-tree-sha1 = "cfbac6c1ed70c002ec6361e7fd334f02820d6419"
296+
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
297+
version = "1.1.2"
298+
289299
[[SHA]]
290300
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
291301

@@ -298,6 +308,10 @@ version = "1.0.3"
298308
[[Serialization]]
299309
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
300310

311+
[[SharedArrays]]
312+
deps = ["Distributed", "Mmap", "Random", "Serialization"]
313+
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
314+
301315
[[SimpleBufferStream]]
302316
git-tree-sha1 = "874e8867b33a00e784c8a7e4b60afe9e037b74e1"
303317
uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7"
@@ -312,6 +326,14 @@ git-tree-sha1 = "80cef67d2953e33935b41c6ab0a178b9987b1c99"
312326
uuid = "2133526b-2bfb-4018-ac12-889fb3908a75"
313327
version = "0.1.1"
314328

329+
[[SparseArrays]]
330+
deps = ["LinearAlgebra", "Random"]
331+
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
332+
333+
[[Statistics]]
334+
deps = ["LinearAlgebra", "SparseArrays"]
335+
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
336+
315337
[[StructIO]]
316338
deps = ["Test"]
317339
git-tree-sha1 = "010dc73c7146869c042b49adcdb6bf528c12e859"
@@ -330,9 +352,9 @@ version = "1.0.0"
330352

331353
[[Tables]]
332354
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
333-
git-tree-sha1 = "8dc2bb7d3548e315d890706547b24502ed79504f"
355+
git-tree-sha1 = "a716dde43d57fa537a19058d044b495301ba6565"
334356
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
335-
version = "1.3.1"
357+
version = "1.3.2"
336358

337359
[[Tar]]
338360
deps = ["ArgTools", "SHA"]

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2626
Registrator = "4418983a-e44d-11e8-3aec-9789530b3b3e"
2727
RegistryTools = "d1eb7eb1-105f-429d-abf5-b0f65cb9e2c4"
2828
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
29+
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
2930
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
3031
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
3132
ghr_jll = "07c12ed4-43bc-5495-8a2a-d5838ef8d533"
@@ -35,7 +36,7 @@ ArgParse = "1.1"
3536
BinaryBuilderBase = "0.5"
3637
GitHub = "5.1"
3738
HTTP = "0.8"
38-
JLD2 = "0.1.6"
39+
JLD2 = "0.1.6, 0.2"
3940
JLLWrappers = "1.2.0"
4041
JSON = "0.21"
4142
LoggingExtras = "0.4"

src/Wizard.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import PkgLicenses
1515
using JLD2
1616
using Base.BinaryPlatforms
1717
using Dates
18+
using Scratch
1819

1920
# It's Magic (TM)!
2021
export run_wizard, deploy
@@ -27,17 +28,16 @@ include("wizard/obtain_source.jl")
2728
include("wizard/interactive_build.jl")
2829
include("wizard/deploy.jl")
2930

30-
function save_last_wizard_state(state::WizardState)
31-
BinaryBuilderBase.create_and_bind_mutable_artifact!("wizard_state") do dir
32-
jldopen(joinpath(dir, "wizard.state"), "w") do f
33-
serialize(f, state)
34-
end
31+
function save_wizard_state(state::WizardState,
32+
wizard_state_dir::String = @get_scratch!("wizard_state"))
33+
jldopen(joinpath(wizard_state_dir, "wizard.state"), "w") do f
34+
serialize(f, state)
3535
end
3636
return state
3737
end
3838

39-
function load_last_wizard_state(; as_is::Bool = false)
40-
wizard_state_dir = BinaryBuilderBase.get_mutable_artifact_path("wizard_state")
39+
function load_wizard_state(wizard_state_dir::String = @get_scratch!("wizard_state");
40+
as_is::Bool = false)
4141

4242
# If no state dir exists, early-exit
4343
if wizard_state_dir === nothing
@@ -89,7 +89,7 @@ function run_wizard(state::Union{Nothing,WizardState} = nothing)
8989
if state === nothing
9090
# If we weren't given a state, check to see if we'd like to resume a
9191
# previous run or start from scratch again.
92-
state = load_last_wizard_state()
92+
state = load_wizard_state()
9393
end
9494

9595
try
@@ -119,11 +119,11 @@ function run_wizard(state::Union{Nothing,WizardState} = nothing)
119119
end
120120

121121
# Save it every step along the way
122-
save_last_wizard_state(state)
122+
save_wizard_state(state)
123123
end
124124
catch err
125125
# If anything goes wrong, immediately save the current wizard state
126-
save_last_wizard_state(state)
126+
save_wizard_state(state)
127127
if isa(err, InterruptException)
128128
msg = "\n\nWizard stopped, use BinaryBuilder.run_wizard() to resume"
129129
if state.step in (:step3, :step3_retry, :step5a, :step5b, :step5c, :step6)

src/wizard/state.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ function unserialize(io)
9393
return x
9494
end
9595

96+
# Compare only serializeable fields when checking ==
97+
function Base.:(==)(x::WizardState, y::WizardState)
98+
for field in serializeable_fields(x)
99+
if getproperty(x, field) != getproperty(y, field)
100+
return false
101+
end
102+
end
103+
return true
104+
end
105+
96106
function show(io::IO, x::WizardState)
97107
print(io, "WizardState [$(x.step)]")
98108
end

test/wizard.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,18 @@ end
414414
end
415415
end
416416

417+
@testset "Wizard - state serialization" begin
418+
for state_generator in (Wizard.WizardState, step2_state, step3_state, step7_state)
419+
mktempdir() do dir
420+
state = state_generator()
421+
422+
Wizard.save_wizard_state(state, dir)
423+
@test Wizard.load_wizard_state(dir; as_is=true) == state
424+
end
425+
end
426+
end
427+
428+
417429
@testset "GitHub - authentication" begin
418430
withenv("GITHUB_TOKEN" => "") do
419431
@test Wizard.github_auth(allow_anonymous=true) isa GitHub.AnonymousAuth

0 commit comments

Comments
 (0)