Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Os { code: 2, kind: NotFound, message: "No such file or directory" } #14

Closed
ghost opened this issue Jan 28, 2018 · 4 comments
Closed

Os { code: 2, kind: NotFound, message: "No such file or directory" } #14

ghost opened this issue Jan 28, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Jan 28, 2018

What is the name of the missing file?

This also illustrates a deeper concern likely present in most idiomatic Rust programs:

  • the stacktrace won't let you easily find out the name of the missing file (all you see is built.rs:7 but no callers within that)
  • the error propagation idiomacy doesn't keep track of some sort of its own stacktrace(that I'm aware of, and I don't know much) to present to me when the "No such file or directory" error is shown.
     Running `/home/xftroxgpx/build/2nonpkgs/rust.stuff/rustlearnage/target/debug/build/built_example-8e075d35037f8c84/build-script-build`
error: failed to run custom build command for `built_example v0.1.0 (file:///home/xftroxgpx/build/2nonpkgs/rust.stuff/rustlearnage/built_example)`
process didn't exit successfully: `/home/xftroxgpx/build/2nonpkgs/rust.stuff/rustlearnage/target/debug/build/built_example-8e075d35037f8c84/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Failed to acquire build-time information: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:945:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
             at libstd/panicking.rs:537
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:521
   7: rust_begin_unwind
             at libstd/panicking.rs:497
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:71
   9: core::result::unwrap_failed
             at /home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/src/libcore/macros.rs:23
  10: <core::result::Result<T, E>>::expect
             at /home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/src/libcore/result.rs:809
  11: build_script_build::main
             at ./build.rs:7
  12: std::rt::lang_start::{{closure}}
             at /home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/src/libstd/rt.rs:74
  13: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:479
  14: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  15: std::rt::lang_start_internal
             at libstd/panicking.rs:458
             at libstd/panic.rs:358
             at libstd/rt.rs:58
  16: std::rt::lang_start
             at /home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/src/libstd/rt.rs:74
  17: main
  18: __libc_start_main
  19: _start

build.rs:7 is:

extern crate built;
fn main() {
//    let opts=built::Options::default() //temporary value does not live long enough
//        .set_dependencies(true);
    let mut opts=built::Options::default();                                                                                            
    opts.set_dependencies(true);
    built::write_built_file_with_opts2(&opts).expect("Failed to acquire build-time information");  //this be line 7
}

main.rs is:

