Skip to content

Commit

Permalink
Give a better error if targets are not connected.
Browse files Browse the repository at this point in the history
The build system sets include directories and defines based on the board
associated with the firmware image.  This leads to confusing compile
errors if a compartment is not part of the image.  Instead, error at
build time.
  • Loading branch information
davidchisnall committed Dec 1, 2023
1 parent 9997e00 commit ef0ee9d
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions sdk/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ rule("cherimcu.component")
-- We don't want a lib prefix or equivalent.
target:set("prefixname", "")
end)
before_build(function (target)
if not target:get("cheriot.board_file") then
raise("target " .. target:name() .. " is being built but does not " ..
"appear to be connected to a firmware image. Please either use " ..
"add_deps(\"" .. target:name() .. "\" to add it or use set_default(false) " ..
"prevent it from being built when not linked")
end
end)

-- Custom link step, link this as a compartment, with the linker script
-- that will be provided in the specialisation of this rule.
Expand Down Expand Up @@ -291,19 +299,6 @@ rule("firmware")
local boarddir, boardfile = board_file(target);
local board = json.loadfile(boardfile)

-- Check that all dependences have a single board that they're targeting.
visit_all_dependencies(function (target)
local targetBoardFile = target:get("cheriot.board_file")
local targetBoardDir = target:get("cheriot.board_dir")
if not targetBoard then
target:set("cheriot.board_file", boardfile)
target:set("cheriot.board_dir", boarddir)
else
if targetBoardFile ~= boardfile or targetBoardDir ~= boarddir then
raise("target " .. target:name() .. " is used in two or more firmware targets with different boards")
end
end
end)

-- Add defines to all dependencies.
local add_defines = function (defines)
Expand All @@ -323,6 +318,20 @@ rule("firmware")
add_defines(temporal_defines)
end

-- Check that all dependences have a single board that they're targeting.
visit_all_dependencies(function (target)
local targetBoardFile = target:get("cheriot.board_file")
local targetBoardDir = target:get("cheriot.board_dir")
if not targetBoard then
target:set("cheriot.board_file", boardfile)
target:set("cheriot.board_dir", boarddir)
else
if targetBoardFile ~= boardfile or targetBoardDir ~= boarddir then
raise("target " .. target:name() .. " is used in two or more firmware targets with different boards")
end
end
end)

if board.driver_includes then
for _, include_path in ipairs(board.driver_includes) do
-- Allow ${sdk} to refer to the SDK directory, so that external
Expand Down

0 comments on commit ef0ee9d

Please sign in to comment.