Skip to content

Commit

Permalink
Add support for manifest validation events in pack command
Browse files Browse the repository at this point in the history
  • Loading branch information
sylane committed Dec 5, 2024
1 parent 66c2192 commit 6590582
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rebar3_grisp_firmware.erl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ event([firmware, prepare, _, {error, not_a_file, Path}]) ->
event([firmware, build_firmware, create_image]) ->
console("* Creating disk image...");
event([firmware, build_firmware, create_image, {error, Reason}]) ->
abort_message("Failed to create firmware image file: ~s", Reason);
abort_message("Failed to create firmware image file", Reason);
event([firmware, build_firmware, copy_bootloader]) ->
console("* Writing bootloader...");
event([firmware, build_firmware, copy_bootloader, {error, Reason}]) ->
Expand Down
48 changes: 47 additions & 1 deletion src/rebar3_grisp_pack.erl
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,55 @@ event([pack, prepare, _, {error, not_a_file, Path}]) ->
abort("Not a regular file: ~s", [RelPath]);
event([pack, package, _, {expanding, Filename}]) ->
console("* Expanding compressed file ~s", [Filename]);
event([pack, package, create_image]) ->
console("* Creating temporary disk image...");
event([pack, package, create_image, {error, Reason}]) ->
abort_message("Failed to create temporary disk image: ~s", Reason);
event([pack, package, create_partitions]) ->
console("* Creating disk partition table...");
event([pack, package, create_partitions, {error, Reason}]) ->
abort_message("Failed to create partition table", Reason);
event([pack, package, copy_firmware]) ->
console("* Writing firmware...");
event([pack, package, copy_firmware, {error, Reason}]) ->
abort_message("Failed to write firmware", Reason);
event([pack, package, extract_manifest]) ->
console("* Extracting software manifest...");
event([pack, package, extract_manifest, {error, Reason}]) ->
abort_message("Failed to extract software manifest", Reason);
event([pack, package, extract_manifest, {manifest, undefined}]) ->
console(" Software manifest not found !");
event([pack, package, extract_manifest, {manifest, Manifest}]) ->
Id = proplists:get_value(id, Manifest),
console(" Using software manifest with identifier ~s", [Id]);
event([pack, package, close_image]) ->
console("* Cleaning up temporary disk image...");
event([pack, package, close_image, {error, Reason}]) ->
abort_message("Failed to cleanup temporary disk image", Reason);
event([pack, package, build_package]) ->
console("* Creating software update package...");
event([pack, package, _, {done, Path}]) ->
RelPath = grisp_tools_util:maybe_relative(Path, ?MAX_DDOT),
console(" Software update package generated: ~s", [RelPath]);
event([pack, package, _, {error, Reason}]) ->
abort_message("Failed to create package: ~s", Reason);
abort_message("Failed to create package", Reason);
event([pack, package, _, {exec, Args}]) ->
LogLine = iolist_to_binary(lists:join(" ", Args)),
debug("command: ~s", [LogLine]);
event([pack, package, _, {exit, {status, Status}}]) ->
debug("[exit ~w]", [Status]);
event([pack, package, _, {exit, {signal, Sig}}]) ->
debug("[signal ~w]", [Sig]);
event([pack, package, _, {Stream, eof}])
when Stream =:= stdin; Stream =:= stdout; Stream =:= stderr ->
debug("[~s closed]", [Stream]);
event([pack, package, _, {Stream, Data}])
when Stream =:= stdin; Stream =:= stdout; Stream =:= stderr ->
Str = unicode:characters_to_list(Data),
debug("~s ~s", [stream_tag(Stream), string:strip(Str, right, $\n)]);
event([pack, package, _, {Tag, _Term}])
when Tag =:= result; Tag =:= error ->
ok;
event(Event) ->
debug("[rebar3_grisp] ~p", [Event]),
case lists:last(Event) of
Expand All @@ -302,6 +344,10 @@ event(Event) ->
_ -> ok
end.

stream_tag(stdin) -> "<<";
stream_tag(stdout) -> "1>";
stream_tag(stderr) -> "2>".

abort_message(Prefix, Msg) when is_binary(Msg) ->
abort("~s; ~s", [Prefix, Msg]);
abort_message(Prefix, Reason) ->
Expand Down

0 comments on commit 6590582

Please sign in to comment.