Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/forge/hb_packager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
-export([scan/2, scan/1]).
-export([package/2, package_all/2, group_device_name/1]).
-export([spec_message/2, impl_message/3]).
-export([require_spec_bodies/1]).
-export([format_error/1]).

-include("include/hb.hrl").
Expand Down Expand Up @@ -333,6 +334,17 @@ package(#{ root := Root, root_file := RootFile, helpers := Helpers,
Pkg
end.

%% @doc Require packaged devices to have a non-empty specification body before
%% publishing through paths that upload the spec as signed item data.
require_spec_bodies(Pkgs) ->
lists:foreach(fun require_spec_body/1, Pkgs),
Pkgs.

require_spec_body(#{ device_name := Name, spec_body := <<>> }) ->
erlang:error({empty_device_specification, Name});
require_spec_body(_Pkg) ->
ok.

%% @doc The device name (`name@version') a scanned group implements,
%% without packaging it. Build tooling uses this to correlate a source
%% group with its package.
Expand Down Expand Up @@ -618,6 +630,11 @@ format_error({device_compile_failed, Device, Path, Errors, Warnings}) ->
compile_messages("", Errors),
compile_messages("Warning: ", Warnings)
];
format_error({empty_device_specification, Name}) ->
io_lib:format(
"Device specification body is empty for ~ts. Add a leading %%% @doc block or -specification(\"path\") before publishing.",
[hb_util:list(Name)]
);
format_error(Reason) ->
io_lib:format("~p", [Reason]).

Expand Down
2 changes: 2 additions & 0 deletions src/forge/plugin/src/hb_forge_args.erl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ run_provider(State, Module, Fun) when is_function(Fun, 1) ->
try Fun(State)
catch
error:{device_compile_failed, _, _, _, _} = Reason ->
{error, hb_packager:format_error(Reason)};
error:{empty_device_specification, _} = Reason ->
{error, hb_packager:format_error(Reason)}
end
end.
Expand Down
8 changes: 5 additions & 3 deletions src/forge/plugin/src/hb_forge_publish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ publish(State) ->
[Action, maps:get(device_name, Pkg), SpecID, ImplID, Signer]
)
end,
hb_packager:package_all(
hb_forge_args:scan_devices(Args),
NodeOpts
hb_packager:require_spec_bodies(
hb_packager:package_all(
hb_forge_args:scan_devices(Args),
NodeOpts
)
)
),
{ok, State}.
Expand Down