Skip to content

Commit

Permalink
Add --manifest option (#17)
Browse files Browse the repository at this point in the history
* Fix tag name

* Update deps

* Add support for specifying the top-level manifest

* Fix clippy lints

* Bump mio, this looks bad, but we don't build for windows

* Update CHANGELOG
  • Loading branch information
Jake-Shadle committed Nov 22, 2021
1 parent 60afbe5 commit 4c703b2
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Added
- [PR#17](https://github.com/Jake-Shadle/xwin/pull/17) resolved [#6](https://github.com/Jake-Shadle/xwin/issues/6) by adding the `--manifest` option so that users can specify an exact manifest to use rather than downloading the mutable one from the Microsoft CDN.

## [0.1.3] - 2021-11-17
### Fixed
- [PR#15](https://github.com/Jake-Shadle/xwin/pull/15) resolved [#14](https://github.com/Jake-Shadle/xwin/issues/14) by removing the unnecessary use of `tokio::main`. Thanks [@mite-user](https://github.com/mite-user)!
Expand Down
65 changes: 54 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pre-release-commit-message = "Release {{crate_name}} {{version}}"
no-dev-version = true
tag-message = "Release {{crate_name}} {{version}}"
tag-name = "{{crate_name}}-{{version}}"
tag-name = "{{version}}"
pre-release-replacements = [
{ file = "CHANGELOG.md", search = "Unreleased", replace = "{{version}}" },
{ file = "CHANGELOG.md", search = "\\.\\.\\.HEAD", replace = "...{{tag_name}}" },
Expand Down
56 changes: 38 additions & 18 deletions src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing_subscriber::filter::LevelFilter;
fn setup_logger(json: bool, log_level: LevelFilter) -> Result<(), Error> {
let mut env_filter = tracing_subscriber::EnvFilter::from_default_env();

// If a user specifies a log level, we assume it only pertains to cargo_fetcher,
// If a user specifies a log level, we assume it only pertains to xwin,
// if they want to trace other crates they can use the RUST_LOG env approach
env_filter = env_filter.add_directive(format!("xwin={}", log_level).parse()?);

Expand Down Expand Up @@ -117,6 +117,10 @@ pub struct Args {
/// Defaults to `./.xwin-cache` if not specified.
#[structopt(long)]
cache_dir: Option<PathBuf>,
/// Specifies a VS manifest to use from a file, rather than downloading it
/// from the Microsoft site.
#[structopt(long, conflicts_with_all = &["version", "channel"])]
manifest: Option<PathBuf>,
/// The version to retrieve, can either be a major version of 15 or 16, or
/// a "<major>.<minor>" version.
#[structopt(long, default_value = "16")]
Expand Down Expand Up @@ -169,28 +173,16 @@ fn main() -> Result<(), Error> {
let ctx = if args.temp {
xwin::Ctx::with_temp()?
} else {
let cache_dir = match args.cache_dir {
Some(cd) => cd,
let cache_dir = match &args.cache_dir {
Some(cd) => cd.clone(),
None => cwd.join(".xwin-cache"),
};
xwin::Ctx::with_dir(cache_dir)?
};

let ctx = std::sync::Arc::new(ctx);

let manifest_pb = ia::ProgressBar::with_draw_target(0, ia::ProgressDrawTarget::stdout())
.with_style(
ia::ProgressStyle::default_bar()
.template(
"{spinner:.green} {prefix:.bold} [{elapsed}] {wide_bar:.green} {bytes}/{total_bytes} {msg}",
)
.progress_chars("█▇▆▅▄▃▂▁ "),
);
manifest_pb.set_prefix("Manifest");
manifest_pb.set_message("📥 downloading");
let pkg_manifest =
xwin::get_pkg_manifest(&ctx, &args.version, &args.channel, manifest_pb.clone())?;
manifest_pb.finish_with_message("📥 downloaded");
let pkg_manifest = load_manifest(&ctx, &args)?;

let arches = args.arch.into_iter().fold(0, |acc, arch| acc | arch as u32);
let variants = args
Expand Down Expand Up @@ -275,8 +267,6 @@ fn main() -> Result<(), Error> {
let res =
std::thread::spawn(move || ctx.execute(pkgs, work_items, arches, variants, op)).join();

//mp.join().unwrap();

res.unwrap()
}

Expand Down Expand Up @@ -330,3 +320,33 @@ fn print_packages(payloads: &[xwin::Payload]) {

let _ = cli_table::print_stdout(table);
}

fn load_manifest(ctx: &xwin::Ctx, args: &Args) -> anyhow::Result<xwin::manifest::PackageManifest> {
let manifest_pb = ia::ProgressBar::with_draw_target(0, ia::ProgressDrawTarget::stdout())
.with_style(
ia::ProgressStyle::default_bar()
.template(
"{spinner:.green} {prefix:.bold} [{elapsed}] {wide_bar:.green} {bytes}/{total_bytes} {msg}",
)
.progress_chars("█▇▆▅▄▃▂▁ "),
);
manifest_pb.set_prefix("Manifest");
manifest_pb.set_message("📥 downloading");

let manifest = match &args.manifest {
Some(manifest_path) => {
let manifest_content = std::fs::read_to_string(manifest_path)
.with_context(|| format!("failed to read path '{}'", manifest_path))?;
serde_json::from_str(&manifest_content)
.with_context(|| format!("failed to deserialize manifest in '{}'", manifest_path))?
}
None => {
xwin::manifest::get_manifest(ctx, &args.version, &args.channel, manifest_pb.clone())?
}
};

let pkg_manifest = xwin::manifest::get_package_manifest(ctx, &manifest, manifest_pb.clone())?;

manifest_pb.finish_with_message("📥 downloaded");
Ok(pkg_manifest)
}
10 changes: 0 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,6 @@ impl Variant {
}
}

pub fn get_pkg_manifest(
ctx: &Ctx,
version: &str,
channel: &str,
progress: indicatif::ProgressBar,
) -> Result<manifest::PackageManifest, Error> {
let vs_manifest = manifest::get_manifest(ctx, version, channel, progress.clone())?;
manifest::get_package_manifest(ctx, &vs_manifest, progress)
}

pub enum Ops {
Download,
Unpack,
Expand Down
6 changes: 6 additions & 0 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct ManifestItem {
}

impl PartialEq for ManifestItem {
#[inline]
fn eq(&self, o: &Self) -> bool {
self.cmp(o) == cmp::Ordering::Equal
}
Expand All @@ -87,12 +88,14 @@ impl PartialEq for ManifestItem {
impl Eq for ManifestItem {}

impl cmp::Ord for ManifestItem {
#[inline]
fn cmp(&self, o: &Self) -> cmp::Ordering {
self.id.cmp(&o.id)
}
}

impl cmp::PartialOrd for ManifestItem {
#[inline]
fn partial_cmp(&self, o: &Self) -> Option<cmp::Ordering> {
Some(self.cmp(o))
}
Expand All @@ -104,6 +107,8 @@ pub struct Manifest {
channel_items: Vec<ManifestItem>,
}

/// Retrieves the top-level manifest which contains license links as well as the
/// link to the actual package manifest which describes all of the contents
pub fn get_manifest(
ctx: &Ctx,
version: &str,
Expand All @@ -122,6 +127,7 @@ pub fn get_manifest(
Ok(manifest)
}

/// Retrieves the package manifest specified in the input manifest
pub fn get_package_manifest(
ctx: &Ctx,
manifest: &Manifest,
Expand Down

0 comments on commit 4c703b2

Please sign in to comment.