Skip to content

Commit 2809259

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Upload sources even for binaries and failed builds
1 parent 8933caf commit 2809259

File tree

3 files changed

+49
-55
lines changed

3 files changed

+49
-55
lines changed

src/db/add_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn add_package_into_database(
3030
source_dir: &Path,
3131
res: &BuildResult,
3232
default_target: &str,
33-
source_files: Option<Value>,
33+
source_files: Value,
3434
doc_targets: Vec<String>,
3535
registry_data: &ReleaseData,
3636
has_docs: bool,

src/docbuilder/rustwide_builder.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,26 +348,23 @@ impl RustwideBuilder {
348348
.run(|build| {
349349
use crate::docbuilder::metadata::BuildTargets;
350350

351-
let mut files_list = None;
352351
let mut has_docs = false;
353-
let mut algs = CompressionAlgorithms::default();
354352
let mut successful_targets = Vec::new();
355353
let metadata = Metadata::from_source_dir(&build.host_source_dir())?;
356354
let BuildTargets {
357355
default_target,
358356
other_targets,
359357
} = metadata.targets();
360358

361-
// Do an initial build and then copy the sources in the database
359+
// Store the sources even if the build fails
360+
debug!("adding sources into database");
361+
let prefix = format!("sources/{}/{}", name, version);
362+
let (files_list, mut algs) =
363+
add_path_into_database(&self.storage, &prefix, build.host_source_dir())?;
364+
365+
// Perform an initial build
362366
let res = self.execute_build(default_target, true, &build, &limits, &metadata)?;
363367
if res.result.successful {
364-
debug!("adding sources into database");
365-
let prefix = format!("sources/{}/{}", name, version);
366-
let (files, new_algs) =
367-
add_path_into_database(&self.storage, &prefix, build.host_source_dir())?;
368-
files_list = Some(files);
369-
algs.extend(new_algs);
370-
371368
if let Some(name) = res.cargo_metadata.root().library_name() {
372369
let host_target = build.host_target_dir();
373370
has_docs = host_target.join("doc").join(name).is_dir();

src/test/fakes.rs

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -184,67 +184,64 @@ impl<'a> FakeRelease<'a> {
184184

185185
/// Returns the release_id
186186
pub(crate) fn create(self) -> Result<i32, Error> {
187-
use std::collections::HashSet;
188187
use std::fs;
189188
use std::path::Path;
190189

191190
let tempdir = tempfile::Builder::new().prefix("docs.rs-fake").tempdir()?;
192191
let package = self.package;
193192
let db = self.db;
193+
let mut rustdoc_files = self.rustdoc_files;
194+
let storage = self.storage;
194195

195-
let mut source_meta = None;
196-
let mut algs = HashSet::new();
197-
if self.build_result.successful {
198-
let storage = self.storage.clone();
199-
let upload_files = |prefix: &str, files: &[(&str, &[u8])], target: Option<&str>| {
200-
let mut path_prefix = tempdir.path().join(prefix);
201-
if let Some(target) = target {
202-
path_prefix.push(target);
203-
}
204-
fs::create_dir(&path_prefix)?;
205-
206-
for (path, data) in files {
207-
// allow `src/main.rs`
208-
if let Some(parent) = Path::new(path).parent() {
209-
fs::create_dir_all(path_prefix.join(parent))?;
210-
}
211-
let file = path_prefix.join(&path);
212-
log::debug!("writing file {}", file.display());
213-
fs::write(file, data)?;
196+
// Upload all source files as rustdoc files
197+
// In real life, these would be highlighted HTML, but for testing we just use the files themselves.
198+
for (source_path, data) in &self.source_files {
199+
if source_path.starts_with("src/") {
200+
let updated = ["src", &package.name, &source_path[4..]].join("/");
201+
rustdoc_files.push((Box::leak(Box::new(updated)), data));
202+
}
203+
}
204+
205+
let upload_files = |prefix: &str, files: &[(&str, &[u8])], target: Option<&str>| {
206+
let mut path_prefix = tempdir.path().join(prefix);
207+
if let Some(target) = target {
208+
path_prefix.push(target);
209+
}
210+
fs::create_dir(&path_prefix)?;
211+
212+
for (path, data) in files {
213+
// allow `src/main.rs`
214+
if let Some(parent) = Path::new(path).parent() {
215+
fs::create_dir_all(path_prefix.join(parent))?;
214216
}
217+
let file = path_prefix.join(&path);
218+
log::debug!("writing file {}", file.display());
219+
fs::write(file, data)?;
220+
}
215221

216-
let prefix = format!(
217-
"{}/{}/{}/{}",
218-
prefix,
219-
package.name,
220-
package.version,
221-
target.unwrap_or("")
222-
);
223-
log::debug!("adding directory {} from {}", prefix, path_prefix.display());
224-
crate::db::add_path_into_database(&storage, &prefix, path_prefix)
225-
};
222+
let prefix = format!(
223+
"{}/{}/{}/{}",
224+
prefix,
225+
package.name,
226+
package.version,
227+
target.unwrap_or("")
228+
);
229+
log::debug!("adding directory {} from {}", prefix, path_prefix.display());
230+
crate::db::add_path_into_database(&storage, &prefix, path_prefix)
231+
};
226232

233+
let (source_meta, mut algs) = upload_files("source", &self.source_files, None)?;
234+
log::debug!("added source files {}", source_meta);
235+
236+
if self.build_result.successful {
227237
let index = [&package.name, "index.html"].join("/");
228-
let mut rustdoc_files = self.rustdoc_files;
229238
if package.is_library() && !rustdoc_files.iter().any(|(path, _)| path == &index) {
230239
rustdoc_files.push((&index, DEFAULT_CONTENT));
231240
}
232-
for (source_path, data) in &self.source_files {
233-
if source_path.starts_with("src/") {
234-
let updated = ["src", &package.name, &source_path[4..]].join("/");
235-
rustdoc_files.push((Box::leak(Box::new(updated)), data));
236-
}
237-
}
241+
238242
let (rustdoc_meta, new_algs) = upload_files("rustdoc", &rustdoc_files, None)?;
239243
algs.extend(new_algs);
240244
log::debug!("added rustdoc files {}", rustdoc_meta);
241-
match upload_files("source", &self.source_files, None)? {
242-
(json, new_algs) => {
243-
source_meta = Some(json);
244-
algs.extend(new_algs);
245-
}
246-
}
247-
log::debug!("added source files {}", source_meta.as_ref().unwrap());
248245

249246
for target in &package.targets[1..] {
250247
let platform = target.src_path.as_ref().unwrap();

0 commit comments

Comments
 (0)