Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upResubmission of templating PR (#1747) #3004
Conversation
rust-highfive
assigned
alexcrichton
Aug 17, 2016
This comment has been minimized.
This comment has been minimized.
rust-highfive
commented
Aug 17, 2016
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
Nice! I would really love to have this. Copying the same README.md, LICENSE, travis, gitignore, editorconfig, etc. files into every repo can't be the way it's supposed to go. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for re-submitting this. I never got the time to come back to it unfortunately, but I think its very useful and would love to see it finished off and merged. Thanks for taking it on @ehiggs! |
This comment has been minimized.
This comment has been minimized.
|
The biggest thing not addressed by this from the earlier PR was the use of Handlebars instead of Mustache. At the time the existing Handlebars implementations were a little unstable, but I imagine it's better now so should be easier to work in. |
This comment has been minimized.
This comment has been minimized.
|
@gchp agreed. So the work is as follows:
Future work: |
ehiggs
force-pushed the
ehiggs:master
branch
2 times, most recently
from
b713d4e
to
0407970
Aug 21, 2016
alexcrichton
reviewed
Aug 22, 2016
| "openssl-sys-extras 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)", | ||
| ] | ||
|
|
||
| [[package]] | ||
| name = "openssl-sys" | ||
| version = "0.7.14" | ||
| version = "0.7.17" |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Aug 22, 2016
Member
It looks like this may have run cargo update, but could this commit just add the dependencies it needs to?
This comment has been minimized.
This comment has been minimized.
|
Thanks for the revival @ehiggs! Excited to see progress on this |
alexcrichton
reviewed
Aug 22, 2016
| }; | ||
| let template_dir = templates_dir.join(repo_name); | ||
|
|
||
| match Repository::clone(template, &*template_dir) { |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Aug 22, 2016
Member
Cargo typically issues a status message for operations that may take a long time, so perhaps this could indicate that a repository is being cloned?
I think this may also wish to use the helpers in git/utils.rs to ensure this handles pieces such as authentication, retries, etc.
alexcrichton
reviewed
Aug 22, 2016
| template.starts_with("git@") => { | ||
| let path = PathBuf::from(template); | ||
|
|
||
| let repo_name = match path.components().last().unwrap() { |
This comment has been minimized.
This comment has been minimized.
alexcrichton
reviewed
Aug 22, 2016
| } | ||
|
|
||
| /// Create a new "bin" project | ||
| fn create_bin_template(path: &PathBuf) -> CargoResult<()> { |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Aug 22, 2016
Member
It seems like these should perhaps be "built in" rather than literally created on the filesystem?
alexcrichton
reviewed
Aug 22, 2016
| @@ -408,6 +411,65 @@ will not fail your overall build. Please see the [Travis CI Rust | |||
| documentation](https://docs.travis-ci.com/user/languages/rust/) for more | |||
| information. | |||
|
|
|||
| # Templates | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Aug 22, 2016
Member
This documentation doesn't seem to mention --template name along with ~/.cargo/templates, but maybe that won't be used that much in practice?
This comment has been minimized.
This comment has been minimized.
ehiggs
Sep 3, 2016
Author
Contributor
It says:
# use the mytemplate template which is located in .cargo/templates/mytemplate
$ cargo new myproj --template mytemplate
ehiggs
force-pushed the
ehiggs:master
branch
from
8050539
to
c39601d
Aug 30, 2016
This comment has been minimized.
This comment has been minimized.
|
I've done some work on this and rebased. I changed the way remote repos work by cloning them into a tempdir and using them as a template. The tempdir is then deleted when it goes out of scope. I do something similar with the default bin/lib templates. These are dumped to a tempdir and then used as a template. I tried to use In trying to get the I also made a skeleton repository to test this with. It used docopt and has a LICENSE file and everything to get started writing command line programs that use subcommands. It's basically @BurntSushi's xsv stripped down to... a skeleton |
This comment has been minimized.
This comment has been minimized.
|
I've added some commits that address docs and fix the tests. |
This comment has been minimized.
This comment has been minimized.
|
Travis failed due to a network issue. Appveyor failed on "override_cargo_home" but I don't have access to a Windows box to try and reproduce it. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the update @ehiggs! Some thoughts of mine:
Also cc @rust-lang/tools, would be good to start hearing thoughts about this as well! |
This comment has been minimized.
This comment has been minimized.
There seems to be some confusion here. @gchp's original work cloned the remote repository into So I guess the resulting work should be:
For the default template, I would keep |
This comment has been minimized.
This comment has been minimized.
|
I like the feature and from reading the docs this seems pretty reasonable. I've always envisioned project templates being part of the platform, so I would expect us to eventually distribute a bunch of them by default, and for IDEs to have options to instantiate them. This implementation doesn't provide for that yet since it only reads from As a step toward including templates in the Rust distribution by default I might expect and encourage somebody to maintain a project collecting templates - a single repo that contains nothing but templates. Thus people would naturally want to instantiate templates out of a subdirectory of a git repo, not from the top-level of the repo. This implementation seems to support one template per repo. |
This comment has been minimized.
This comment has been minimized.
In writing the example repository I thought that it might be a pain the backside to maintain several repositories for each skeleton. I think the options would be:
|
This comment has been minimized.
This comment has been minimized.
|
After discussion with @brson on irc, we think this will work: New lib: New local template:
New template based on git repo:
New template based on git repo where the repo is a collection of templates:
Probably new errors:
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@ehiggs oh thanks for the previous clarifications! The strategy you and @brson came up with sounds reasonable to me, but I wonder if we could perhaps forgo the If you want to rebase I can take another look as well. |
This comment has been minimized.
This comment has been minimized.
|
I rebased and removed use of the config. So now there is The following is supported: New default library: New default binary: New templated project based on remote repo: New templated project selecting a single template from a bunch in the repository: Local repo (untested Local directory: Error (template with no associated repo): |
ehiggs
closed this
Oct 7, 2016
ehiggs
force-pushed the
ehiggs:master
branch
from
34881dc
to
6534bdd
Oct 7, 2016
ehiggs
reopened this
Oct 7, 2016
TheNeikos
reviewed
Oct 10, 2016
|
|
||
| let template_dir = match (opts.template_repo, opts.template) { | ||
| // given template is a remote git repository & needs to be cloned | ||
| // This will be cloned to .cargo/templates/<repo_name> where <repo_name> |
This comment has been minimized.
This comment has been minimized.
TheNeikos
Oct 10, 2016
Contributor
This doesn't seem to be true anymore, I think that's a left over from previous iterations.
ehiggs
added some commits
Aug 16, 2016
ehiggs
force-pushed the
ehiggs:master
branch
from
501ff6c
to
265452d
Jan 31, 2017
This comment has been minimized.
This comment has been minimized.
|
Beta was branched let's merge! @bors: r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 1, 2017
This comment has been minimized.
This comment has been minimized.
|
Travis has had problems with the OS X queue. Hence the |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 1, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 265452d
into
rust-lang:master
Feb 2, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks so much again @ehiggs for your patience! |
This comment has been minimized.
This comment has been minimized.
|
Thank you for the patience. Now time to go bash out some templates. |
This comment has been minimized.
This comment has been minimized.
|
@ehiggs I think it's safe to say you far out-did my original work |
vi
referenced this pull request
Feb 17, 2017
Closed
`cargo init` no longer handles pre-existing source files nicely #3722
alexcrichton
referenced this pull request
Mar 3, 2017
Closed
List of default dependencies for all projects #3793
carols10cents
added a commit
to integer32llc/cargo
that referenced
this pull request
Mar 4, 2017
carols10cents
referenced this pull request
Mar 4, 2017
Merged
Restore the generated tests module created by `cargo new` #3799
bors
added a commit
that referenced
this pull request
Mar 6, 2017
alexcrichton
referenced this pull request
Mar 10, 2017
Closed
couldn't read src/main.rs in reustmann-0.1.2, Rust 1.17 #40185
This comment has been minimized.
This comment has been minimized.
|
A note that this pull-request has been reverted in #3878 in waiting for a RFC. |
This comment has been minimized.
This comment has been minimized.
|
Indeed, ongoing discussion is here. It seems there is no consensus yet. |
ehiggs commentedAug 17, 2016
This is a manual rebase of the older #1747 PR which was basically unrebasable due to the time it's been dormant.. This implements templating for Cargo and is basically the work of Greg Chapple (@gchp).
I'd love for this feature to move forward since it's really tedious to create all the directories (e.g.
src/bin) and copy paste docopt examples which I then edit. Then implement themainprogram to delegate to the subcommands insrc/bin, etc.