-
Notifications
You must be signed in to change notification settings - Fork 89
Docs publish #3218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Docs publish #3218
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| use crate::core::PackageId; | ||
| use crate::core::Workspace; | ||
| use crate::flock::LockedFile; | ||
| use crate::ops::subcommands::execute_external_subcommand_and_wait; | ||
| use anyhow::{Context, Result}; | ||
| use camino::Utf8Path; | ||
| use camino::Utf8PathBuf; | ||
| use scarb_ui::HumanBytes; | ||
| use scarb_ui::HumanCount; | ||
| use scarb_ui::components::Status; | ||
| use std::fs::File; | ||
| use std::io::Seek; | ||
| use std::io::SeekFrom; | ||
|
|
||
| fn generate_docs(pkg_id: &PackageId, ws: &Workspace<'_>) -> Result<Utf8PathBuf> { | ||
| let docs_target = ws.target_dir().path_unchecked().to_owned(); | ||
| let config = ws.config(); | ||
| let args = vec![ | ||
| "--build".into(), | ||
| "--disable-remote-linking".into(), | ||
| "--package".into(), | ||
| pkg_id.name.to_string().into(), | ||
| ]; | ||
|
|
||
| execute_external_subcommand_and_wait("doc", &args, None, config, Some(docs_target.clone()))?; | ||
|
|
||
| let docs_path = docs_target | ||
| .join("doc") | ||
| .join(pkg_id.name.to_string()) | ||
| .join("book"); | ||
| Ok(docs_path) | ||
| } | ||
|
|
||
| fn tar(src: &Utf8Path, dst: &mut File) -> Result<()> { | ||
| const COMPRESSION_LEVEL: i32 = 22; | ||
| let encoder = zstd::stream::Encoder::new(dst, COMPRESSION_LEVEL)?; | ||
|
|
||
| let mut tar = tar::Builder::new(encoder); | ||
| tar.append_dir_all(".", src) | ||
| .with_context(|| format!("failed to append directory all for {}", src))?; | ||
|
|
||
| let encoder = tar.into_inner()?; | ||
|
|
||
| encoder.finish()?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn dir_stats(src: &Utf8Path) -> Result<(usize, u64)> { | ||
| let mut count = 0; | ||
| let mut size = 0; | ||
| for entry in walkdir::WalkDir::new(src) { | ||
| let entry = entry?; | ||
| if entry.file_type().is_file() { | ||
| count += 1; | ||
| size += entry.metadata()?.len(); | ||
| } | ||
| } | ||
| Ok((count, size)) | ||
| } | ||
|
|
||
| pub fn package_docs_one(package_id: &PackageId, ws: &Workspace<'_>) -> Result<LockedFile> { | ||
| let docs_path = generate_docs(package_id, ws)?; | ||
|
|
||
| let filename = format!("docs.{}", package_id.tarball_name()); | ||
| let target_dir = ws.target_dir().child("doc"); | ||
|
|
||
| let mut dst = target_dir.create_rw(&filename, "docs tarball", ws.config())?; | ||
|
|
||
| tar(&docs_path, &mut dst)?; | ||
|
|
||
| dst.seek(SeekFrom::Start(0))?; | ||
| let dst_metadata = dst | ||
| .metadata() | ||
| .with_context(|| format!("failed to get metadata for {}", dst.path()))?; | ||
|
|
||
| let (num_files, uncompressed_size) = dir_stats(&docs_path)?; | ||
| let compressed_size = dst_metadata.len(); | ||
|
|
||
| ws.config().ui().print(Status::new( | ||
| "Packaged", | ||
| &format!( | ||
| "docs {} files, {:.1} ({:.1} compressed)", | ||
| HumanCount(num_files as u64), | ||
| HumanBytes(uncompressed_size), | ||
| HumanBytes(compressed_size), | ||
| ), | ||
| )); | ||
|
|
||
| Ok(dst) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.