diff --git a/lambda/compiler.rb b/lambda/compiler.rb index 9e9b8848552b..58ab0eaef8d2 100644 --- a/lambda/compiler.rb +++ b/lambda/compiler.rb @@ -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 @@ -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] @@ -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 = @@ -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