-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: remove features when removing dependencies #113
base: main
Are you sure you want to change the base?
Changes from all commits
5affaaa
a311af2
86a1283
17155ba
43dc72c
5c232a6
57fc31f
6c37640
f401094
58ab1de
b2549ca
3cc1675
2df4a58
f3d4814
f068d72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "just-unused" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
log = "0.4.14" | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["log/std", "other"] | ||
other = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "just-unused" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
log = "0.4.14" | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["log/std", "other"] | ||
dontlog = [] | ||
log = [] | ||
other = ["log", "dontlog"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "just-unused" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
log = "0.4.14" | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["log/std", "log"] | ||
log = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "just-unused" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ "other"] | ||
other = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "just-unused" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
log = "0.4.14" | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["log/std", "other"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and |
||
dontlog = [] | ||
log = [] | ||
other = ["log", "dontlog"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "just-unused" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
log = "0.4.14" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and same in this file |
||
|
||
[features] | ||
default = ["std"] | ||
std = ["log/std", "log"] | ||
log = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,29 @@ fn remove_dependencies(manifest: &str, dependencies_list: &[String]) -> anyhow:: | |
.with_context(|| format!("Dependency {k} not found"))?; | ||
} | ||
|
||
let features = manifest | ||
.iter_mut() | ||
.find_map(|(k, v)| (v.is_table_like() && k == "features").then_some(Some(v))) | ||
.flatten() | ||
.and_then(|v| v.as_table_mut()); | ||
|
||
if let Some(features) = features { | ||
for (_, deps) in features.iter_mut() { | ||
if let Some(deps) = deps.as_array_mut() { | ||
deps.retain(|dep| { | ||
if let Some(dep) = dep.as_str() { | ||
!dependencies_list.iter().any(|d| { | ||
let prefix = d.to_string() + "/"; | ||
dep.contains(&prefix) | ||
}) | ||
Comment on lines
+283
to
+286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, scanning https://doc.rust-lang.org/cargo/reference/features.html, I think the whole set of rules is the following:
It would be super sweet to address those four cases completely, or someone could do this as a followup. Do you have a preference? |
||
} else { | ||
true | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
let serialized = manifest.to_string(); | ||
Ok(serialized) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
log
should be removed in thisexpected
test result, since it's unused in the src directory?