Skip to content

Commit

Permalink
metadata -> library_packages, metadata_cargo -> cargo_lib, `m…
Browse files Browse the repository at this point in the history
…etadata_cli` -> `cargo_cli`
  • Loading branch information
smoelius committed Feb 8, 2024
1 parent fef8dce commit 42cb7a2
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
fi
if [[ '${{ matrix.package }}' != 'other' ]]; then
if [[ '${{ matrix.package }}' == 'cargo-dylint-cli' ]]; then
cargo test -p cargo-dylint --no-default-features --features=metadata-cli -- --nocapture
cargo test -p cargo-dylint --no-default-features --features=cargo-cli -- --nocapture
else
cargo test -p '${{ matrix.package }}' --all-features -- --nocapture
fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**News:** Dylint has a new, experimental method for downloading packages. Please consider trying it by installing `cargo-dylint` with the following command:

```sh
cargo install cargo-dylint --no-default-features --features=metadata-cli
cargo install cargo-dylint --no-default-features --features=cargo-cli
```

The new method requires fewer dependencies, which will make Dylint easier to maintain. Plus, it should install faster.
Expand Down
6 changes: 3 additions & 3 deletions cargo-dylint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ dylint_internal = { version = "=2.6.1", path = "../internal", features = [
] }

[features]
default = ["metadata-cargo"]
metadata-cargo = ["dylint/__metadata_cargo"]
metadata-cli = ["dylint/__metadata_cli"]
default = ["cargo-lib"]
cargo-lib = ["dylint/__cargo_lib"]
cargo-cli = ["dylint/__cargo_cli"]
2 changes: 1 addition & 1 deletion cargo-dylint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**News:** Dylint has a new, experimental method for downloading packages. Please consider trying it by installing `cargo-dylint` with the following command:

```sh
cargo install cargo-dylint --no-default-features --features=metadata-cli
cargo install cargo-dylint --no-default-features --features=cargo-cli
```

