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

Build fails in Cargo workspace #12

Closed
flxo opened this issue Sep 7, 2020 · 2 comments
Closed

Build fails in Cargo workspace #12

flxo opened this issue Sep 7, 2020 · 2 comments

Comments

@flxo
Copy link

flxo commented Sep 7, 2020

Hi,

when using cmd_lib in a crate that is part of a cargo workspace it get's confused because of a path relative CARGO_MANIFEST_DIR in source_text.rs.

 let __st_file: Vec<char> = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", file!()))

I check version 0.8.3 and latest HEAD.

For reproducing create a cargo workspace with a containing crate that uses cmd lib (I used one if the examples.

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:8:5
   |
8  | /     run_cmd!{
9  | |         cd $dir;
10 | |         pwd;
11 | |         sleep $gap;
12 | |         cd $f;
13 | |     }
   | |_____^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:17:5
   |
17 |     run_fun!(date +%Y)
   |     ^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:22:5
   |
22 |     run_cmd!(ls /tmp/nofile || true; echo "continue")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:23:5
   |
23 |     run_cmd!(cd /tmp; ls | wc -l;)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:24:5
   |
24 |     run_cmd!(pwd)?;
   |     ^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:27:5
   |
27 |     run_cmd!(echo $name)?;
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:28:5
   |
28 |     run_cmd!(|name| echo "hello, $name")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:29:5
   |
29 |     run_cmd!(du -ah . | sort -hr | head -n 5 | wc -w)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/felix/tmp/ws/cmd_lib_workspace/cmd_lib_workspace/src/main.rs: No such file or directory (os error 2)
  --> cmd_lib_workspace/src/main.rs:31:18
   |
31 |     let result = run_fun!(du -ah . | sort -hr | head -n 5)?;
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:8:5
   |
8  | /     run_cmd!{
9  | |         cd $dir;
10 | |         pwd;
11 | |         sleep $gap;
12 | |         cd $f;
13 | |     }
   | |_____^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:17:5
   |
17 |     run_fun!(date +%Y)
   |     ^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:22:5
   |
22 |     run_cmd!(ls /tmp/nofile || true; echo "continue")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:23:5
   |
23 |     run_cmd!(cd /tmp; ls | wc -l;)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:24:5
   |
24 |     run_cmd!(pwd)?;
   |     ^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:27:5
   |
27 |     run_cmd!(echo $name)?;
   |     ^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:28:5
   |
28 |     run_cmd!(|name| echo "hello, $name")?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:29:5
   |
29 |     run_cmd!(du -ah . | sort -hr | head -n 5 | wc -w)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `cmd_lib_core`
  --> cmd_lib_workspace/src/main.rs:31:18
   |
31 |     let result = run_fun!(du -ah . | sort -hr | head -n 5)?;
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `cmd_lib_core`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 18 previous errors

For more information about this error, try `rustc --explain E0433`.
error: could not compile `cmd_lib_workspace`.

To learn more, run the command again with --verbose.
@rust-shell-script
Copy link
Owner

Thanks for the reporting. Yeah, the declarative macros are fragile and I have modified the code to use proc_macros by default.

If you don't want to use nightly rust, you can use functions run_cmd() and run_fun() in cmd_lib_core instead.

rust-shell-script pushed a commit that referenced this issue Sep 7, 2020
Deprecated declarative macros and use proc_macros by default.
rust-shell-script pushed a commit that referenced this issue Sep 7, 2020
Deprecated declarative macros and use proc_macros by default.
@flxo
Copy link
Author

flxo commented Sep 7, 2020

@rust-shell-script Thanks for the fast response. I found run_cmd() and run_fun() - works fine!

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

2 participants