Skip to content

print current rust version on the about page #272

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

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/docbuilder/chroot_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::process::Command;
use std::path::PathBuf;
use std::fs::remove_dir_all;
use postgres::Connection;
use rustc_serialize::json::Json;
use rustc_serialize::json::{Json, ToJson};
use error::Result;


Expand Down Expand Up @@ -314,7 +314,7 @@ impl DocBuilder {


/// Gets rustc and cratesfyi version from chroot environment
fn get_versions(&self) -> (String, String) {
pub fn get_versions(&self) -> (String, String) {
// It is safe to use expect here
// chroot environment must always have rustc and cratesfyi installed
(String::from(self.chroot_command("rustc --version")
Expand Down Expand Up @@ -439,6 +439,15 @@ impl DocBuilder {

try!(self.clean(&pkg));

let (vers, _) = self.get_versions();

try!(conn.query("INSERT INTO config (name, value) VALUES ('rustc_version', $1)",
&[&vers.to_json()])
.or_else(|_| {
conn.query("UPDATE config SET value = $1 WHERE name = 'rustc_version'",
&[&vers.to_json()])
}));

Ok(())
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use semver::{Version, VersionReq};
use rustc_serialize::json::{Json, ToJson};
use std::collections::BTreeMap;


/// Duration of static files for staticfile and DatabaseFileHandler (in seconds)
const STATIC_FILE_CACHE_DURATION: u64 = 60 * 60 * 24 * 30 * 12; // 12 months
const STYLE_CSS: &'static str = include_str!(concat!(env!("OUT_DIR"), "/style.css"));
Expand Down Expand Up @@ -97,9 +96,7 @@ impl CratesfyiHandler {
let mut router = Router::new();
router.get("/", releases::home_page, "index");
router.get("/style.css", style_css_handler, "style_css");
router.get("/about",
|_: &mut Request| page::Page::new(false).title("About Docs.rs").to_resp("about"),
"about");
router.get("/about", sitemap::about_handler, "about");
router.get("/robots.txt", sitemap::robots_txt_handler, "robots_txt");
router.get("/sitemap.xml", sitemap::sitemap_handler, "sitemap_xml");
router.get("/opensearch.xml", opensearch_xml_handler, "opensearch_xml");
Expand Down Expand Up @@ -427,7 +424,6 @@ fn opensearch_xml_handler(_: &mut Request) -> IronResult<Response> {
Ok(response)
}


/// MetaData used in header
#[derive(Debug)]
pub struct MetaData {
Expand Down
23 changes: 20 additions & 3 deletions src/web/sitemap.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


use std::collections::BTreeMap;
use iron::prelude::*;
use iron::headers::ContentType;
use rustc_serialize::json::Json;
use super::page::Page;
use super::pool::Pool;
use time;

use db::connect_db;

pub fn sitemap_handler(req: &mut Request) -> IronResult<Response> {
let conn = extension!(req, Pool);
Expand All @@ -31,3 +31,20 @@ pub fn robots_txt_handler(_: &mut Request) -> IronResult<Response> {
resp.headers.set(ContentType("text/plain".parse().unwrap()));
Ok(resp)
}

pub fn about_handler(req: &mut Request) -> IronResult<Response> {
let mut content = BTreeMap::new();

let conn = extension!(req, Pool);
let res = ctry!(conn.query("SELECT value FROM config WHERE name = 'rustc_version'", &[]));

if let Some(row) = res.iter().next() {
if let Some(Ok::<Json, _>(res)) = row.get_opt(0) {
if let Some(vers) = res.as_string() {
content.insert("rustc_version".to_string(), vers.to_string());
}
}
}

Page::new(content).title("About Docs.rs").to_resp("about")
}
6 changes: 6 additions & 0 deletions templates/about.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
Docs.rs automatically builds crates' documentation released on
<a href="https://crates.io/">crates.io</a>
using the nightly release of the Rust compiler.
{{#if content.rustc_version}}
The current version of the Rust compiler in use is <code>{{content.rustc_version}}</code>.
If you need a newer version of this compiler, check the
<a href="https://github.com/rust-lang/docs.rs/issues">issues page</a>
and file a new issue if you don't see an existing request.
{{/if}}
</p>

<p>
Expand Down