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

Add gocp tool #275

Closed
wants to merge 4 commits into from
Closed

Add gocp tool #275

wants to merge 4 commits into from

Conversation

pellared
Copy link
Member

@pellared pellared commented Mar 13, 2023

Why

Fixes #276

Towards addressing open-telemetry/opentelemetry-go#3846

Towards fixing open-telemetry/opentelemetry-go#3548

Addresses open-telemetry/opentelemetry-go#3841 (comment)

What

Add gocpy tool that can be used for sharing internal code (more in README.md).

This tool is currently needed for https://github.com/open-telemetry/opentelemetry-go.

Prior art (with example usage): open-telemetry/opentelemetry-go#3841

Other

Do we want to use it for internal/repo and internal/syncerror? Personally, I think there is no big need as these APIs looks pretty stable. And AFAIK the tools are bumped together. On the other hand, it may be good to dogfood for the sake of consistency across OTel Go repositories. Because I cannot find a clear answer myself, I can simply create a follow-up PR once this one is merged. It should be easier for the reviewers to decide.

@codecov
Copy link

codecov bot commented Mar 13, 2023

Codecov Report

Patch coverage: 50.00% and project coverage change: -0.26 ⚠️

Comparison is base (6a7e7b4) 58.95% compared to head (28e4501) 58.69%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #275      +/-   ##
==========================================
- Coverage   58.95%   58.69%   -0.26%     
==========================================
  Files          44       46       +2     
  Lines        1988     2046      +58     
==========================================
+ Hits         1172     1201      +29     
- Misses        686      708      +22     
- Partials      130      137       +7     
Impacted Files Coverage Δ
gocp/main.go 0.00% <0.00%> (ø)
gocp/gocp.go 58.00% <58.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

The gocpy binary needs to be removed from the git history.

gocp/README.md Outdated Show resolved Hide resolved
gocp/README.md Outdated Show resolved Hide resolved
gocp/gocp.go Show resolved Hide resolved
@pellared pellared requested a review from MrAlias March 13, 2023 16:35
Remove gocpy binary

Fix typos

Add tests

Apply suggestions from code review

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@pellared
Copy link
Member Author

The gocpy binary needs to be removed from the git history.

Done.

@pellared pellared requested a review from Aneurysm9 March 13, 2023 21:35
@pellared pellared dismissed MrAlias’s stale review March 14, 2023 21:07

comments addressed

gocp/README.md Outdated Show resolved Hide resolved
gocp/README.md Outdated Show resolved Hide resolved
@pellared pellared requested a review from utezduyar March 15, 2023 15:09
Copy link

@utezduyar utezduyar left a comment

Choose a reason for hiding this comment

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

LGTM for my review comments

"fmt"
"os"

flag "github.com/spf13/pflag"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just use flag?

Copy link
Member Author

@pellared pellared Mar 20, 2023

Choose a reason for hiding this comment

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

Only because this package is used in all other tools. Indirectly in most of them via spf13/cobra and directly in crosslilnk and semconvgen. flag is not directly used in any of the tools.

for scanner.Scan() {
txt := scanner.Text()

if !pkgReplaced && strings.HasPrefix(txt, "package ") {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it has limited functionality compared to using a text template. When these copied internal packages start to depend on each other the imports will need to be appropriately templatized. Why not just use a text template for this?

Copy link
Member Author

@pellared pellared Mar 20, 2023

Choose a reason for hiding this comment

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

When these copied internal packages start to depend on each other the imports will need to be appropriately templatized.

That is true. Currently, we already have a use case for it: https://github.com/open-telemetry/opentelemetry-go/blob/4ccd59056982f34c3fcc8faef574f209b70d0f59/sdk/internal/env/env_test.go#L24

Why not just use a text template for this?

I found it easier to use actual Go code than writing Go source code templates because we get IDE support.

The second reason is that the the "shared Go code" is analyzed using golangci-lint what we could not say about templates. The problem is that if the generated code has // Code generated by gocp. DO NOT EDIT. comment then it won't be analyzed by golangci-lint. We could alter the text to something like // Generated by gocp. However, we will lint all the generated files instead of only linting the source files .

Summary

Having all that said I feel that we indeed need this flexibility and I will try to simply create a simple CLI for text/template. Probably the tool should be also renamed to something more or less like gotmpl.

@pellared pellared marked this pull request as draft March 20, 2023 09:26
@pellared pellared marked this pull request as ready for review March 20, 2023 19:20
@pellared
Copy link
Member Author

Closing per #275 (comment). I will create a new PR (next iteration) in the following days.

@pellared pellared closed this Mar 20, 2023
@pellared pellared mentioned this pull request Mar 21, 2023
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.

Add a tool facilitating sharing Go code across Go modules
4 participants