Skip to content

Commit 2207434

Browse files
committed
remove --target by default
this required a bit of a rearchitecture
1 parent 2c76ae0 commit 2207434

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

src/db/add_package.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
use Metadata;
32
use utils::MetadataPackage;
43
use docbuilder::BuildResult;
54
use regex::Regex;
@@ -38,7 +37,6 @@ pub(crate) fn add_package_into_database(conn: &Connection,
3837
let readme = get_readme(metadata_pkg, source_dir).unwrap_or(None);
3938
let (release_time, yanked, downloads) = get_release_time_yanked_downloads(metadata_pkg)?;
4039
let is_library = metadata_pkg.is_library();
41-
let metadata = Metadata::from_source_dir(source_dir)?;
4240

4341
let release_id: i32 = {
4442
let rows = conn.query("SELECT id FROM releases WHERE crate_id = $1 AND version = $2",
@@ -83,7 +81,7 @@ pub(crate) fn add_package_into_database(conn: &Connection,
8381
&is_library,
8482
&res.rustc_version,
8583
&metadata_pkg.documentation,
86-
&metadata.default_target])?;
84+
&res.target])?;
8785
// return id
8886
rows.get(0).get(0)
8987

@@ -137,7 +135,7 @@ pub(crate) fn add_package_into_database(conn: &Connection,
137135
&is_library,
138136
&res.rustc_version,
139137
&metadata_pkg.documentation,
140-
&metadata.default_target])?;
138+
&res.target])?;
141139
rows.get(0).get(0)
142140
}
143141
};

src/db/migrate.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,18 @@ pub fn migrate(version: Option<Version>) -> CratesfyiResult<()> {
213213
// downgrade query
214214
"ALTER TABLE releases ALTER COLUMN target_name DROP NOT NULL",
215215
),
216+
migration!(
217+
// version
218+
6,
219+
// description
220+
"Make default_target non-nullable",
221+
// upgrade query
222+
"UPDATE releases SET default_target = 'x86_64-unknown-linux-gnu' where default_target IS NULL;
223+
ALTER TABLE releases ALTER COLUMN default_target SET NOT NULL",
224+
// downgrade query
225+
"ALTER TABLE releases ALTER COLUMN default_target DROP NOT NULL;
226+
ALTER TABLE releases ALTER COLUMN default_target DROP DEFAULT",
227+
),
216228
];
217229

218230
for migration in migrations {

src/docbuilder/rustwide_builder.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl RustwideBuilder {
158158
}
159159

160160
info!("copying essential files for {}", self.rustc_version);
161-
let source = build.host_target_dir().join(&res.target).join("doc");
161+
let source = build.host_target_dir().join("doc");
162162
let dest = ::tempdir::TempDir::new("essential-files")?;
163163

164164
let files = ESSENTIAL_FILES_VERSIONED
@@ -266,7 +266,7 @@ impl RustwideBuilder {
266266
.build(&self.toolchain, &krate, sandbox)
267267
.run(|build| {
268268
let mut files_list = None;
269-
let (mut has_docs, mut in_target) = (false, false);
269+
let mut has_docs = false;
270270
let mut successful_targets = Vec::new();
271271
let metadata = Metadata::from_source_dir(&build.host_source_dir())?;
272272

@@ -283,20 +283,7 @@ impl RustwideBuilder {
283283

284284
if let Some(name) = res.cargo_metadata.root().library_name() {
285285
let host_target = build.host_target_dir();
286-
if host_target
287-
.join(&res.target)
288-
.join("doc")
289-
.join(&name)
290-
.is_dir()
291-
{
292-
has_docs = true;
293-
in_target = true;
294-
// hack for proc-macro documentation:
295-
// it really should be in target/$target/doc,
296-
// but rustdoc has a bug and puts it in target/doc
297-
} else if host_target.join("doc").join(name).is_dir() {
298-
has_docs = true;
299-
}
286+
has_docs = host_target.join("doc").join(name).is_dir();
300287
}
301288
}
302289

@@ -305,27 +292,25 @@ impl RustwideBuilder {
305292
self.copy_docs(
306293
&build.host_target_dir(),
307294
local_storage.path(),
308-
if in_target { &res.target } else { "" },
295+
"",
309296
true,
310297
)?;
311298

312299
successful_targets.push(res.target.clone());
313-
if in_target {
314-
// Then build the documentation for all the targets
315-
for target in &metadata.extra_targets {
316-
if *target == res.target {
317-
continue;
318-
}
319-
debug!("building package {} {} for {}", name, version, &target);
320-
self.build_target(
321-
&target,
322-
&build,
323-
&limits,
324-
&local_storage.path(),
325-
&mut successful_targets,
326-
&metadata
327-
)?;
300+
// Then build the documentation for all the targets
301+
for target in &metadata.extra_targets {
302+
if *target == res.target {
303+
continue;
328304
}
305+
debug!("building package {} {} for {}", name, version, &target);
306+
self.build_target(
307+
&target,
308+
&build,
309+
&limits,
310+
&local_storage.path(),
311+
&mut successful_targets,
312+
&metadata
313+
)?;
329314
}
330315
self.upload_docs(&conn, name, version, local_storage.path())?;
331316
}
@@ -509,6 +494,6 @@ pub(crate) struct BuildResult {
509494
pub(crate) docsrs_version: String,
510495
pub(crate) build_log: String,
511496
pub(crate) successful: bool,
512-
target: String,
497+
pub(crate) target: String,
513498
cargo_metadata: CargoMetadata,
514499
}

src/web/rustdoc.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
193193
let url_version = router.find("version");
194194
let version; // pre-declaring it to enforce drop order relative to `req_path`
195195
let conn = extension!(req, Pool);
196+
let base = redirect_base(req);
196197

197198
let mut req_path = req.url.path();
198199

@@ -208,7 +209,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
208209
// versions, redirect the browser to the returned version instead of loading it
209210
// immediately
210211
let url = ctry!(Url::parse(&format!("{}/{}/{}/{}",
211-
redirect_base(req),
212+
base,
212213
name,
213214
v,
214215
req_path.join("/"))[..]));
@@ -234,6 +235,16 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
234235
path
235236
};
236237

238+
// if visiting the full path to the default target, remove the target from the path
239+
// expects a req_path that looks like `/rustdoc/:crate/:version[/:target]/.*`
240+
let crate_details = cexpect!(CrateDetails::new(&conn, &name, &version));
241+
debug!("req_path: {}, default_target: {}", req_path.join("/"), crate_details.metadata.default_target);
242+
if req_path[3] == crate_details.metadata.default_target {
243+
let path = [base, req_path[1..3].join("/"), req_path[4..].join("/")].join("/");
244+
let canonical = Url::parse(&path).expect("got an invalid URL to start");
245+
return Ok(super::redirect(canonical));
246+
}
247+
237248
let file = match File::from_path(&conn, &path) {
238249
Some(f) => f,
239250
None => return Err(IronError::new(Nope::ResourceNotFound, status::NotFound)),
@@ -243,13 +254,6 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
243254
if !path.ends_with(".html") {
244255
return Ok(file.serve());
245256
}
246-
// if visiting the full path to the default target, remove the target from the path
247-
let crate_details = cexpect!(CrateDetails::new(&conn, &name, &version));
248-
if req_path[3] == crate_details.metadata.default_target {
249-
let canonical = Url::parse(&req_path[..2].join("/"))
250-
.expect("got an invalid URL to start");
251-
return Ok(super::redirect(canonical));
252-
}
253257

254258
let mut content = RustdocPage::default();
255259

0 commit comments

Comments
 (0)