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

Refactor how path structs are split. #719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Refactor how path structs are split. #719

wants to merge 1 commit into from

Conversation

robshakir
Copy link
Contributor

* (M) ypathgen/pathgen.go
 * (M) ypathgen/pathgen_test.go
   - Change splits to include N structs per file based on iterating
     through them rather than precalculating.
   - Avoid creating files that are just the package header.
 * (A) ypathgen/testdata/splitstructs/*
   - Add new test case files.
   - Remove files that contained only the header.

 * (M) ypathgen/pathgen.go
 * (M) ypathgen/pathgen_test.go
   - Change splits to include N structs per file based on iterating
     through them rather than precalculating.
   - Avoid creating files that are just the package header.
 * (A) ypathgen/testdata/splitstructs/*
   - Add new test case files.
   - Remove files that contained only the header.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.002%) to 90.489% when pulling d33236c on splitn into f9326f6 on master.

Copy link
Collaborator

@wenovus wenovus left a comment

Choose a reason for hiding this comment

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

So the code looks good to me, though I am wondering if we should continue to generate the empty files in order to match whatever number of files the user specified? The reason being for build systems like bazel AFAIK there isn't an easy way to deal with an unknown number of generated files, and if you specify a file that isn't generated the build system will complain. Empty files seem to be mostly harmless to me, so I think the benefits of keeping them outweigh the negatives. What do you think?

Comment on lines +406 to +412
if i != 0 && i%structsPerFile == 0 {
fileContent = append(fileContent, structs)
structs = []string{}
}
structs = append(structs, gotStruct.String())
}
for i := 0; i != emptyFiles; i++ {
files = append(files, genCode.CommonHeader)
fileContent = append(fileContent, structs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

(optional): Move line 410 to just before line 406, change if condition to if i != 0 && (i%structsPerFile == 0 || i == structN-1) {, and you can remove the corner case after the for loop (delete line 412)

@wenovus
Copy link
Collaborator

wenovus commented Aug 5, 2022

FYI https://github.com/openconfig/ygnmi/tree/main/pathgen is the future place for ypathgen and pathgen.go here will eventually be deleted. I will upstream this change after merge.

@robshakir
Copy link
Contributor Author

Good point about generating the empty files -- it's a bit messy from the perspective of non-bazel users to have a bunch of files sitting around, should we consider having a flag as to whether to write those?

w.r.t where this code should live, I can create the PR in the upstream if you'd prefer? At what point will there stop being a fork?

@wenovus
Copy link
Collaborator

wenovus commented Aug 8, 2022

Good point about generating the empty files -- it's a bit messy from the perspective of non-bazel users to have a bunch of files sitting around, should we consider having a flag as to whether to write those?

w.r.t where this code should live, I can create the PR in the upstream if you'd prefer? At what point will there stop being a fork?

Personally I think it's ok to just have them lying around, since I suspect people will grep or use their code editors to navigate through these files instead of opening them up one-by-one. I also consider having less structs than the number of files to split them to be a corner case, which is why I think a flag is not necessarily worth the maintenance effort.

The upstream is at openconfig/ygnmi, I think the code changes should be similar since this part of the code is copied. Whenever ygnmi is ready to be widely used (gated mostly on generics stability and various tooling support) then I think that is an appropriate time we can remove ypathgen here.

@wenovus
Copy link
Collaborator

wenovus commented Aug 8, 2022

Generics isn't actually being used in ygnmi's path struct generation package, so I think we can remove ypathgen now. Filed #720

Just verified that we can actually have circular imports between repositories, it's only a circular package import that's disallowed. So when we're remove ypathgen, we can keep the path generation in generator.go if we want, and simply use ygnmi's pathgen code for generation. Alternatively we remove it altogether.

@robshakir I'd actually prefer removing ypathgen's package and code generation altogether from ygot because I don't like seeing two different places where path structs are being generated, and ygot would have to continually get the latest version of ygnmi to keep the generation up-to-date. What do you think.

@robshakir
Copy link
Contributor Author

That sounds great to me :-)

Do we know all of the callers of generator.go that are doing path struct generation today? I'm not sure that we do - so it might be safer to keep generator.go doing this, but I'm also happy to break this.

In that case, I should take this code and submit it upstream at ypathgen, right?

@wenovus
Copy link
Collaborator

wenovus commented Aug 8, 2022

That sounds great to me :-)

Do we know all of the callers of generator.go that are doing path struct generation today? I'm not sure that we do - so it might be safer to keep generator.go doing this, but I'm also happy to break this.

In that case, I should take this code and submit it upstream at ypathgen, right?

Yep submitting upstream instead SGTM. I'm thinking we can remove it some point before the end of the year, latest by v1 release. I added the issue to the release milestone.

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.

3 participants