Skip to content

Conversation

@dmashuda
Copy link
Contributor

@dmashuda dmashuda commented Nov 14, 2025

Feature

-input <string> sets the name of the input file. When set uses "go/build" and "go/parser" directly, which can result in performance improvements

runWithInputFile is an alternative to packages.Load because packages.Load requires a full go driver
runWithInputFile uses "go/build" and "go/parser" directly, but requires a file name to be passed.
This limits the number of required dependencies, and speeds up generation times

Tested against gonfalon with this pr resulting in a no-op: https://github.com/launchdarkly/gonfalon/pull/55614


Related Jira issue: FUN-747: Bazel genrule: go-options

@launchdarkly-upra launchdarkly-upra bot changed the title Add input file option with smaller dependency set [FUN-747] Add input file option with smaller dependency set Nov 14, 2025
@dmashuda dmashuda self-assigned this Nov 14, 2025
@dmashuda dmashuda requested a review from a team November 14, 2025 15:34
Copy link
Member

@tvarney13 tvarney13 left a comment

Choose a reason for hiding this comment

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

approved but asked a question around potential improvements

Comment on lines +169 to +182
inferedPackage := f.Name.Name
success := false
ast.Inspect(f, func(node ast.Node) bool {
found := writeOptionsFile(typeNames, inferedPackage, node, fset)
if found {
success = true
}
return !found
})
if !success {
return fmt.Errorf(`unable to find type "%s"`, typeNames)
}

return nil
Copy link
Member

Choose a reason for hiding this comment

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

This is semi-duplicated with the thing that main is already doing - should we create a common function? Alternatively can we write a function that constructs the pkgs array differently based on the input provided?

Copy link
Member

Choose a reason for hiding this comment

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

Looking closer - they're not that similar but there are similar pieces of data with similar types being looked at. There's probably something that could be done, but it's a question of whether or not that effort is worth it for this gen script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is semi-duplicated with the thing that main is already doing - should we create a common function? Alternatively can we write a function that constructs the pkgs array differently based on the input provided?

The main duplication here is the call to ast.Inspect but a lot of the params are sourced differently.

  1. the method in main loops over all of the files vs single file when using the new mode
  2. the new method has to infer the package name from the input file

@dmashuda dmashuda merged commit 31e009b into main Nov 14, 2025
3 checks passed
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