-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo init
no longer handles pre-existing source files nicely
#3722
Comments
cargo init
no longer works handles pre-existing source files nicelycargo init
no longer handles pre-existing source files nicely
cc @ehiggs, mind taking a look? |
My gut would say that we should preserve the original behavior, inserting |
Hi.
Is this based on the flag used on the command line or is there any possibility that the code is grepped for |
Yes, code was indeed grepped for The idea is/was that user can begin playing with Rust without cargo, just with The algorithm was approximately like this:
The scheme may be improved: if nothing of Do such improvements require RFC or one can pull request them directly? |
Based on my reading of the git log, there has never been a So, I guess the issue is that in
|
Yes. The tests were testing that the project is buildable after |
@ehiggs yeah the intention here was to just pick up what exists (if possible) and otherwise fill in gaps that are missing. Do you think it'd be a small change to reinstate the existing behavior? |
There should be additional tests to prevent similar breakage in future, so the change is not going to be trivial. |
I agree with @vi. |
@ehiggs , Are you planning on resolving the issue yourself or I should [someday] prepare my own pull request? Further advancements for |
I'm sorry I was unresponsive this week. I've been very busy. I can take a look. First, the test. What test is needed here? At least four to prevent further regressions:
|
@ehiggs , Yes. "3." -> And also make sure a dummy unused "4." -> And also make sure a dummy unused The same for source code without |
Checked c7d904a61dab69eef11d708f701d249a4d14d0e2. @ehiggs , Outstanding issues:
Otherwise looks OK. Fortunately Future ideas about
|
This seems like correct behaviour. The user explicitly specified a bin project but hasn't written a main function. That seems like a bad idea to override.
Ok, we can fix this. In line with the above, I think the detection step should only take place if there was no explicit |
It may be reasonable to avoid adding any |
Fix for #3722 When using init, add [[bin]] and [lib] section where appropriate.
I took a look at fixing this final issue with the output. I thought the best way to fix it would be to return the Workspace from // In impl Workspace:
pub fn has_binary_targets(&self) -> bool {
self.packages.packages.values()
.any(|ref mp| {
match *mp {
&MaybePackage::Package(ref p) => {
p.targets().iter().any(|t| { *t.kind() == TargetKind::Bin })
},
_ => false,
}
})
} But this doesn't work because Cargo is somehow a target for every project. If I put in a print statement in the above check for
Is that correct? Should Cargo be a binary target for every workspace? To reproduce, I have a patch here: https://gist.github.com/ehiggs/bd120ef8c9fe5cee89dea9c4223758d9
|
Returning the workspace seems fine yeah, but I wonder if that's just a bug in cargo's tests? (i.e. how cargo runs its own tests in a subdir of itself) |
Templates have been removed pending an RFC. There is a pre-RFC thread here. I think this can be closed for now. |
Thanks @ehiggs! |
#3004 broken it a bit.
Previously Cargo looked for files like
main.rs
,src/main.rs
,lib.rs
,src/lib.rs
,projectname.rs
andsrc/projectname.rs
and created[[bin]]
and/or[lib]
sections inCargo.toml
automatically if source files located unusually.Now it does look for those files, but fails to use this information meaningfully and just creates
src/main.rs
orsrc/lib.rs
instead of using sections in Cargo.toml even if a usable source file outsidesrc
already exists, making the "hello world" lib or app while previously it used pre-existing source code.What shall be done? Options:
--lib
/--bin
. Don't look at any files except ofsrc/{main,lib}.rs
[[bin]]
and[lib]
again (when--template
is not in use)cargo init
, e.gmyapp/myapp.rs
becomesmyapp/src/main.rs
.The text was updated successfully, but these errors were encountered: