gccrs
gccrs copied to clipboard
Infer crate name after file opening
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::handle_crate_name): Remove
crate name inference
(Session::compile_crate): Add crate name inference and error if
inferred name is empty. Remove CompileOptions::get_instance ()
that returned a local copy of the options. Rename
crate_name_changed to crate_name_found to match semantics.
(rust_crate_name_validation_test): Test inferring ".rs" name
* rust-session-manager.h: Modify handle_crate_name definition to
include filename.
Fixes #3129. Also fixes an issue where filenames such as ".rs" provided cause an ICE.
Note that I didn't make a test because I wasn't sure how to use DejaGnu to test that a directory was provided instead of a file (because if I created a test file, then it wouldn't be a directory!). I could've made a ".rs" test file to test the empty crate name behavior, but then the test would be hidden...
I did manually run the following tests:
workspace@ee59f2d37013:~/gccrs/build$ ./gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use .rs
crab1: error: crate name from filename .rs is empty
workspace@ee59f2d37013:~/gccrs/build$ ./gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use gcc/
crab1: error: cannot open filename gcc/: Is a directory
workspace@ee59f2d37013:~/gccrs/build$ ./gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use ~/
crab1: error: cannot open filename /home/workspace/: Is a directory
workspace@ee59f2d37013:~/gccrs/build$ ./gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use .rs.txt
crab1: error: invalid character ‘.’ in crate name: ‘.rs’
.rs.txt:1: note: crate name inferred from this file
workspace@ee59f2d37013:~/gccrs/build$ ./gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use missing.rs
crab1: error: cannot open filename missing.rs: No such file or directory
Finally, I am waiting for confirmation from my employer that I own the copyright to these changes. This may take a while. I will add a DCO once I get that confirmation.