Skip to content

Commit

Permalink
Remove implied pkg from idents in pkg submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchmindtree committed Feb 22, 2022
1 parent 2c90777 commit 13f2cf4
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions forc/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ fn fetch_children(
};
for (name, dep) in deps {
let name = name.clone();
let source = dep_to_pkg_source(dep)?;
let source = dep_to_source(dep)?;
if offline_mode && !matches!(source, Source::Path(_)) {
return Err(format!("Unable to fetch pkg {:?} in offline mode", source));
}
let pkg = Pkg { name, source };
let pinned = pin_pkg(&pkg)?;
let dep_node = if let Entry::Vacant(entry) = visited.entry(pinned.clone()) {
let fetched = fetch_pkg_pinned(pinned)?;
let fetched = fetch_pinned(pinned)?;
let node = graph.add_node(fetched);
entry.insert(node);
fetch_children(offline_mode, node, graph, visited)?;
Expand All @@ -200,7 +200,7 @@ fn fetch_children(
}

/// The name to use for a package's git repository under the user's forc directory.
fn pkg_git_repo_dir_name(name: &str, repo: &Url) -> String {
fn git_repo_dir_name(name: &str, repo: &Url) -> String {
let repo_url_hash = hash_url(repo);
format!("{}-{:x}", name, repo_url_hash)
}
Expand All @@ -221,12 +221,12 @@ fn hash_url(url: &Url) -> u64 {
/// $HOME/.forc/git/checkouts/tmp/name-<repo_url_hash>
/// ```
fn tmp_git_repo_dir(name: &str, repo: &Url) -> PathBuf {
let repo_dir_name = pkg_git_repo_dir_name(name, repo);
let repo_dir_name = git_repo_dir_name(name, repo);
git_checkouts_directory().join("tmp").join(repo_dir_name)
}

/// Clones the package git repo into a temporary directory and applies the given function.
fn with_pkg_tmp_git_repo<F, O>(name: &str, source: &SourceGit, f: F) -> Result<O, String>
fn with_tmp_git_repo<F, O>(name: &str, source: &SourceGit, f: F) -> Result<O, String>
where
F: FnOnce(git2::Repository) -> Result<O, String>,
{
Expand Down Expand Up @@ -260,8 +260,8 @@ where
///
/// This clones the repository to a temporary directory in order to determine the commit at the
/// HEAD of the given git reference.
fn pin_pkg_git(name: &str, source: SourceGit) -> Result<SourceGitPinned, String> {
let commit_hash = with_pkg_tmp_git_repo(name, &source, |repo| {
fn pin_git(name: &str, source: SourceGit) -> Result<SourceGitPinned, String> {
let commit_hash = with_tmp_git_repo(name, &source, |repo| {
// Find specified reference in repo.
let reference = repo
.resolve_reference_from_short_name(&source.reference)
Expand Down Expand Up @@ -292,7 +292,7 @@ fn pin_pkg(pkg: &Pkg) -> Result<Pinned, String> {
let source = match &pkg.source {
Source::Path(path) => SourcePinned::Path(path.clone()),
Source::Git(ref source) => {
let pinned = pin_pkg_git(&pkg.name, source.clone())?;
let pinned = pin_git(&pkg.name, source.clone())?;
SourcePinned::Git(pinned)
}
Source::Registry(ref _source) => {
Expand All @@ -313,8 +313,8 @@ fn pin_pkg(pkg: &Pkg) -> Result<Pinned, String> {
/// ```
///
/// where `<repo_url_hash>` is a hash of the source repository URL.
fn pkg_git_commit_path(name: &str, repo: &Url, commit_hash: &str) -> PathBuf {
let repo_dir_name = pkg_git_repo_dir_name(name, repo);
fn git_commit_path(name: &str, repo: &Url, commit_hash: &str) -> PathBuf {
let repo_dir_name = git_repo_dir_name(name, repo);
git_checkouts_directory()
.join(repo_dir_name)
.join(commit_hash)
Expand All @@ -323,11 +323,11 @@ fn pkg_git_commit_path(name: &str, repo: &Url, commit_hash: &str) -> PathBuf {
/// Fetch the repo at the given git package's URL and checkout the pinned commit.
///
/// Returns the location of the checked out commit.
fn fetch_pkg_git(name: &str, pinned: &SourceGitPinned) -> Result<PathBuf, String> {
let path = pkg_git_commit_path(name, &pinned.source.repo, &pinned.commit_hash);
fn fetch_git(name: &str, pinned: &SourceGitPinned) -> Result<PathBuf, String> {
let path = git_commit_path(name, &pinned.source.repo, &pinned.commit_hash);

// Checkout the pinned hash to the path.
with_pkg_tmp_git_repo(name, &pinned.source, |repo| {
with_tmp_git_repo(name, &pinned.source, |repo| {
// Change HEAD to point to the pinned commit.
let id = git2::Oid::from_str(&pinned.commit_hash)
.map_err(|e| format!("failed to parse obj ID from commit hash: {}", e))?;
Expand Down Expand Up @@ -355,9 +355,9 @@ fn fetch_pkg_git(name: &str, pinned: &SourceGitPinned) -> Result<PathBuf, String
}

/// Given a package's pinned source ensure we have a copy of the source on the local filesystem.
fn fetch_pkg_pinned(pkg: Pinned) -> Result<PinnedFetched, String> {
fn fetch_pinned(pkg: Pinned) -> Result<PinnedFetched, String> {
let path = match &pkg.source {
SourcePinned::Git(pinned) => fetch_pkg_git(&pkg.name, pinned)?,
SourcePinned::Git(pinned) => fetch_git(&pkg.name, pinned)?,
SourcePinned::Path(path) => path.clone(),
SourcePinned::Registry(_pinned) => {
unimplemented!("fetch pinned package from registry");
Expand All @@ -367,7 +367,7 @@ fn fetch_pkg_pinned(pkg: Pinned) -> Result<PinnedFetched, String> {
Ok(fetched)
}

fn dep_to_pkg_source(dep: &Dependency) -> Result<Source, String> {
fn dep_to_source(dep: &Dependency) -> Result<Source, String> {
let source = match dep {
Dependency::Simple(ref _ver_str) => unimplemented!(),
Dependency::Detailed(ref det) => match (&det.path, &det.version, &det.git, &det.branch) {
Expand All @@ -393,16 +393,16 @@ fn dep_to_pkg_source(dep: &Dependency) -> Result<Source, String> {
}

pub(crate) fn build_config(
pkg_path: PathBuf,
path: PathBuf,
manifest: &Manifest,
build_conf: &BuildConf,
) -> Result<BuildConfig, String> {
// Prepare the build config to pass through to the compiler.
let main_path = find_main_path(&pkg_path, manifest);
let file_name = find_file_name(&pkg_path, &main_path)?;
let main_path = find_main_path(&path, manifest);
let file_name = find_file_name(&path, &main_path)?;
let build_config = BuildConfig::root_from_file_name_and_manifest_path(
file_name.to_path_buf(),
pkg_path.to_path_buf(),
path.to_path_buf(),
)
.use_ir(build_conf.use_ir || build_conf.print_ir) // --print-ir implies --use-ir.
.print_finalized_asm(build_conf.print_finalized_asm)
Expand Down

0 comments on commit 13f2cf4

Please sign in to comment.