Skip to content

Commit fa14994

Browse files
committed
remove --target by default
this required a bit of a rearchitecture
1 parent 675b96a commit fa14994

File tree

5 files changed

+46
-39
lines changed

5 files changed

+46
-39
lines changed

src/db/add_package.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub(crate) fn add_package_into_database(conn: &Connection,
2828
res: &BuildResult,
2929
files: Option<Json>,
3030
doc_targets: Vec<String>,
31-
default_target: &Option<String>,
3231
cratesio_data: &CratesIoData,
3332
has_docs: bool,
3433
has_examples: bool)
@@ -83,7 +82,7 @@ pub(crate) fn add_package_into_database(conn: &Connection,
8382
&is_library,
8483
&res.rustc_version,
8584
&metadata_pkg.documentation,
86-
&default_target])?;
85+
&res.target])?;
8786
// return id
8887
rows.get(0).get(0)
8988

@@ -137,7 +136,7 @@ pub(crate) fn add_package_into_database(conn: &Connection,
137136
&is_library,
138137
&res.rustc_version,
139138
&metadata_pkg.documentation,
140-
&default_target])?;
139+
&res.target])?;
141140
rows.get(0).get(0)
142141
}
143142
};

src/db/migrate.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ fn migrate_inner(version: Option<Version>, conn: &Connection, apply_mode: ApplyM
269269
// downgrade query
270270
"DROP TABLE blacklisted_crates;"
271271
),
272+
migration!(
273+
context,
274+
// version
275+
7,
276+
// description
277+
"Make default_target non-nullable",
278+
// upgrade query
279+
"UPDATE releases SET default_target = 'x86_64-unknown-linux-gnu' WHERE default_target IS NULL;
280+
ALTER TABLE releases ALTER COLUMN default_target SET NOT NULL",
281+
// downgrade query
282+
"ALTER TABLE releases ALTER COLUMN default_target DROP NOT NULL;
283+
ALTER TABLE releases ALTER COLUMN default_target DROP DEFAULT",
284+
),
272285
];
273286

274287
for migration in migrations {

src/docbuilder/rustwide_builder.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl RustwideBuilder {
189189
}
190190

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

195195
let files = ESSENTIAL_FILES_VERSIONED
@@ -303,7 +303,7 @@ impl RustwideBuilder {
303303
.build(&self.toolchain, &krate, sandbox)
304304
.run(|build| {
305305
let mut files_list = None;
306-
let (mut has_docs, mut in_target) = (false, false);
306+
let mut has_docs = false;
307307
let mut successful_targets = Vec::new();
308308

309309
// Do an initial build and then copy the sources in the database
@@ -319,20 +319,7 @@ impl RustwideBuilder {
319319

320320
if let Some(name) = res.cargo_metadata.root().library_name() {
321321
let host_target = build.host_target_dir();
322-
if host_target
323-
.join(&res.target)
324-
.join("doc")
325-
.join(&name)
326-
.is_dir()
327-
{
328-
has_docs = true;
329-
in_target = true;
330-
// hack for proc-macro documentation:
331-
// it really should be in target/$target/doc,
332-
// but rustdoc has a bug and puts it in target/doc
333-
} else if host_target.join("doc").join(name).is_dir() {
334-
has_docs = true;
335-
}
322+
has_docs = host_target.join("doc").join(name).is_dir();
336323
}
337324
}
338325

@@ -341,26 +328,24 @@ impl RustwideBuilder {
341328
self.copy_docs(
342329
&build.host_target_dir(),
343330
local_storage.path(),
344-
if in_target { &res.target } else { "" },
331+
"",
345332
true,
346333
)?;
347334

348335
successful_targets.push(res.target.clone());
349-
if in_target {
350-
// Then build the documentation for all the targets
351-
for target in TARGETS {
352-
debug!("building package {} {} for {}", name, version, target);
353-
if *target == res.target {
354-
continue;
355-
}
356-
self.build_target(
357-
target,
358-
&build,
359-
&limits,
360-
&local_storage.path(),
361-
&mut successful_targets,
362-
)?;
336+
// Then build the documentation for all the targets
337+
for target in TARGETS {
338+
if *target == res.target {
339+
continue;
363340
}
341+
debug!("building package {} {} for {}", name, version, &target);
342+
self.build_target(
343+
&target,
344+
&build,
345+
&limits,
346+
&local_storage.path(),
347+
&mut successful_targets,
348+
)?;
364349
}
365350
self.upload_docs(&conn, name, version, local_storage.path())?;
366351
}
@@ -380,7 +365,6 @@ impl RustwideBuilder {
380365
&res.result,
381366
files_list,
382367
successful_targets,
383-
&res.default_target,
384368
&CratesIoData::get_from_network(res.cargo_metadata.root())?,
385369
has_docs,
386370
has_examples,
@@ -555,4 +539,5 @@ pub(crate) struct BuildResult {
555539
pub(crate) docsrs_version: String,
556540
pub(crate) build_log: String,
557541
pub(crate) successful: bool,
542+
pub(crate) target: String,
558543
}

src/test/fakes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ impl<'db> FakeRelease<'db> {
8686
&self.build_result,
8787
self.files,
8888
self.doc_targets,
89-
&self.default_target,
9089
&self.cratesio_data,
9190
self.has_docs,
9291
self.has_examples,

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)