Skip to content

Commit dd550d1

Browse files
print current rust version on the about page
1 parent e287639 commit dd550d1

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

src/docbuilder/chroot_builder.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::process::Command;
1111
use std::path::PathBuf;
1212
use std::fs::remove_dir_all;
1313
use postgres::Connection;
14-
use rustc_serialize::json::Json;
14+
use rustc_serialize::json::{Json, ToJson};
1515
use error::Result;
1616

1717

@@ -314,7 +314,7 @@ impl DocBuilder {
314314

315315

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

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

442+
let (vers, _) = self.get_versions();
443+
444+
try!(conn.query("INSERT INTO config (name, value) VALUES ('rustc_version', $1)",
445+
&[&vers.to_json()])
446+
.or_else(|_| {
447+
conn.query("UPDATE config SET value = $1 WHERE name = 'rustc_version'",
448+
&[&vers.to_json()])
449+
}));
450+
442451
Ok(())
443452
}
444453
}

src/web/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ use semver::{Version, VersionReq};
6161
use rustc_serialize::json::{Json, ToJson};
6262
use std::collections::BTreeMap;
6363

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

430-
431427
/// MetaData used in header
432428
#[derive(Debug)]
433429
pub struct MetaData {

src/web/sitemap.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
2-
1+
use std::collections::BTreeMap;
32
use iron::prelude::*;
43
use iron::headers::ContentType;
4+
use rustc_serialize::json::Json;
55
use super::page::Page;
66
use super::pool::Pool;
77
use time;
8-
8+
use db::connect_db;
99

1010
pub fn sitemap_handler(req: &mut Request) -> IronResult<Response> {
1111
let conn = extension!(req, Pool);
@@ -31,3 +31,20 @@ pub fn robots_txt_handler(_: &mut Request) -> IronResult<Response> {
3131
resp.headers.set(ContentType("text/plain".parse().unwrap()));
3232
Ok(resp)
3333
}
34+
35+
pub fn about_handler(req: &mut Request) -> IronResult<Response> {
36+
let mut content = BTreeMap::new();
37+
38+
let conn = extension!(req, Pool);
39+
let res = ctry!(conn.query("SELECT value FROM config WHERE name = 'rustc_version'", &[]));
40+
41+
if let Some(row) = res.iter().next() {
42+
if let Some(Ok::<Json, _>(res)) = row.get_opt(0) {
43+
if let Some(vers) = res.as_string() {
44+
content.insert("rustc_version".to_string(), vers.to_string());
45+
}
46+
}
47+
}
48+
49+
Page::new(content).title("About Docs.rs").to_resp("about")
50+
}

templates/about.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
Docs.rs automatically builds crates' documentation released on
1111
<a href="https://crates.io/">crates.io</a>
1212
using the nightly release of the Rust compiler.
13+
{{#if content.rustc_version}}
14+
The current version of the Rust compiler in use is <code>{{content.rustc_version}}</code>.
15+
If you need a newer version of this compiler, check the
16+
<a href="https://github.com/rust-lang/docs.rs/issues">issues page</a>
17+
and file a new issue if you don't see an existing request.
18+
{{/if}}
1319
</p>
1420

1521
<p>

0 commit comments

Comments
 (0)