-
Notifications
You must be signed in to change notification settings - Fork 140
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
Added Scarb workspaces for Cast #1093
Conversation
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.
overall the logic looks good 👍
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 generally don't understand --package
filter from the perspective of cast. What purpose does it serve exactly?
crates/cast/src/main.rs
Outdated
which::which("scarb") | ||
.context("Cannot find `scarb` binary in PATH. Make sure you have Scarb installed https://github.com/software-mansion/scarb")?; |
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.
@piotmag769 what was the reason we require it for all comands in forge?
crates/cast/src/main.rs
Outdated
pub package: Result<PackageMetadata>, | ||
} | ||
|
||
// Lazily get all the required package information from CLI |
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 don't understand the argument. What is the difference between calling different functions from different places instead of unpacking the errors in those places. It only adds complexity (we have to pass PackageData around) and is heavily not idiomatic. Please change that.
crates/cast/src/main.rs
Outdated
}; | ||
|
||
// Check if the path is actually valid | ||
result.manifest_path = match path { |
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.
Please unpack path with ?
in the part above.
crates/cast/src/main.rs
Outdated
// Check if the path is actually valid | ||
result.manifest_path = match path { | ||
Ok(path) => { | ||
if path.exists() { |
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.
Please move this part to a separate function.
crates/cast/src/helpers/build.rs
Outdated
use super::constants::LIB_CONTRACT_ARTIFACTS_NAME; | ||
|
||
#[allow(clippy::too_many_lines)] | ||
pub fn build( |
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.
It is good practice to have small functions doing only one thing. Current interface makes it not obvious that scarb writes to the memory. Declare shouldn't load scripts.
crates/cast/src/main.rs
Outdated
.context("Cannot find `scarb` binary in PATH. Make sure you have Scarb installed https://github.com/software-mansion/scarb")?; | ||
|
||
let package_data = get_package_data(&cli); | ||
let mut config = match &package_data.package { |
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.
let mut config = match &package_data.package { | |
let mut cast_config = match &package_data.package_metadata { |
crates/cast/src/main.rs
Outdated
@@ -27,13 +33,16 @@ mod starknet_commands; | |||
#[allow(clippy::struct_excessive_bools)] | |||
struct Cli { | |||
/// Profile name in Scarb.toml config file | |||
#[clap(short, long)] | |||
#[clap(short = 'p', long)] |
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.
Not related change, please revert it
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.
Is it? I think it is to override the -p
option as a short option for --package
(not sure how clap handles 2 flags with the same short form)
crates/cast/src/main.rs
Outdated
profile: Option<String>, | ||
|
||
/// Path to Scarb.toml that is to be used; overrides default behaviour of searching for scarb.toml in current or parent directories | ||
/// Path to Scarb.toml that is to be used; overrides default behaviour of searching for Scarb.toml in current or parent directories |
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.
Not related change, please revert it
docs/src/appendix/cast/common.md
Outdated
|
||
## `--package` |
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.
What is the purpose of this flag? How it behaves when I call a script, How it behaves when i call declare.
@@ -226,6 +226,23 @@ pub fn duplicate_directory_with_salt(src_path: String, to_be_salted: &str, salt: | |||
temp_dir | |||
} | |||
|
|||
#[must_use] | |||
pub fn duplicate_directory(src_path: String) -> TempDir { |
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.
probably copy_directory_to_tempdir?
Also we probably shouldn't take the first match, we should throw an error when it is ambigous |
We discussed it with @THenry14 , filter mechanism does not make much sense in the context of scripts. If only
Passing |
@MaksymilianDemitraszek Also what config from Scarb.toml takes priority when both |
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.
.join(&metadata.current_profile) | ||
.join(sierra_filename); | ||
|
||
let lib_artifacts = StarknetContractArtifacts { |
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.
Storing it together with StarknetContractArtifacts
is kinda a hack, should be stored in a separate struct prob
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.
maybe introduce a type alias?
@@ -276,23 +259,40 @@ pub fn get_package_tool_sncast(metadata: &scarb_metadata::Metadata) -> Result<&V | |||
Ok(tool_sncast) | |||
} | |||
|
|||
pub fn get_first_package_from_metadata(metadata: &Metadata) -> Result<PackageMetadata> { |
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.
It terrifies me (I know this logic has been there before) xD Is it only used in tests? If so can we move it to the tests mod?
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.
It's used in tests in multiple modules
<!-- Reference any GitHub issues resolved by this PR --> ## Introduced changes <!-- A brief description of the changes --> - Opens up a discussion about sncast declare/script interfaces, first raised under this PR #1093 ## Checklist <!-- Make sure all of these are complete --> - [X] Linked relevant issue - [X] Updated relevant documentation - [X] Added relevant tests - [X] Performed self-review of the code - [X] Added changes to `CHANGELOG.md`
Introduced changes
Checklist
CHANGELOG.md