Skip to content

Commit a038575

Browse files
committed
Revert "Merge pull request #534 from jyn514/one-default-target"
This reverts commit 2b9f981, reversing changes made to 0b16db9.
1 parent 2b9f981 commit a038575

File tree

9 files changed

+49
-102
lines changed

9 files changed

+49
-102
lines changed

src/db/add_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub(crate) fn add_package_into_database(conn: &Connection,
2626
metadata_pkg: &MetadataPackage,
2727
source_dir: &Path,
2828
res: &BuildResult,
29-
default_target: &str,
3029
files: Option<Json>,
3130
doc_targets: Vec<String>,
31+
default_target: &Option<String>,
3232
cratesio_data: &CratesIoData,
3333
has_docs: bool,
3434
has_examples: bool)

src/db/migrate.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,6 @@ 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-
),
285272
];
286273

287274
for migration in migrations {

src/docbuilder/rustwide_builder.rs

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@ use std::path::Path;
1818
use utils::{copy_doc_dir, parse_rustc_version, CargoMetadata};
1919
use Metadata;
2020

21-
const USER_AGENT: &str = "docs.rs builder (https://github.com/rust-lang/docs.rs)";
22-
const DEFAULT_RUSTWIDE_WORKSPACE: &str = ".rustwide";
21+
static USER_AGENT: &str = "docs.rs builder (https://github.com/rust-lang/docs.rs)";
22+
static DEFAULT_RUSTWIDE_WORKSPACE: &str = ".rustwide";
2323

24-
const DEFAULT_TARGET: &str = "x86_64-unknown-linux-gnu";
25-
const TARGETS: &[&str] = &[
24+
static TARGETS: &[&str] = &[
2625
"i686-pc-windows-msvc",
2726
"i686-unknown-linux-gnu",
2827
"x86_64-apple-darwin",
2928
"x86_64-pc-windows-msvc",
3029
"x86_64-unknown-linux-gnu",
3130
];
3231

33-
const ESSENTIAL_FILES_VERSIONED: &[&str] = &[
32+
static ESSENTIAL_FILES_VERSIONED: &[&str] = &[
3433
"brush.svg",
3534
"wheel.svg",
3635
"down-arrow.svg",
@@ -47,7 +46,7 @@ const ESSENTIAL_FILES_VERSIONED: &[&str] = &[
4746
"noscript.css",
4847
"rust-logo.png",
4948
];
50-
const ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
49+
static ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
5150
"FiraSans-Medium.woff",
5251
"FiraSans-Regular.woff",
5352
"SourceCodePro-Regular.woff",
@@ -57,8 +56,8 @@ const ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
5756
"SourceSerifPro-It.ttf.woff",
5857
];
5958

60-
const DUMMY_CRATE_NAME: &str = "acme-client";
61-
const DUMMY_CRATE_VERSION: &str = "0.0.0";
59+
static DUMMY_CRATE_NAME: &str = "acme-client";
60+
static DUMMY_CRATE_VERSION: &str = "0.0.0";
6261

6362
pub struct RustwideBuilder {
6463
workspace: Workspace,
@@ -190,7 +189,7 @@ impl RustwideBuilder {
190189
}
191190

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

196195
let files = ESSENTIAL_FILES_VERSIONED
@@ -304,7 +303,7 @@ impl RustwideBuilder {
304303
.build(&self.toolchain, &krate, sandbox)
305304
.run(|build| {
306305
let mut files_list = None;
307-
let mut has_docs = false;
306+
let (mut has_docs, mut in_target) = (false, false);
308307
let mut successful_targets = Vec::new();
309308

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

321320
if let Some(name) = res.cargo_metadata.root().library_name() {
322321
let host_target = build.host_target_dir();
323-
has_docs = host_target.join("doc").join(name).is_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+
}
324336
}
325337
}
326338

@@ -329,24 +341,22 @@ impl RustwideBuilder {
329341
self.copy_docs(
330342
&build.host_target_dir(),
331343
local_storage.path(),
332-
"",
344+
if in_target { &res.target } else { "" },
333345
true,
334346
)?;
335347

336-
successful_targets.push(res.target.clone());
337-
// Then build the documentation for all the targets
338-
for target in TARGETS {
339-
if *target == res.target {
340-
continue;
348+
if in_target {
349+
// Then build the documentation for all the targets
350+
for target in TARGETS {
351+
debug!("building package {} {} for {}", name, version, target);
352+
self.build_target(
353+
target,
354+
&build,
355+
&limits,
356+
&local_storage.path(),
357+
&mut successful_targets,
358+
)?;
341359
}
342-
debug!("building package {} {} for {}", name, version, &target);
343-
self.build_target(
344-
&target,
345-
&build,
346-
&limits,
347-
&local_storage.path(),
348-
&mut successful_targets,
349-
)?;
350360
}
351361
self.upload_docs(&conn, name, version, local_storage.path())?;
352362
}
@@ -364,9 +374,9 @@ impl RustwideBuilder {
364374
res.cargo_metadata.root(),
365375
&build.host_source_dir(),
366376
&res.result,
367-
&res.target,
368377
files_list,
369378
successful_targets,
379+
&res.default_target,
370380
&CratesIoData::get_from_network(res.cargo_metadata.root())?,
371381
has_docs,
372382
has_examples,
@@ -415,7 +425,6 @@ impl RustwideBuilder {
415425
let cargo_metadata =
416426
CargoMetadata::load(&self.workspace, &self.toolchain, &build.host_source_dir())?;
417427

418-
let is_default_target = target.is_none();
419428
let target = target.or_else(|| metadata.default_target.as_ref().map(|s| s.as_str()));
420429

421430
let mut rustdoc_flags: Vec<String> = vec![
@@ -475,20 +484,6 @@ impl RustwideBuilder {
475484
.run()
476485
.is_ok()
477486
});
478-
// If we're passed a default_target which requires a cross-compile,
479-
// cargo will put the output in `target/<target>/doc`.
480-
// However, if this is the default build, we don't want it there,
481-
// we want it in `target/doc`.
482-
if let Some(explicit_target) = target {
483-
if is_default_target {
484-
// mv target/$explicit_target/doc target/doc
485-
let target_dir = build.host_target_dir();
486-
let old_dir = target_dir.join(explicit_target).join("doc");
487-
let new_dir = target_dir.join("doc");
488-
debug!("rename {} to {}", old_dir.display(), new_dir.display());
489-
std::fs::rename(old_dir, new_dir)?;
490-
}
491-
}
492487

493488
Ok(FullBuildResult {
494489
result: BuildResult {
@@ -498,7 +493,8 @@ impl RustwideBuilder {
498493
successful,
499494
},
500495
cargo_metadata,
501-
target: target.unwrap_or(DEFAULT_TARGET).to_string(),
496+
target: target.unwrap_or_default().to_string(),
497+
default_target: metadata.default_target.clone(),
502498
})
503499
}
504500

@@ -546,6 +542,7 @@ impl RustwideBuilder {
546542
struct FullBuildResult {
547543
result: BuildResult,
548544
target: String,
545+
default_target: Option<String>,
549546
cargo_metadata: CargoMetadata,
550547
}
551548

src/test/fakes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ impl<'db> FakeRelease<'db> {
8484
&self.package,
8585
tempdir.path(),
8686
&self.build_result,
87-
self.default_target.as_deref().unwrap_or("x86_64-unknown-linux-gnu"),
8887
self.files,
8988
self.doc_targets,
89+
&self.default_target,
9090
&self.cratesio_data,
9191
self.has_docs,
9292
self.has_examples,

src/web/crate_details.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct CrateDetails {
4343
github_stars: Option<i32>,
4444
github_forks: Option<i32>,
4545
github_issues: Option<i32>,
46-
pub metadata: MetaData,
46+
metadata: MetaData,
4747
is_library: bool,
4848
doc_targets: Option<Json>,
4949
license: Option<String>,
@@ -120,8 +120,7 @@ impl CrateDetails {
120120
releases.is_library,
121121
releases.doc_targets,
122122
releases.license,
123-
releases.documentation_url,
124-
releases.default_target
123+
releases.documentation_url
125124
FROM releases
126125
INNER JOIN crates ON releases.crate_id = crates.id
127126
WHERE crates.name = $1 AND releases.version = $2;";
@@ -161,7 +160,6 @@ impl CrateDetails {
161160
description: rows.get(0).get(4),
162161
rustdoc_status: rows.get(0).get(11),
163162
target_name: rows.get(0).get(16),
164-
default_target: rows.get(0).get(25),
165163
};
166164

167165
let mut crate_details = CrateDetails {

src/web/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ pub struct MetaData {
451451
pub description: Option<String>,
452452
pub target_name: Option<String>,
453453
pub rustdoc_status: bool,
454-
pub default_target: String,
455454
}
456455

457456

@@ -461,8 +460,7 @@ impl MetaData {
461460
releases.version,
462461
releases.description,
463462
releases.target_name,
464-
releases.rustdoc_status,
465-
releases.default_target
463+
releases.rustdoc_status
466464
FROM releases
467465
INNER JOIN crates ON crates.id = releases.crate_id
468466
WHERE crates.name = $1 AND releases.version = $2",
@@ -475,7 +473,6 @@ impl MetaData {
475473
description: row.get(2),
476474
target_name: row.get(3),
477475
rustdoc_status: row.get(4),
478-
default_target: row.get(5),
479476
});
480477
}
481478

@@ -492,7 +489,6 @@ impl ToJson for MetaData {
492489
m.insert("description".to_owned(), self.description.to_json());
493490
m.insert("target_name".to_owned(), self.target_name.to_json());
494491
m.insert("rustdoc_status".to_owned(), self.rustdoc_status.to_json());
495-
m.insert("default_target".to_owned(), self.default_target.to_json());
496492
m.to_json()
497493
}
498494
}

src/web/rustdoc.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ 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);
197196

198197
let mut req_path = req.url.path();
199198

@@ -209,7 +208,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
209208
// versions, redirect the browser to the returned version instead of loading it
210209
// immediately
211210
let url = ctry!(Url::parse(&format!("{}/{}/{}/{}",
212-
base,
211+
redirect_base(req),
213212
name,
214213
v,
215214
req_path.join("/"))[..]));
@@ -225,15 +224,6 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
225224
req_path.insert(1, &name);
226225
req_path.insert(2, &version);
227226

228-
// if visiting the full path to the default target, remove the target from the path
229-
// expects a req_path that looks like `/rustdoc/:crate/:version[/:target]/.*`
230-
let crate_details = cexpect!(CrateDetails::new(&conn, &name, &version));
231-
if req_path[3] == crate_details.metadata.default_target {
232-
let path = [base, req_path[1..3].join("/"), req_path[4..].join("/")].join("/");
233-
let canonical = Url::parse(&path).expect("got an invalid URL to start");
234-
return Ok(super::redirect(canonical));
235-
}
236-
237227
let path = {
238228
let mut path = req_path.join("/");
239229
if path.ends_with('/') {
@@ -271,6 +261,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
271261
content.body_class = body_class;
272262

273263
content.full = file_content;
264+
let crate_details = cexpect!(CrateDetails::new(&conn, &name, &version));
274265
let (path, version) = if let Some(version) = latest_version(&crate_details.versions, &version) {
275266
req_path[2] = &version;
276267
(path_for_version(&req_path, &crate_details.target_name, &conn), version)

src/web/source.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ impl FileList {
9393
releases.description,
9494
releases.target_name,
9595
releases.rustdoc_status,
96-
releases.files,
97-
releases.default_target
96+
releases.files
9897
FROM releases
9998
LEFT OUTER JOIN crates ON crates.id = releases.crate_id
10099
WHERE crates.name = $1 AND releases.version = $2",
@@ -174,7 +173,6 @@ impl FileList {
174173
description: rows.get(0).get(2),
175174
target_name: rows.get(0).get(3),
176175
rustdoc_status: rows.get(0).get(4),
177-
default_target: rows.get(0).get(5),
178176
},
179177
files: file_list,
180178
})

templates/about.hbs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,41 +127,21 @@
127127
</tbody>
128128
</table>
129129

130-
<h4 id="metadata"><a href="#metadata">Metadata for custom builds</a></h4>
130+
<h4>Metadata for custom builds</h4>
131131

132132
<p>You can customize docs.rs builds by defining <code>[package.metadata.docs.rs]</code> table in your crates' `Cargo.toml`.</p>
133133

134-
<p>The available configuration flags you can customize are:</p>
134+
<p>An example metadata:</p>
135135

136136
<pre><code>[package]
137137
name = "test"
138138

139139
[package.metadata.docs.rs]
140-
141-
# Features to pass to Cargo (default: [])
142140
features = [ "feature1", "feature2" ]
143-
144-
# Whether to pass `--all-features` to Cargo (default: false)
145141
all-features = true
146-
147-
# Whether to pass `--no-default-features` to Cargo (default: false)
148142
no-default-features = true
149-
150-
# Target to test build on, used as the default landing page (default: "x86_64-unknown-linux-gnu")
151-
#
152-
# Available targets:
153-
# - x86_64-unknown-linux-gnu
154-
# - x86_64-apple-darwin
155-
# - x86_64-pc-windows-msvc
156-
# - i686-unknown-linux-gnu
157-
# - i686-apple-darwin
158-
# - i686-pc-windows-msvc
159143
default-target = "x86_64-unknown-linux-gnu"
160-
161-
# Additional `RUSTFLAGS` to set (default: [])
162144
rustc-args = [ "--example-rustc-arg" ]
163-
164-
# Additional `RUSTDOCFLAGS` to set (default: [])
165145
rustdoc-args = [ "--example-rustdoc-arg" ]</pre></code>
166146

167147
<h4>Version</h4>

0 commit comments

Comments
 (0)