// Use of a mod or pub mod is not actually necessary.
pub mod built_info {
   // The file has been placed there by the build script.
   include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

fn main() {                                                                                                                            
    println!("Hello, world! it's me {}", built_info::PKG_NAME);
    //let a=built_info.iterator();
    //src: https://github.com/lukaslueg/built
    println!("This is version {}{}, built for {} by {}.",
       built_info::PKG_VERSION,
       built_info::GIT_VERSION.map_or_else(|| "".to_owned(),
                                           |v| format!(" (git {})", v)),
       built_info::TARGET,
       built_info::RUSTC_VERSION);
    eprintln!("I was built with profile \"{}\", features \"{}\" on {} using {{}}",
       built_info::PROFILE,
       built_info::FEATURES_STR,
       built_info::BUILT_TIME_UTC
       //,built_info::DEPENDENCIES_STR //fail, not defined! https://github.com/lukaslueg/built/issues/10
       );

    println!("authors {}", built_info::PKG_AUTHORS);
}

write_built_file_with_opts2 is:

diff --git a/src/lib.rs b/src/lib.rs
index f9b8d545..59c58c40 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -808,9 +808,16 @@ pub fn write_built_file_with_opts<P: AsRef<path::Path>, Q: AsRef<path::Path>>(
 /// A shorthand for calling `write_built_file()` with `CARGO_MANIFEST_DIR` and
 /// `[OUT_DIR]/built.rs`.
 pub fn write_built_file() -> io::Result<()> {
+    write_built_file_with_opts2(&Options::default())?;
+    Ok(())
+}
+
+/// A shorthand for calling `write_built_file_with_opts()` with `CARGO_MANIFEST_DIR` ,
+/// `[OUT_DIR]/built.rs` and the provided `options`.
+pub fn write_built_file_with_opts2(options: &Options) -> io::Result<()> { //XXX: cannot use same name function, even tho they have different number of args - ie. function overloading!(and this isn't part of a struct)
     let src = env::var("CARGO_MANIFEST_DIR").unwrap();
     let dst = path::Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs");
-    write_built_file_with_opts(&Options::default(), &src, &dst)?;
+    write_built_file_with_opts(options, &src, &dst)?;
     Ok(())
 }
 

Ok now to save anyone some time, I'm guessing(!) that the name of the file is:
804158613665329152
but you see what I mean? it's not easy to figure it out really, from just the stacktrace and the generic "No such file or directory" error.
This is my biggest Rust show-stopper yet! And man, I am dissapoint! :)
(I can only hope that I'm missing something that I just can't see right now; like there's some way the error includes the stacktrace of all the places it was handed off to and that can be somehow shown; or the error can be made to show the filename)
EDIT: looks like what I want, to restore some faith in Rust, is https://docs.rs/error-chain/0.11.0/error_chain/
EDIT: failure seems to be a potentially better error-chain? https://github.com/withoutboats/failure Well, at least according to this

It is intended to replace error management based on std::error::Error with a new system based on lessons learned over the past several years, including those learned from experience with quick-error and error-chain.

@ghost
Copy link
Author

ghost commented Jan 29, 2018

Assuming the name of the missing file is Cargo.lock AND we're inside a cargo workspace, then the file can be found only in workspace root dir, ie.

$ time cargo metadata --format-version 1 | json_reformat | grep workspace_root
!! LD_LIBRARY_PATH=/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:
!! Executing '/home/xftroxgpx/build/2nonpkgs/rust.stuff/cargo/cargo//target/release//cargo' with args: 'metadata --format-version 1'
    "workspace_root": "/home/xftroxgpx/build/2nonpkgs/rust.stuff/rustlearnage"

real	0m0.432s
user	0m0.397s
sys	0m0.044s

instead of in CARGO_MANIFEST_DIR which for my particular case is:

$ time cargo metadata --format-version 1 | json_reformat | grep root|grep built_example
!! LD_LIBRARY_PATH=/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/xftroxgpx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:
!! Executing '/home/xftroxgpx/build/2nonpkgs/rust.stuff/cargo/cargo//target/release//cargo' with args: 'metadata --format-version 1'
        "root": "built_example 0.1.0 (path+file:///home/xftroxgpx/build/2nonpkgs/rust.stuff/rustlearnage/built_example)"

real	0m0.418s
user	0m0.381s
sys	0m0.049s

@lukaslueg
Copy link
Owner

I'm closing this for now, please re-open if this is still a problem

@chirag-bgh
Copy link

@lukaslueg I've the same issue

@correabuscar
Copy link

correabuscar commented Apr 9, 2024

For 0.7.2, the code is here:

fs::File::open(manifest_location.join("Cargo.lock"))?.read_to_string(&mut lock_buf)?;

the fix might be this:
#33 (comment)

To trigger the issue:

[build-dependencies]
built = { version="0.7.2", features = [ "dependency-tree" ] }

ie. it needs dependency-tree feature which is off by default.

output:

error: failed to run custom build command for `binprog v0.1.0 (/tmp/1/binprog)`

Caused by:
  process didn't exit successfully: `/tmp/1/target/debug/build/binprog-ea16158480722438/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at /tmp/1/binprog/build.rs:43:31:
  Failed to acquire build-time information: Os { code: 2, kind: NotFound, message: "No such file or directory" }
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

why? because this is a project in a workspace, so Cargo.lock is not in current dir but in parent dir.

With the fix, it would look like this:

error: failed to run custom build command for `binprog v0.1.0 (/tmp/1/binprog)`

Caused by:
  process didn't exit successfully: `/tmp/1/target/debug/build/binprog-55a0bbd182871c65/build-script-build` (exit status: 101)
  --- stderr
  Failed to open Cargo.lock. This information is only available for top-level packages. See the documentation for `built::Options::set_dependencies`.
  thread 'main' panicked at /tmp/1/binprog/build.rs:43:31:
  Failed to acquire build-time information: Os { code: 2, kind: NotFound, message: "No such file or directory" }
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Not sure when this other code is supposed to execute, but might need same fix:

fs::File::open(manifest_location.join("Cargo.lock"))?.read_to_string(&mut lock_buf)?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants