Skip to content

Commit

Permalink
fix: run build issue (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy HERGAULT <jeremy.hergault@worldline.com>
  • Loading branch information
reneca committed Jun 28, 2024
1 parent 6b9ab4a commit 7541000
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
schedule: [cron: "40 1 * * *"]

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include = [
]

[workspace.dependencies]
prosa-utils = { version = "0.1.0", path = "prosa_utils" }
prosa-utils = { version = "0.1.1", path = "prosa_utils" }
prosa-macros = { version = "0.1.0", path = "prosa_macros" }
thiserror = "1"
aquamarine = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion cargo-prosa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-prosa"
version = "0.1.0"
version = "0.1.1"
authors.workspace = true
description = "ProSA utility to package and deliver a builded ProSA"
homepage.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions cargo-prosa/assets/build.rs.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use cargo_prosa::CONFIGURATION_FILENAME;

fn write_settings_rs(out_dir: &OsString, desc: &Desc, metadata: &HashMap<String, Metadata>) -> io::Result<()> {{ '{' }}
let mut f = fs::File::create(Path::new(&out_dir).join("settings.rs"))?;
writeln!(f, "use prosa::core::settings::prosa_settings;")?;
writeln!(f, "use prosa::core::settings::settings;")?;

if let Some(processors) = &desc.proc {{ '{' }}
writeln!(f, "\n/// ProSA Run settings")?;
writeln!(f, "#[prosa_settings]")?;
writeln!(f, "#[settings]")?;
writeln!(f, "#[derive(Default, Debug, Deserialize, Serialize)]")?;
writeln!(f, "pub struct RunSettings {{ '{{' }}")?;
for processor in processors {{ '{' }}
Expand Down
20 changes: 12 additions & 8 deletions cargo-prosa/assets/main.rs.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ include!(concat!(env!("OUT_DIR"), "/config.rs"));
// Include run
include!(concat!(env!("OUT_DIR"), "/run.rs"));

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {{ '{' }}
fn main() -> Result<(), Box<dyn std::error::Error>> {{ '{' }}
let matches = cli().get_matches();

// Deamonize the program if needed
if matches.get_flag("daemon") {{ '{' }}
daemonize(&matches);
{{ '}' }}

prosa_main(matches)
{{ '}' }}

#[tokio::main]
async fn prosa_main(matches: clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {{ '{' }}
// Look if we have to launch the ProSA or just dry run
if matches.get_flag("dry_run") {{ '{' }}
if let Some(config_path) = matches.get_one::<String>("config") {{ '{' }}
Expand All @@ -36,26 +45,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {{ '{' }}
{{ '}' }}
{{ '}' }}
{{ '}' }} else {{ '{' }}
info!("Starting ProSA {} - {}", env!("CARGO_PKG_NAME"), PROSA_VERSIONS);
let mut prosa_settings = prosa_config(&matches)?.try_deserialize::<RunSettings>()?;

// Provide ProSA name if set in command line
if let Some(name) = matches.get_one::<String>("name") {{ '{' }}
prosa_settings.set_prosa_name(name.clone());
{{ '}' }}

// Deamonize the program if needed
if matches.get_flag("daemon") {{ '{' }}
daemonize(&matches);
{{ '}' }}

// Init observability
let filter = TelemetryFilter::default();
prosa_settings
.get_observability()
.tracing_init(&filter)?;

// Create bus and main processor
info!("Starting ProSA {} - {}", env!("CARGO_PKG_NAME"), PROSA_VERSIONS);
let (bus, main) = new_main(&prosa_settings);

// Launch the main task
Expand Down
10 changes: 8 additions & 2 deletions cargo-prosa/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ where
{
const RENDER_FILENAME: &str = "build.rs";
let mut tera_build = Tera::default();
tera_build.add_raw_template(RENDER_FILENAME, include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/build.rs.j2")))?;
tera_build.add_raw_template(
RENDER_FILENAME,
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/build.rs.j2")),
)?;

let build_file = fs::File::create(&path).map_err(tera::Error::io_error)?;
tera_build.render_to(RENDER_FILENAME, ctx, build_file)
Expand All @@ -72,7 +75,10 @@ where
{
const RENDER_FILENAME: &str = "main.rs";
let mut tera_build = Tera::default();
tera_build.add_raw_template(RENDER_FILENAME, include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/main.rs.j2")))?;
tera_build.add_raw_template(
RENDER_FILENAME,
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/main.rs.j2")),
)?;

let main_file = fs::File::create(&path).map_err(tera::Error::io_error)?;
tera_build.render_to(RENDER_FILENAME, ctx, main_file)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion prosa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prosa"
version = "0.1.0"
version = "0.1.1"
authors.workspace = true
description = "ProSA core"
homepage.workspace = true
Expand Down
9 changes: 4 additions & 5 deletions prosa/src/core/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
//! use std::error::Error;
//! use serde::Serialize;
//! use prosa_utils::msg::tvf::Tvf;
//! use prosa::core::proc::{proc, Proc, ProcBusParam};
//! use prosa::core::proc::{proc_settings, proc, Proc, ProcBusParam};
//! use prosa::core::adaptor::Adaptor;
//! use prosa::core::settings::settings;
//! use prosa::core::msg::{Msg, InternalMsg};
//!
//! pub trait MyAdaptorTrait<M>
Expand Down Expand Up @@ -58,14 +57,14 @@
//! }
//! }
//!
//! #[settings]
//! #[proc_settings]
//! #[derive(Default, Debug, Serialize)]
//! pub struct MySettings {
//! pub struct MyProcSettings {
//! param: String,
//! // ...
//! }
//!
//! #[proc(settings = MySettings)]
//! #[proc(settings = MyProcSettings)]
//! pub struct MyProc { /* Nothing in here */ }
//!
//! #[proc]
Expand Down
2 changes: 1 addition & 1 deletion prosa_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prosa-utils"
version = "0.1.0"
version = "0.1.1"
authors.workspace = true
description = "ProSA utils"
homepage.workspace = true
Expand Down
10 changes: 2 additions & 8 deletions prosa_utils/src/config/observability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,7 @@ impl Observability {
/// Meter provider builder
pub fn build_meter_provider(&self) -> MeterProvider {
if let Some(settings) = &self.metrics {
match settings.build_provider() {
Ok(m) => m,
Err(_) => MeterProvider::default(),
}
settings.build_provider().unwrap_or_default()
} else {
MeterProvider::default()
}
Expand Down Expand Up @@ -272,10 +269,7 @@ impl Observability {
/// ```
pub fn build_tracer_provider(&self) -> TracerProvider {
if let Some(settings) = &self.traces {
match settings.build_tracer_provider() {
Ok(m) => m,
Err(_) => TracerProvider::default(),
}
settings.build_tracer_provider().unwrap_or_default()
} else {
TracerProvider::default()
}
Expand Down

0 comments on commit 7541000

Please sign in to comment.