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

cmd/api: make non-importable #62069

Closed
rsc opened this issue Aug 16, 2023 · 8 comments
Closed

cmd/api: make non-importable #62069

rsc opened this issue Aug 16, 2023 · 8 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Aug 16, 2023

Oops.

% cat x.go
package main
import _ "cmd/api"
func main() {}
% GOTOOLCHAIN=go1.19 go build x.go
x.go:2:8: import "cmd/api" is a program, not an importable package
% GOTOOLCHAIN=go1.20 go build x.go
% GOTOOLCHAIN=go1.21.0 go build x.go
% 
@rsc rsc added this to the Go1.22 milestone Aug 16, 2023
@rsc
Copy link
Contributor Author

rsc commented Aug 16, 2023

@gopherbot please backport

@gopherbot
Copy link

Backport issue(s) opened: #62070 (for 1.20), #62071 (for 1.21).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@dmitshur
Copy link
Contributor

dmitshur commented Aug 16, 2023

Relevant context: cmd/api was a command (i.e., package main) in Go 1.19 and older, and became a package (i.e., package api) in Go 1.20 and later in CL 453258.

@rsc
Copy link
Contributor Author

rsc commented Aug 16, 2023

That's a relief. That's a much smaller mistake. Will fix by moving cmd/api to cmd/internal/api.

@rsc
Copy link
Contributor Author

rsc commented Aug 16, 2023

Actually I can just rename the one non-test file.

@gopherbot
Copy link

Change https://go.dev/cl/520038 mentions this issue: cmd/api: rename api.go to main_test.go

@rsc rsc changed the title cmd/go: import of main package not diagnosed cmd/api: make non-importable Aug 16, 2023
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 16, 2023
@gopherbot
Copy link

Change https://go.dev/cl/520060 mentions this issue: [release-branch.go1.20] cmd/api: rename api.go to main_test.go

@gopherbot
Copy link

Change https://go.dev/cl/520061 mentions this issue: [release-branch.go1.21] cmd/api: rename api.go to main_test.go

gopherbot pushed a commit that referenced this issue Aug 17, 2023
This makes cmd/api no longer an importable package.
In CL 453258 I forgot that there was no direct prohibition
on importing packages from cmd - we just rely on the
fact that cmd/* is all package main and everything else
is cmd/internal.

Fixes #62069.
Fixes #62071.

Change-Id: Ifed738d333b40663f85eca8f83025fcea5df89a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/520038
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/520061
gopherbot pushed a commit that referenced this issue Aug 17, 2023
This makes cmd/api no longer an importable package.
In CL 453258 I forgot that there was no direct prohibition
on importing packages from cmd - we just rely on the
fact that cmd/* is all package main and everything else
is cmd/internal.

Fixes #62069.
Fixes #62070.

Change-Id: Ifed738d333b40663f85eca8f83025fcea5df89a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/520038
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/520060
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants