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

Allow specifying the subxt crate path for generated code #664

Merged
merged 12 commits into from
Sep 27, 2022

Conversation

cmichi
Copy link
Contributor

@cmichi cmichi commented Sep 22, 2022

Closes #655.

We need this in ink! for use-ink/ink#1234.

I'm not particularly fond of the testing story for this feature, but I would also not duplicate all the existing tests. Hmm.

@cmichi cmichi force-pushed the cmichi-allow-specifying-crate-path branch from 11c59c3 to 7e890a3 Compare September 22, 2022 17:06
@@ -41,6 +42,7 @@ pub struct CompositeDef {

impl CompositeDef {
/// Construct a definition which will generate code for a standalone `struct`.
#[allow(clippy::too_many_arguments)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly create a follow-up ticket to refactor with a config struct instead of the params.

@jsdw
Copy link
Collaborator

jsdw commented Sep 22, 2022

I haven't looked properly at the test you've added yet. One quicker thing you could do is to do all of the codegen with a custom path and check that the string "subxt" doesn't appear at all in it. Otherwise I wonder about tweaking the subxt crate import in the tests to be a custom path; at least if using acustom path is the default thing in the tests it'll get fairly well covered!

codegen/src/api/calls.rs Outdated Show resolved Hide resolved
codegen/src/api/mod.rs Outdated Show resolved Hide resolved
codegen/src/api/mod.rs Outdated Show resolved Hide resolved
codegen/src/lib.rs Outdated Show resolved Hide resolved
codegen/src/types/composite_def.rs Outdated Show resolved Hide resolved
codegen/src/types/mod.rs Outdated Show resolved Hide resolved
codegen/src/types/mod.rs Outdated Show resolved Hide resolved
codegen/src/types/tests.rs Outdated Show resolved Hide resolved
codegen/src/types/mod.rs Outdated Show resolved Hide resolved

pub fn default_with_crate_path(crate_path: &CratePath) -> Self {
Self {
default_derives: Derives::default_with_crate_path(crate_path),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about removing the Default impls because we never want to be able to forget to provide a crate path?

This could then just be new or new_with_crate_path

Comment on lines 107 to 111
impl Default for Derives {
fn default() -> Self {
Derives::default_with_crate_path(&CratePath::default())
}
}
Copy link
Collaborator

@jsdw jsdw Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this exist? I think we should make sure crate path is always explicitly provided so we are forced to pass it through always (and thus can't accidentally forget).

Copy link
Contributor Author

@cmichi cmichi Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to be on the same page: would this go through to the user-facing side? I.e. would each user always be required to specify ::subxt as the crate path to use?

@jsdw
Copy link
Collaborator

jsdw commented Sep 26, 2022

Looks great overall!

I am happy with the tests (defaulting to checking that a custom path works everywhere I think is good enough for now and will almost certainly catch any issues there).

Just a couple of wee comments; I think we should remove Default impls for things that rely on a crate path wherever possible just to make it hard for future us to miss threading the crate path through somewhere it's needed.

@cmichi
Copy link
Contributor Author

cmichi commented Sep 27, 2022

@jsdw @ascjones All comments have been implemented.

Copy link
Contributor

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

codegen/src/types/mod.rs Outdated Show resolved Hide resolved
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thankyou @cmichi!

@jsdw jsdw merged commit f115ff9 into master Sep 27, 2022
@jsdw jsdw deleted the cmichi-allow-specifying-crate-path branch September 27, 2022 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce path prefix for generated ::subxt code
3 participants