Skip to content

Commit 7e6ff6e

Browse files
committed
remove --target by default
this required a bit of a rearchitecture
1 parent 66e4f1c commit 7e6ff6e

File tree

4 files changed

+45
-39
lines changed

4 files changed

+45
-39
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: 17 additions & 32 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

272272
// Do an initial build and then copy the sources in the database
@@ -282,20 +282,7 @@ impl RustwideBuilder {
282282

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

@@ -304,26 +291,24 @@ impl RustwideBuilder {
304291
self.copy_docs(
305292
&build.host_target_dir(),
306293
local_storage.path(),
307-
if in_target { &res.target } else { "" },
294+
"",
308295
true,
309296
)?;
310297

311298
successful_targets.push(res.target.clone());
312-
if in_target {
313-
// Then build the documentation for all the targets
314-
for target in TARGETS {
315-
debug!("building package {} {} for {}", name, version, target);
316-
if *target == res.target {
317-
continue;
318-
}
319-
self.build_target(
320-
target,
321-
&build,
322-
&limits,
323-
&local_storage.path(),
324-
&mut successful_targets,
325-
)?;
299+
// Then build the documentation for all the targets
300+
for target in TARGETS {
301+
if *target == res.target {
302+
continue;
326303
}
304+
debug!("building package {} {} for {}", name, version, &target);
305+
self.build_target(
306+
&target,
307+
&build,
308+
&limits,
309+
&local_storage.path(),
310+
&mut successful_targets,
311+
)?;
327312
}
328313
self.upload_docs(&conn, name, version, local_storage.path())?;
329314
}
@@ -506,6 +491,6 @@ pub(crate) struct BuildResult {
506491
pub(crate) docsrs_version: String,
507492
pub(crate) build_log: String,
508493
pub(crate) successful: bool,
509-
target: String,
494+
pub(crate) target: String,
510495
cargo_metadata: CargoMetadata,
511496
}

src/web/rustdoc.rs

Lines changed: 14 additions & 3 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("/"))[..]));
@@ -227,8 +228,8 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
227228
// if visiting the full path to the default target, remove the target from the path
228229
let crate_details = cexpect!(CrateDetails::new(&conn, &name, &version));
229230
if req_path[3] == crate_details.metadata.default_target {
230-
let canonical = Url::parse(&req_path[..2].join("/"))
231-
.expect("got an invalid URL to start");
231+
let path = [base, req_path[1..3].join("/"), req_path[4..].join("/")].join("/");
232+
let canonical = Url::parse(&path).expect("got an invalid URL to start");
232233
return Ok(super::redirect(canonical));
233234
}
234235

@@ -242,6 +243,16 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
242243
path
243244
};
244245

246+
// if visiting the full path to the default target, remove the target from the path
247+
// expects a req_path that looks like `/rustdoc/:crate/:version[/:target]/.*`
248+
let crate_details = cexpect!(CrateDetails::new(&conn, &name, &version));
249+
debug!("req_path: {}, default_target: {}", req_path.join("/"), crate_details.metadata.default_target);
250+
if req_path[3] == crate_details.metadata.default_target {
251+
let path = [base, req_path[1..3].join("/"), req_path[4..].join("/")].join("/");
252+
let canonical = Url::parse(&path).expect("got an invalid URL to start");
253+
return Ok(super::redirect(canonical));
254+
}
255+
245256
let file = match File::from_path(&conn, &path) {
246257
Some(f) => f,
247258
None => return Err(IronError::new(Nope::ResourceNotFound, status::NotFound)),

0 commit comments

Comments
 (0)