Skip to content

Commit

Permalink
Pretty hacky way to make LocalRegistry git deps work
Browse files Browse the repository at this point in the history
  • Loading branch information
cormacrelf committed May 23, 2024
1 parent e1d2c53 commit a7b0188
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
50 changes: 16 additions & 34 deletions src/buckify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ fn generate_nonvendored_sources_archive<'scope>(
} => match context.config.vendor {
VendorConfig::Off => generate_git_fetch(repo, commit_hash).map(Some),
VendorConfig::LocalRegistry => {
generate_extract_archive_git(context, pkg, lockfile_package, repo, commit_hash)
.map(Some)
generate_extract_archive(context, pkg, lockfile_package).map(Some)
}
VendorConfig::Source(_) => unreachable!(),
},
Expand Down Expand Up @@ -306,32 +305,6 @@ fn generate_extract_archive<'scope>(
}))
}

fn generate_extract_archive_git<'scope>(
_context: &'scope RuleContext<'scope>,
pkg: &'scope Manifest,
_lockfile_package: &LockfilePackage,
repo: &str,
_commit_hash: &str,
) -> anyhow::Result<Rule> {
let vendordir = "vendor";
let short_name = short_name_for_git_repo(repo)?;
Ok(Rule::ExtractArchive(ExtractArchive {
name: Name(format!("{}.git", short_name)),
//
// Would be nice if cargo local-registry wrote out a git-related name instead
// of `mycrate-0.1.0.crate`. However it does not.
//
src: BuckPath(PathBuf::from(format!(
"{vendordir}/{}-{}.crate",
pkg.name, pkg.version
))),
strip_prefix: format!("{}-{}", pkg.name, pkg.version),
sub_targets: BTreeSet::new(), // populated later after all fixups are constructed
visibility: Visibility::Private,
sort_key: Name(format!("{}-{}", pkg.name, pkg.version)),
}))
}

fn generate_http_archive<'scope>(
context: &'scope RuleContext<'scope>,
pkg: &'scope Manifest,
Expand Down Expand Up @@ -476,13 +449,10 @@ fn generate_target_rules<'scope>(
let mapped_manifest_dir =
if context.config.vendor.is_source() || matches!(pkg.source, Source::Local) {
relative_path(&paths.third_party_dir, manifest_dir)
} else if let VendorConfig::LocalRegistry = context.config.vendor {
PathBuf::from(format!("{}-{}.crate", pkg.name, pkg.version))
} else if let Source::Git { repo, .. } = &pkg.source {
let mut git_fetch = short_name_for_git_repo(repo)?;
if matches!(context.config.vendor, VendorConfig::LocalRegistry) {
// Subtle difference -- git_fetch rules will strip the `.git` off the name
// when used as a dependency. extract_archive will not.
git_fetch += ".git";
}
let git_fetch = short_name_for_git_repo(repo)?;
let repository_root = find_repository_root(manifest_dir)?;
let path_within_repo = relative_path(repository_root, manifest_dir);
PathBuf::from(git_fetch).join(path_within_repo)
Expand Down Expand Up @@ -581,6 +551,10 @@ fn generate_target_rules<'scope>(
fixups.compute_srcs(srcs)?,
)
.context("srcs")?;
} else if let VendorConfig::LocalRegistry = config.vendor {
let http_archive_target = format!(":{}-{}.crate", pkg.name, pkg.version);
base.srcs
.insert(BuckPath(PathBuf::from(http_archive_target)));
} else if let Source::Git { repo, .. } = &pkg.source {
let short_name = short_name_for_git_repo(repo)?;
let git_fetch_target = format!(":{}.git", short_name);
Expand Down Expand Up @@ -949,6 +923,14 @@ fn generate_target_rules<'scope>(
globs.check_all_globs_used()?;
}
srcs
} else if let VendorConfig::LocalRegistry = config.vendor {
// e.g. {":foo-1.0.0.git": "foo-1.0.0"}
let http_archive_target = format!(":{}-{}.crate", pkg.name, pkg.version);
[(
BuckPath(mapped_manifest_dir.clone()),
SubtargetOrPath::Path(BuckPath(PathBuf::from(http_archive_target))),
)]
.into()
} else if let Source::Git { repo, .. } = &pkg.source {
// e.g. {":foo-123.git": "foo-123"}
let short_name = short_name_for_git_repo(repo)?;
Expand Down
6 changes: 6 additions & 0 deletions src/fixups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::cargo::NodeDepKind;
use crate::cargo::Source;
use crate::collection::SetOrMap;
use crate::config::Config;
use crate::config::VendorConfig;
use crate::glob::Globs;
use crate::glob::SerializableGlobSet as GlobSet;
use crate::glob::NO_EXCLUDE;
Expand Down Expand Up @@ -882,6 +883,11 @@ impl<'meta> Fixups<'meta> {
&self.third_party_dir,
self.manifest_dir,
)))
} else if let VendorConfig::LocalRegistry = self.config.vendor {
StringOrPath::String(format!(
"{}-{}.crate",
self.package.name, self.package.version,
))
} else if let Source::Git { repo, .. } = &self.package.source {
let short_name = short_name_for_git_repo(repo)?;
StringOrPath::String(short_name.to_owned())
Expand Down

0 comments on commit a7b0188

Please sign in to comment.