Skip to content

Commit

Permalink
drop use_archive_storage config var and old non-archive build logic
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Aug 18, 2021
1 parent 2f0865a commit 44e68e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 139 deletions.
2 changes: 0 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub struct Config {
// where do we want to store the locally cached index files
// for the remote archives?
pub(crate) local_archive_cache_path: PathBuf,
pub(crate) use_archive_storage: bool,

// Content Security Policy
pub(crate) csp_report_only: bool,
Expand Down Expand Up @@ -136,7 +135,6 @@ impl Config {
"DOCSRS_ARCHIVE_INDEX_CACHE_PATH",
PathBuf::from(".archive_cache"),
)?,
use_archive_storage: env("DOCSRS_USE_ARCHIVE_STORAGE", false)?,

rustwide_workspace: env("DOCSRS_RUSTWIDE_WORKSPACE", PathBuf::from(".workspace"))?,
inside_docker: env("DOCSRS_DOCKER", false)?,
Expand Down
145 changes: 8 additions & 137 deletions src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,44 +359,24 @@ impl RustwideBuilder {
&metadata,
)?;
}
if self.config.use_archive_storage {
let (_, new_alg) = add_path_into_remote_archive(
&self.storage,
&rustdoc_archive_path(name, version),
local_storage.path(),
)?;
algs.insert(new_alg);
} else {
debug!("Adding documentation into database");
let (_, new_algs) = add_path_into_database(
&self.storage,
&format!("rustdoc/{}/{}", name, version),
local_storage.path(),
)?;

algs.extend(new_algs);
}
let (_, new_alg) = add_path_into_remote_archive(
&self.storage,
&rustdoc_archive_path(name, version),
local_storage.path(),
)?;
algs.insert(new_alg);
};

// Store the sources even if the build fails
debug!("adding sources into database");
let files_list = if self.config.use_archive_storage {
let files_list = {
let (files_list, new_alg) = add_path_into_remote_archive(
&self.storage,
&source_archive_path(name, version),
build.host_source_dir(),
)?;
algs.insert(new_alg);
files_list
} else {
let prefix = format!("sources/{}/{}", name, version);
let (files_list, new_algs) = add_path_into_database(
&self.storage,
&prefix,
build.host_source_dir(),
)?;
algs.extend(new_algs);
files_list
};

let has_examples = build.host_source_dir().join("examples").is_dir();
Expand Down Expand Up @@ -432,7 +412,7 @@ impl RustwideBuilder {
has_examples,
algs,
repository,
self.config.use_archive_storage,
true,
)?;

if let Some(doc_coverage) = res.doc_coverage {
Expand Down Expand Up @@ -766,115 +746,6 @@ mod tests {
let version = DUMMY_CRATE_VERSION;
let default_target = "x86_64-unknown-linux-gnu";

assert!(env.config().include_default_targets);

let mut builder = RustwideBuilder::init(env).unwrap();
builder
.build_package(crate_, version, PackageKind::CratesIo)
.map(|_| ())?;

// check release record in the db (default and other targets)
let mut conn = env.db().conn();
let rows = conn
.query(
"SELECT
r.rustdoc_status,
r.default_target,
r.doc_targets,
r.archive_storage,
cov.total_items
FROM
crates as c
INNER JOIN releases AS r ON c.id = r.crate_id
LEFT OUTER JOIN doc_coverage AS cov ON r.id = cov.release_id
WHERE
c.name = $1 AND
r.version = $2",
&[&crate_, &version],
)
.unwrap();
let row = rows.get(0).unwrap();

assert!(row.get::<_, bool>("rustdoc_status"));
assert_eq!(row.get::<_, String>("default_target"), default_target);
assert!(row.get::<_, Option<i32>>("total_items").is_some());
assert!(!row.get::<_, bool>("archive_storage"));

let mut targets: Vec<String> = row
.get::<_, Value>("doc_targets")
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap().to_owned())
.collect();
targets.sort();
assert_eq!(
targets,
vec![
"i686-pc-windows-msvc",
"i686-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
]
);

let storage = env.storage();
let web = env.frontend();

// sources exist
assert!(storage.exists(&format!("sources/{}/{}/src/lib.rs", crate_, version))?);
assert_success(
&format!("/crate/{}/{}/source/src/lib.rs", crate_, version),
web,
)?;

let base = format!("rustdoc/{}/{}", crate_, version);

// default target was built and is accessible
assert!(storage.exists(&format!("{}/{}/index.html", base, crate_path))?);
assert_success(&format!("/{}/{}/{}", crate_, version, crate_path), web)?;

// other targets too
for target in DEFAULT_TARGETS {
let target_docs_present =
storage.exists(&format!("{}/{}/{}/index.html", base, target, crate_path))?;

let target_url = format!(
"/{}/{}/{}/{}/index.html",
crate_, version, target, crate_path
);

if target == &default_target {
assert!(!target_docs_present);
assert_redirect(
&target_url,
&format!("/{}/{}/{}/index.html", crate_, version, crate_path),
web,
)?;
} else {
assert!(target_docs_present);
assert_success(&target_url, web)?;
}
}

Ok(())
})
}

#[test]
#[ignore]
fn test_build_crate_into_archive() {
wrapper(|env| {
let crate_ = DUMMY_CRATE_NAME;
let crate_path = crate_.replace("-", "_");
let version = DUMMY_CRATE_VERSION;
let default_target = "x86_64-unknown-linux-gnu";

env.override_config(|config| {
config.use_archive_storage = true;
});

let mut builder = RustwideBuilder::init(env).unwrap();
builder
.build_package(crate_, version, PackageKind::CratesIo)
Expand Down

0 comments on commit 44e68e4

Please sign in to comment.