mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
C++: add #pragma once
to generated file
This commit is contained in:
parent
475ced0a62
commit
5a4713aa17
3 changed files with 10 additions and 0 deletions
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "logic.h"
|
||||
#include "appwindow.h"
|
||||
// Test that it's ok to include twice
|
||||
#include "appwindow.h"
|
||||
|
||||
void setup_logic(const Logic &logic)
|
||||
{
|
||||
|
|
|
@ -89,6 +89,8 @@ mod cpp_ast {
|
|||
|
||||
impl Display for File {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||
writeln!(f, "// This file is auto-generated")?;
|
||||
writeln!(f, "#pragma once")?;
|
||||
for i in &self.includes {
|
||||
writeln!(f, "#include {}", i)?;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>>
|
|||
return Err(vec.join("\n").into());
|
||||
}
|
||||
|
||||
// Remove the `#pragma once` as this is not going to be included and would produce a warning
|
||||
// when compiling the generated code.
|
||||
let hash_pos = generated_cpp.iter().position(|&b| b == b'#').unwrap();
|
||||
assert_eq!(&generated_cpp[hash_pos..hash_pos + 12], b"#pragma once");
|
||||
generated_cpp.drain(hash_pos..hash_pos + 12);
|
||||
|
||||
generated_cpp.write_all(
|
||||
br"
|
||||
#ifdef NDEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue