Skip to content

Commit

Permalink
Remove github-specific logic in favour of new git pkg handling
Browse files Browse the repository at this point in the history
See #829.

This also temporarily disables `forc update` and the related
`forc_dep_check` module pending more general `git` support and
committing updates to a `Forc.lock` file.
  • Loading branch information
mitchmindtree committed Feb 28, 2022
1 parent 1b27b39 commit da6c3cc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 545 deletions.
1 change: 0 additions & 1 deletion forc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ ansi_term = "0.12"
anyhow = "1.0.41"
clap = { version = "3.1.2", features = ["env", "derive"] }
dirs = "3.0.2"
flate2 = "1.0.20"
fuel-asm = "0.1"
fuel-gql-client = { version = "0.3", default-features = false }
fuel-tx = "0.5"
Expand Down
133 changes: 0 additions & 133 deletions forc/src/ops/forc_dep_check.rs

This file was deleted.

94 changes: 23 additions & 71 deletions forc/src/ops/forc_update.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
use crate::{
cli::UpdateCommand,
ops::forc_dep_check,
utils::{
dependency,
helpers::{read_manifest, user_forc_directory},
},
};
use crate::{cli::UpdateCommand, utils::helpers::read_manifest};
use anyhow::{anyhow, Result};
use std::{path::PathBuf, str};
use std::path::PathBuf;
use sway_utils::find_manifest_dir;

/// Forc update will update the contents inside the Forc dependencies directory.
/// If a dependency `d` is passed as parameter, it will only try and update that specific dependency.
/// Otherwise, it will try and update all GitHub-based dependencies in a project's `Forc.toml`.
/// It won't automatically update dependencies that have a version specified, if you have
/// specified a version for a dependency and want to update it you should, instead,
/// run `forc update --check` to check for updates for all GitHub-based dependencies, and if
/// a new version is detected and return, manually update your `Forc.toml` with this new version.
/// Running `forc update` will check for updates for the entire dependency graph and commit new
/// semver-compatible versions to the `Forc.lock` file. For git dependencies, the commit is updated
/// to the HEAD of the specified branch, or remains unchanged in the case a tag is specified. Path
/// dependencies remain unchanged as they are always sourced directly.
///
/// Run `forc update --check` to perform a dry-run and produce a list of updates that will be
/// performed across all dependencies without actually committing them to the lock file.
///
/// Use the `--package <package-name>` flag to update only a specific package throughout the
/// dependency graph.
pub async fn update(command: UpdateCommand) -> Result<()> {
if command.check {
return forc_dep_check::check(command.path, command.target_dependency).await;
// TODO
unimplemented!(
"When set, output whether target dep may be updated but don't commit to lock file"
);
}

let UpdateCommand {
path,
target_dependency,
check: _,
// TODO: Use `package` here rather than `target_dependency`
..
} = command;

let this_dir = if let Some(path) = path {
Expand All @@ -44,58 +44,10 @@ pub async fn update(command: UpdateCommand) -> Result<()> {
}
};

let mut manifest = read_manifest(&manifest_dir).unwrap();
let _manifest = read_manifest(&manifest_dir).unwrap();

let dependencies = dependency::get_detailed_dependencies(&mut manifest);

match target_dependency {
// Target dependency (`-d`) specified
Some(target_dep) => match dependencies.get(&target_dep) {
Some(dep) => Ok(update_dependency(&target_dep, dep).await?),
None => return Err(anyhow!("dependency {} not found", target_dep)),
},
// No target dependency specified, try and update all dependencies
None => {
for (dependency_name, dep) in dependencies {
update_dependency(&dependency_name, dep).await?;
}
Ok(())
}
}
}

async fn update_dependency(
dependency_name: &str,
dep: &dependency::DependencyDetails,
) -> Result<()> {
// Currently we only handle updates on github-based dependencies
if let Some(git) = &dep.git {
match &dep.version {
// Automatically updating a dependency that has a tag/version specified in `Forc.toml`
// would mean to update the `Forc.toml` file, which I believe isn't a very
// nice behavior. Instead, if a tag/version is specified, the user should
// lookup for a desired version and manually specify it in `Forc.toml`.
Some(version) => println!("Ignoring update for {} at version {}: Forc update not implemented for dependencies with specified tag. To update to another tag, change the tag in `Forc.toml` and run the build command.", dependency_name, version),
None => {
let forc_dir = user_forc_directory();
let dep_dir = forc_dir.join(dependency_name);
let target_directory = match &dep.branch {
Some(branch) => dep_dir.join(branch),
None => dep_dir.join("default"),
};

let current = dependency::get_current_dependency_version(&target_directory)?;

let latest_hash = dependency::get_latest_commit_sha(git, &dep.branch).await?;

if current.hash == latest_hash {
println!("{} is up-to-date", dependency_name);
} else {
dependency::replace_dep_version(&target_directory, git, dep)?;
println!("{}: {} -> {}", dependency_name, current.hash, latest_hash);
}
}
}
}
Ok(())
// TODO
unimplemented!(
"Check the graph for git and registry changes and update the `Forc.lock` file accordingly"
)
}
1 change: 0 additions & 1 deletion forc/src/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod forc_abi_json;
pub mod forc_build;
pub mod forc_clean;
pub mod forc_dep_check;
pub mod forc_deploy;
pub mod forc_explorer;
pub mod forc_fmt;
Expand Down
Loading

0 comments on commit da6c3cc

Please sign in to comment.