Browse Source

Fix warning about `#pragma once` in main file

We do some manual header insertion into the ROS2 bindings `.cc` file to fix some import errors. This commit skips copying of the `#pragma once` attribute at the beginning to avoid a C++ warning.
tags/v0.3.3-rc1
Philipp Oppermann 1 year ago
parent
commit
c92bad3faf
Failed to extract signature
1 changed files with 16 additions and 3 deletions
  1. +16
    -3
      apis/c++/node/build.rs

+ 16
- 3
apis/c++/node/build.rs View File

@@ -43,7 +43,10 @@ fn target_dir() -> PathBuf {
#[cfg(feature = "ros2-bridge")]
mod ros2 {
use super::target_dir;
use std::path::{Component, Path, PathBuf};
use std::{
io::{BufRead, BufReader},
path::{Component, Path, PathBuf},
};

pub fn generate() -> PathBuf {
use rust_format::Formatter;
@@ -118,7 +121,7 @@ mod ros2 {
std::fs::copy(&header_path, &target_path).unwrap();
println!("cargo:rerun-if-changed={}", header_path.display());

let mut node_header =
let node_header =
std::fs::File::open(target_path.with_file_name("dora-node-api.h")).unwrap();
let mut code_file = std::fs::File::open(&code_path).unwrap();
println!("cargo:rerun-if-changed={}", code_path.display());
@@ -126,7 +129,17 @@ mod ros2 {
std::fs::File::create(target_path.with_file_name("dora-ros2-bindings.cc")).unwrap();

// copy both the node header and the code file to prevent import errors
std::io::copy(&mut node_header, &mut code_target_file).unwrap();
let mut header_reader = {
let mut reader = BufReader::new(node_header);

// read first line to skip `#pragma once`, which is not allowed in main files
let mut first_line = String::new();
reader.read_line(&mut first_line).unwrap();
assert_eq!(first_line.trim(), "#pragma once");

reader
};
std::io::copy(&mut header_reader, &mut code_target_file).unwrap();
std::io::copy(&mut code_file, &mut code_target_file).unwrap();
code_target_file.flush().unwrap();
}


Loading…
Cancel
Save