fltk-rs / fl2rust

A fluid (fltk ui designer) file to Rust transpiler
MIT License
52 stars 3 forks source link

Something related to current_dir broke between versions 0.5.19 and 0.5.20 #31

Open diegoefe opened 1 week ago

diegoefe commented 1 week ago

Using this build.rs:

use std::{error::Error, path::PathBuf};
use fl2rust::Generator;

fn generate_file(g:&Generator, out_path:&PathBuf, name:&str) {
  println!("cargo:rerun-if-changed=src/{name}.fl");
  let op = format!("{}", out_path.join(&format!("{name}.rs")).to_str().unwrap());
  // println!("cargo:warning=op [{op}]");
  g.in_out(&format!("src/{name}.fl"), &op).expect(&format!("Failed to generate {name}.rs!"))
}

fn main() -> Result<(), Box<dyn Error>> {
    use std::env;
    // println!("cargo:rerun-if-changed=src/main_ui.fl");
    let g = fl2rust::Generator::default();
    let out_dir = env::var("OUT_DIR").unwrap();
    //  println!("cargo:warning=out_dir [{out_dir}]");
    let out_path = PathBuf::from(out_dir.clone());

        println!("cargo:warning=current_dir [{:?}]", std::env::current_dir().unwrap().to_str());
    generate_file(&g, &out_path, "ui_main");

        println!("cargo:warning=current_dir [{:?}]", std::env::current_dir().unwrap().to_str());
        /// When a second .fl file is added to the project it fails (with version 0.5.20 and not with 0.5.19)
    generate_file(&g, &out_path, "ui_part");

  Ok(())
}

This is the ouput:

error: failed to run custom build command for `*****`

Caused by:
  process didn't exit successfully: `*****/target/debug/build/indicame-9e85cb3bbb282b5e/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=*****/.git/HEAD
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-changed=src/ui_main.fl
  cargo:rerun-if-changed=src/ui_part.fl

  --- stderr
  thread 'main' panicked at build.rs:12:44:
  Failed to generate ui_part.rs!: Os { code: 2, kind: NotFound, message: "No such file or directory" }
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Modifying generate_file() to receive the full path of the source .fl

fn generate_file(g:&Generator, in_path:&PathBuf, out_path:&PathBuf, name:&str) {
  let infile = format!("{}", in_path.join(&format!("src/{name}.rs")).to_str().unwrap());
  println!("cargo:rerun-if-changed={infile}");
  let op = format!("{}", out_path.join(&format!("{name}.rs")).to_str().unwrap());
  println!("cargo:warning=op [{op}]");
  g.in_out(infile, op).expect(&format!("Failed to generate {name}.rs!"))
}

still fails and the second file (ui_part.rs) its almost empty (has some, i guess, boilerplate includes but not the generated one Obviously, downgrading to 0.5.19 solved the problem. Hope this helps

MoAlyousef commented 1 week ago

Thank you for the report. This should be fixed in 0.5.21. It required resetting the current dir after codegen.

diegoefe commented 1 week ago

Excellent

On Sat, Sep 21, 2024 at 6:44 PM Mohammed Alyousef @.***> wrote:

Thank you for the report. This should be fixed in 0.5.21. It required resetting the current dir after codegen.

— Reply to this email directly, view it on GitHub https://github.com/fltk-rs/fl2rust/issues/31#issuecomment-2365330918, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALBP4HLD5VGYBWDW2KSSVTZXXSEZAVCNFSM6AAAAABOQJEVFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRVGMZTAOJRHA . You are receiving this because you authored the thread.Message ID: @.***>