Skip to content

Commit

Permalink
Defer dtc parse errors in prevalidation
Browse files Browse the repository at this point in the history
In the case that we can't prevalidate the dts because of a parse error, defer
dtc's error output until after attempting to build. If the Zephyr build also
fails, its error output is much more legible. If it doesn't, then fail with the
dtc output.
  • Loading branch information
chrisandreae committed Feb 10, 2024
1 parent 116fd33 commit 51825d9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lambda/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def compile_board(board, keymap_data:, kconfig_data:, include_static_rhs: false)
compile_command = ['compileZmk', '-b', board]

if keymap_data
validate_devicetree!(keymap_data)
dts_parse_errors = validate_devicetree!(keymap_data)
File.open('build.keymap', 'w') { |io| io.write(keymap_data) }
compile_command << '-k' << './build.keymap'
end
Expand Down Expand Up @@ -67,6 +67,13 @@ def compile_board(board, keymap_data:, kconfig_data:, include_static_rhs: false)
raise CompileError.new('Compile failed to produce result binary', status: 500, log: compile_output)
end

if dts_parse_errors
# DTS validation failed to parse the DTS, yet the Zephyr build
# nonetheless succeeded. We can't allow returning the result, since we
# were unable to check it for unsafe dts sections.
raise CompileError.new('Syntax error validating device-tree input', log: dts_parse_errors)
end

result = File.read('zmk.uf2')

[result, compile_output]
Expand All @@ -84,7 +91,11 @@ def validate_devicetree!(dtsi)
Open3.capture3({}, 'dts2yml', unsetenv_others: true, stdin_data: dts)

unless status.success?
raise CompileError.new('Syntax error checking device-tree input', log: stderr.split("\n"))
# The error output from dtc is much harder to understand than Zephyr's
# errors, and the line numbers don't match up due to preprocessing. Rather
# than raising these now, return the error output in order that it's only
# used in the case that the Zephyr build doesn't itself error.
return stderr.split("\n")
end

data =
Expand All @@ -101,6 +112,8 @@ def validate_devicetree!(dtsi)
raise CompileError.new(
"Device-tree included the non-permitted root sections: #{invalid_sections.inspect}", log: [])
end

nil
end

# Lambda is single-process per container, and we get substantial speedups
Expand Down

0 comments on commit 51825d9

Please sign in to comment.