Skip to content

Commit 61d58a8

Browse files
committed
Calculate build hash when collecting files
1 parent 2ed45cb commit 61d58a8

4 files changed

+18
-31
lines changed

src/grisp_tools_build.erl

+9-18
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,9 @@ install(S0) ->
191191

192192
run_hooks(S2, post_install, [{cd, InstallPath}]).
193193

194-
post(#{build := #{overlay := Overlay}} = S0) ->
195-
% info("Computing file hashes"),
196-
{Hash, HashIndex} = grisp_tools_util:overlay_hash(Overlay),
197-
198-
199-
% info("Writing hashes to file. Hash: ~p", [Hash]),
194+
post(#{build := #{hash := #{index := Index}}} = S0) ->
200195
PackageListing = filename:join(mapz:deep_get([paths, install], S0), "GRISP_PACKAGE_FILES"),
201-
ok = file:write_file(PackageListing, HashIndex),
196+
ok = file:write_file(PackageListing, Index),
202197

203198
% info("Copying revision string into install dir"),
204199
ToolchainRoot = mapz:deep_get([paths, toolchain], S0),
@@ -209,19 +204,15 @@ post(#{build := #{overlay := Overlay}} = S0) ->
209204
{ok, _} -> ok;
210205
_ -> error({missing_toolchain_revision, RevSource})
211206
end,
212-
mapz:deep_put([build, hash], Hash, S0).
207+
S0.
213208

214209
tar(#{build := #{flags := #{tar := true}}} = S0) ->
215-
#{
216-
build := #{hash := Hash},
217-
otp_version := Version,
218-
paths := #{package := PackagePath, install := InstallPath}
219-
} = S0,
220-
CacheFile = grisp_tools_util:package_name(#{otp_version => Version, hash => Hash}),
221-
Filename = filename:join(PackagePath, CacheFile),
222-
grisp_tools_util:ensure_dir(Filename),
223-
shell_ok(S0, ["tar -zcf ", Filename, " ."], [{cd, InstallPath}]),
224-
event(S0, [{file, relative(Filename)}]);
210+
#{paths := #{package := PackagePath, install := InstallPath}} = S0,
211+
Name = grisp_tools_util:package_name(S0),
212+
Package = filename:join(PackagePath, Name),
213+
grisp_tools_util:ensure_dir(Package),
214+
shell_ok(S0, ["tar -zcf ", Package, " ."], [{cd, InstallPath}]),
215+
event(S0, [{file, relative(Package)}]);
225216
tar(S0) ->
226217
event(S0, ['_skip']).
227218

src/grisp_tools_deploy.erl

+3-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ run(State) ->
2020
fun grisp_tools_step:version/1
2121
]},
2222
fun grisp_tools_step:collect/1,
23-
fun calculate_hash/1,
2423
fun package/1,
2524
fun release/1,
2625
fun copy/1
@@ -29,14 +28,9 @@ run(State) ->
2928

3029
%--- Tasks ---------------------------------------------------------------------
3130

32-
calculate_hash(#{build := #{overlay := Overlay}} = S0) ->
33-
% FIXME: Move to function in _steps module and use in build task
34-
{Hash, _HashIndex} = grisp_tools_util:overlay_hash(Overlay),
35-
S0#{hash => Hash}.
36-
37-
package(#{custom_build := true, hash := Hash} = State0) ->
31+
package(#{custom_build := true, build := #{hash := #{value := Hash}}} = State0) ->
3832
event(State0, [{type, {custom_build, Hash}}]);
39-
package(#{hash := Hash} = State0) ->
33+
package(#{build := #{hash := #{value := Hash}}} = State0) ->
4034
State1 = event(State0, [{type, {package, Hash}}]),
4135
grisp_tools_util:weave(State1, [
4236
fun meta/1,
@@ -200,7 +194,7 @@ download_loop({ReqID, RequestPid}, Handle, State0, Bytes) ->
200194
State1 = event(State0, ['_skip']),
201195
mapz:deep_merge([State1, #{package => #{state => not_modified}}]);
202196
{http, {ReqID, {{_HTTPVer, 404, "Not Found"}, _Headers, _Body}}} ->
203-
#{otp_version := OTPVersion, hash := Hash} = State0,
197+
#{otp_version := OTPVersion, build := #{hash := #{value := Hash}}} = State0,
204198
error({package, {not_found, OTPVersion, Hash}});
205199
{http, Other} ->
206200
State1 = event(State0, [{error, Other}]),

src/grisp_tools_step.erl

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ apps(#{apps := Apps} = State0) ->
8989

9090
collect(#{platform := Platform} = State0) ->
9191
Platforms = [default, Platform],
92-
lists:foldl(fun collect_platform_files/2, State0, Platforms).
92+
State1 = lists:foldl(fun collect_platform_files/2, State0, Platforms),
93+
{Hash, HashIndex} = grisp_tools_util:build_hash(State1),
94+
mapz:deep_put([build, hash], #{value => Hash, index => HashIndex}, State1).
9395

9496
%--- Internal ------------------------------------------------------------------
9597

src/grisp_tools_util.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
-export([rm/1]).
2020
-export([build_overlay/4]).
2121
-export([deploy_overlay/4]).
22-
-export([overlay_hash/1]).
22+
-export([build_hash/1]).
2323
-export([merge_build_config/2]).
2424
-export([source_hash/2]).
2525
-export([with_file/3]).
@@ -98,7 +98,7 @@ paths(Root, Platform, Version) ->
9898
otp_dir(Root, Platform, {_Components, _Pre, _Build, Ver}) ->
9999
filename:join([Root, "_grisp", Platform, "otp", Ver]).
100100

101-
package_name(#{otp_version := {_, _, _, OTPVersion}, hash := Hash}) ->
101+
package_name(#{otp_version := {_, _, _, OTPVersion}, build := #{hash := #{value := Hash}}}) ->
102102
iolist_to_binary(["grisp_otp_build_", OTPVersion, "_", Hash, ".tar.gz"]).
103103

104104
package_cache_temp(State) ->
@@ -178,7 +178,7 @@ collect_overlay(Dir, Platform, Versions, Init, CollectFun) ->
178178
merge_build_config(C1, C2) ->
179179
mapz:deep_merge(C1, C2).
180180

181-
overlay_hash(#{hooks := Hooks} = Overlay) ->
181+
build_hash(#{build := #{overlay := #{hooks := Hooks} = Overlay}}) ->
182182
AllHooks = maps:from_list([{N, I} || {_T, F} <- maps:to_list(Hooks), {N, I} <- maps:to_list(F)]),
183183
HashIndex = lists:sort(maps:fold(fun
184184
(_Type, Files, Acc) ->

0 commit comments

Comments
 (0)