The new method requires fewer dependencies, which will make Dylint easier to maintain. Plus, it should install faster.
Expand Down
10 changes: 5 additions & 5 deletions cargo-dylint/tests/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ fn supply_chain() {
for target in TARGETS {
let mut command = Command::new("cargo");
command.args(["supply-chain", "json", "--no-dev", "--target", target]);
let subdir = if cfg!(feature = "metadata-cargo") {
"cargo"
let subdir = if cfg!(feature = "cargo-lib") {
"cargo_lib"
} else {
assert!(cfg!(feature = "metadata-cli"));
command.args(["--no-default-features", "--features=metadata-cli"]);
"cli"
assert!(cfg!(feature = "cargo-cli"));
command.args(["--no-default-features", "--features=cargo-cli"]);
"cargo_cli"
};
let assert = command.assert().success();

Expand Down
6 changes: 3 additions & 3 deletions dylint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ dylint_internal = { version = "=2.6.1", path = "../internal", features = [

[features]
default = []
metadata = ["__metadata_cargo"]
library_packages = ["__cargo_lib"]
package_options = [
"heck",
"if_chain",
"dylint_internal/clippy_utils",
"dylint_internal/git",
]
__metadata_cargo = [
__cargo_lib = [
"cargo",
"cargo-platform",
"cargo-util",
Expand All @@ -79,7 +79,7 @@ __metadata_cargo = [
"serde-untagged",
"toml",
]
__metadata_cli = [
__cargo_cli = [
"cargo-util",
"fs_extra",
"glob",
Expand Down
2 changes: 1 addition & 1 deletion dylint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**News:** Dylint has a new, experimental method for downloading packages. Please consider trying it by installing `cargo-dylint` with the following command:

```sh
cargo install cargo-dylint --no-default-features --features=metadata-cli
cargo install cargo-dylint --no-default-features --features=cargo-cli
```

The new method requires fewer dependencies, which will make Dylint easier to maintain. Plus, it should install faster.
Expand Down
8 changes: 4 additions & 4 deletions dylint/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use std::{fs::OpenOptions, io::Write, path::Path};
fn main() {
write_dylint_driver_manifest_dir();

#[cfg(all(feature = "__metadata_cargo", feature = "__metadata_cli"))]
#[cfg(all(feature = "__cargo_lib", feature = "__cargo_cli"))]
{
println!("cargo:warning=Both `__metadata_cargo` and `__metadata_cli` are enabled.");
println!("cargo:warning=Both `__cargo_lib` and `__cargo_cli` are enabled.");
println!("cargo:warning=Perhaps you forgot to build with `--no-default-features`?");
}

#[cfg(any(feature = "__metadata_cargo", feature = "__metadata_cli"))]
println!("cargo:rustc-cfg=__metadata");
#[cfg(any(feature = "__cargo_lib", feature = "__cargo_cli"))]
println!("cargo:rustc-cfg=__library_packages");

println!("cargo:rerun-if-changed=build.rs");
}
Expand Down
12 changes: 6 additions & 6 deletions dylint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
type Object = serde_json::Map<String, serde_json::Value>;

// smoelius: See note in dylint/src/metadata/mod.rs.
#[cfg(all(feature = "__metadata_cargo", not(feature = "__metadata_cli")))]
#[cfg(all(feature = "__cargo_lib", not(feature = "__cargo_cli")))]
pub(crate) use cargo::{core, sources, util};

pub mod driver_builder;
Expand All @@ -37,8 +37,8 @@ mod name_toolchain_map;
pub use name_toolchain_map::{Lazy as NameToolchainMap, ToolchainMap};
use name_toolchain_map::{LazyToolchainMap, MaybeLibrary};

#[cfg(__metadata)]
pub(crate) mod metadata;
#[cfg(__library_packages)]
pub(crate) mod library_packages;

#[cfg(feature = "package_options")]
mod package_options;
Expand Down Expand Up @@ -511,10 +511,10 @@ fn check_or_fix(opts: &Dylint, resolved: &ToolchainMap) -> Result<()> {
let target_dir_str = target_dir.to_string_lossy();
let driver = driver_builder::get(opts, toolchain)?;
let dylint_libs = serde_json::to_string(&paths)?;
#[cfg(not(__metadata))]
#[cfg(not(__library_packages))]
let dylint_metadata = None;
#[cfg(__metadata)]
let dylint_metadata = metadata::dylint_metadata(opts)?;
#[cfg(__library_packages)]
let dylint_metadata = library_packages::dylint_metadata(opts)?;
let dylint_metadata_str = dylint_metadata
.map(|object: &Object| serde_json::Value::from(object.clone()))
.unwrap_or_default()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions dylint/src/metadata/mod.rs → dylint/src/library_packages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use std::{
path::{Path, PathBuf},
};

// smoelius: If both `__metadata_cargo` and `__metadata_cli` are enabled, assume the user built with
// `--features=metadata-cli` and forgot `--no-default-features`.
#[cfg(all(feature = "__metadata_cargo", not(feature = "__metadata_cli")))]
#[path = "cargo/mod.rs"]
// smoelius: If both `__cargo_lib` and `__cargo_cli` are enabled, assume the user built with
// `--features=cargo-cli` and forgot `--no-default-features`.
#[cfg(all(feature = "__cargo_lib", not(feature = "__cargo_cli")))]
#[path = "cargo_lib/mod.rs"]
mod impl_;

#[cfg(feature = "__metadata_cli")]
#[path = "cli/mod.rs"]
#[cfg(feature = "__cargo_cli")]
#[path = "cargo_cli/mod.rs"]
mod impl_;

use impl_::{dependency_source_id_and_root, Config, DetailedTomlDependency, PackageId, SourceId};
Expand Down Expand Up @@ -83,7 +83,7 @@ struct Library {
details: DetailedTomlDependency,
}

pub fn opts_library_packages(opts: &crate::Dylint) -> Result<Vec<Package>> {
pub fn from_opts(opts: &crate::Dylint) -> Result<Vec<Package>> {
let maybe_metadata = cargo_metadata(opts)?;

let metadata = maybe_metadata.ok_or_else(|| anyhow!("Could not read cargo metadata"))?;
Expand Down Expand Up @@ -128,12 +128,12 @@ fn to_map_entry(key: &str, value: Option<&String>) -> Option<(String, toml::Valu
.map(|s| (String::from(key), toml::Value::from(s)))
}

pub fn workspace_metadata_packages(opts: &crate::Dylint) -> Result<Vec<Package>> {
pub fn from_workspace_metadata(opts: &crate::Dylint) -> Result<Vec<Package>> {
if_chain! {
if let Some(metadata) = cargo_metadata(opts)?;
if let Some(object) = dylint_metadata(opts)?;
then {
dylint_metadata_packages(opts, metadata, object)
library_packages_from_dylint_metadata(opts, metadata, object)
} else {
Ok(vec![])
}
Expand Down Expand Up @@ -195,7 +195,7 @@ fn cargo_metadata(opts: &crate::Dylint) -> Result<Option<&'static Metadata>> {
.map(Option::as_ref)
}

fn dylint_metadata_packages(
fn library_packages_from_dylint_metadata(
opts: &crate::Dylint,
metadata: &'static Metadata,
object: &Object,
Expand Down Expand Up @@ -303,7 +303,7 @@ fn library_package(
let Ok(package) = package_with_root(&path) else {
return Ok(None);
};
// smoelius: When `__metadata_cli` is enabled, `source_id`'s type is `String`.
// smoelius: When `__cargo_cli` is enabled, `source_id`'s type is `String`.
#[allow(clippy::clone_on_copy)]
let package_id = package_id(&package, source_id.clone())?;
let lib_name = package_library_name(&package)?;
Expand Down
18 changes: 9 additions & 9 deletions dylint/src/name_toolchain_map/maybe_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ impl From<PathBuf> for MaybeLibrary {
}
}

#[cfg(__metadata)]
impl From<crate::metadata::Package> for MaybeLibrary {
fn from(package: crate::metadata::Package) -> Self {
#[cfg(__library_packages)]
impl From<crate::library_packages::Package> for MaybeLibrary {
fn from(package: crate::library_packages::Package) -> Self {
Self {
inner: Inner::Package(package),
}
Expand All @@ -37,27 +37,27 @@ impl From<crate::metadata::Package> for MaybeLibrary {
pub enum Inner {
Path(PathBuf),

#[cfg(__metadata)]
Package(crate::metadata::Package),
#[cfg(__library_packages)]
Package(crate::library_packages::Package),
}

impl Inner {
pub fn path(&self) -> PathBuf {
match self {
Self::Path(path) => path.clone(),

#[cfg(__metadata)]
#[cfg(__library_packages)]
Self::Package(package) => package.path(),
}
}

#[cfg_attr(not(__metadata), allow(unused_variables))]
#[cfg_attr(not(__library_packages), allow(unused_variables))]
fn build(&self, opts: &crate::Dylint) -> Result<PathBuf> {
match self {
Self::Path(path) => Ok(path.clone()),

#[cfg(__metadata)]
Self::Package(package) => crate::metadata::build_library(opts, package),
#[cfg(__library_packages)]
Self::Package(package) => crate::library_packages::build_library(opts, package),
}
}
}
8 changes: 4 additions & 4 deletions dylint/src/name_toolchain_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) type NameToolchainMap = BTreeMap<String, LazyToolchainMap>;
#[allow(clippy::redundant_pub_crate)]
pub(crate) type LazyToolchainMap = BTreeMap<String, BTreeSet<MaybeLibrary>>;

#[cfg_attr(not(__metadata), allow(dead_code))]
#[cfg_attr(not(__library_packages), allow(dead_code))]
struct Inner<'opts> {
opts: &'opts crate::Dylint,
name_toolchain_map: OnceCell<NameToolchainMap>,
Expand All @@ -46,12 +46,12 @@ impl<'opts> Lazy<'opts> {
.get_or_try_init(|| -> Result<_> {
let mut name_toolchain_map = NameToolchainMap::new();

#[cfg(__metadata)]
#[cfg(__library_packages)]
{
let library_packages = if self.inner.opts.git_or_path() {
crate::metadata::opts_library_packages(self.inner.opts)?
crate::library_packages::from_opts(self.inner.opts)?
} else {
crate::metadata::workspace_metadata_packages(self.inner.opts)?
crate::library_packages::from_workspace_metadata(self.inner.opts)?
};

for package in library_packages {
Expand Down

0 comments on commit 42cb7a2

Please sign in to comment.