Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize when the current package has no lib target #209

Merged
merged 2 commits into from Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/cargo.rs
Expand Up @@ -12,12 +12,19 @@ use std::{env, fs, iter};
pub struct Metadata {
pub target_directory: Directory,
pub workspace_root: Directory,
pub packages: Vec<Package>,
pub packages: Vec<PackageMetadata>,
}

#[derive(Deserialize)]
pub struct Package {
pub struct PackageMetadata {
pub name: String,
pub targets: Vec<BuildTarget>,
pub manifest_path: PathBuf,
}

#[derive(Deserialize)]
pub struct BuildTarget {
pub crate_types: Vec<String>,
}

fn raw_cargo() -> Command {
Expand Down
53 changes: 35 additions & 18 deletions src/run.rs
@@ -1,4 +1,4 @@
use crate::cargo::{self, Metadata};
use crate::cargo::{self, Metadata, PackageMetadata};
use crate::dependencies::{self, Dependency, EditionOrInherit};
use crate::directory::Directory;
use crate::env::Update;
Expand Down Expand Up @@ -155,6 +155,7 @@ impl Runner {
&workspace,
&project_name,
&source_dir,
&packages,
tests,
source_manifest,
)?;
Expand Down Expand Up @@ -205,6 +206,7 @@ impl Runner {
workspace: &Directory,
project_name: &str,
source_dir: &Directory,
packages: &[PackageMetadata],
tests: &[ExpandedTest],
source_manifest: dependencies::Manifest,
) -> Result<Manifest> {
Expand All @@ -223,22 +225,35 @@ impl Runner {
let mut dependencies = Map::new();
dependencies.extend(source_manifest.dependencies);
dependencies.extend(source_manifest.dev_dependencies);
dependencies.insert(
crate_name.clone(),
Dependency {
version: None,
path: Some(source_dir.clone()),
optional: false,
default_features: false,
features: Vec::new(),
git: None,
branch: None,
tag: None,
rev: None,
workspace: false,
rest: Map::new(),
},
);

let cargo_toml_path = source_dir.join("Cargo.toml");
let mut has_lib_target = true;
for package_metadata in packages {
if package_metadata.manifest_path == cargo_toml_path {
has_lib_target = package_metadata
.targets
.iter()
.any(|target| target.crate_types != ["bin"]);
}
}
if has_lib_target {
dependencies.insert(
crate_name.clone(),
Dependency {
version: None,
path: Some(source_dir.clone()),
optional: false,
default_features: false,
features: Vec::new(),
git: None,
branch: None,
tag: None,
rev: None,
workspace: false,
rest: Map::new(),
},
);
}

let mut targets = source_manifest.target;
for target in targets.values_mut() {
Expand All @@ -265,7 +280,9 @@ impl Runner {
}
false
});
enables.insert(0, format!("{}/{}", crate_name, feature));
if has_lib_target {
enables.insert(0, format!("{}/{}", crate_name, feature));
}
}

let mut manifest = Manifest {
Expand Down