Navigation Menu

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

x/mobile/cmd/gobind: doesn't work if vendored because the .java files are not vendored #43736

Closed
albertvaka opened this issue Jan 15, 2021 · 6 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@albertvaka
Copy link

albertvaka commented Jan 15, 2021

What version of Go are you using (go version)?

$ go version
go version go1.15.6 linux/amd64

Also happens with 1.14

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/vaka/go/bin"
GOCACHE="/home/vaka/.cache/go-build"
GOENV="/home/vaka/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/vaka/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/vaka/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="/usr/bin/clang"
CXX="/usr/bin/clang++"
CGO_ENABLED="1"
GOMOD="/home/vaka/go/src/github.com/datadog/datadog-agent/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build230484147=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ gobind -lang=go,java -outdir=/tmp/gomobile-work-326180131 -tags=android github.com/DataDog/datadog-agent/cmd/agent/android failed: exit status 1
failed to open Java support file: open /home/vaka/go/src/github.com/DataDog/datadog-agent/vendor/golang.org/x/mobile/bind/java/Seq.java: no such file or directory
failed to copy Java support file: invalid argument

gobind is the last version: v0.0.0-20201217150744-e6ae53a27f4f. Also fails if I use go run golang.org/x/mobile/cmd/gobind instead of using the installed version.

@albertvaka
Copy link
Author

albertvaka commented Jan 15, 2021

It seems the problem is that the java files in golang.org/x/mobile/bind/java are not being copied to the vendor directory.

Which in turn seems to be a very upvoted issue but closed as wontfix: #26366

I guess vendoring golang.org/x/mobile is not supported then? 🤔

@albertvaka albertvaka changed the title [gomobile] gobind seems to look for Seq.java in the wrong place when vendored [gomobile] gobind doesn't work if vendored because the .java files are not vendored Jan 15, 2021
@albertvaka albertvaka reopened this Jan 15, 2021
@dmitshur dmitshur changed the title [gomobile] gobind doesn't work if vendored because the .java files are not vendored x/mobile/cmd/gobind: doesn't work if vendored because the .java files are not vendored Jan 16, 2021
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jan 16, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jan 16, 2021
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 19, 2021
@canning-duck
Copy link

This still happens with Go 1.17.6. Is it possible to embed the files with https://pkg.go.dev/embed ? Or are you expecting the behavior of go mod vendor to change in the future?

@hyangah
Copy link
Contributor

hyangah commented Jan 11, 2022

I don't think the root cause is #26366 (related but not the direct cause).
The go mod vendor vendors only packages the go command identifies during the build process, and golang.org/x/mobile/bind/java is a dependency added in the generated code, which the go command doesn't understand.

Can you please show us how github.com/DataDog/datadog-agent specifies dependency on golang.org/x/mobile currently?

@gopherbot
Copy link

Change https://golang.org/cl/377754 mentions this issue: cmd,bind: add implicit dependencies

@hyangah
Copy link
Contributor

hyangah commented Jan 11, 2022

I sent a cl that spells out the implicit dependencies in the tools' source code (cl/377754), but the current best practice (especially for gobind) is to check in the generated source code to the repository - does that work for your workflows?

gopherbot pushed a commit to golang/mobile that referenced this issue Jan 12, 2022
cmd/gomobile depends on cmd/gobind. Code generated by cmd/gobind
depends on packages under golang.org/x/mobile/bind. Explicitly
list those (with build tags) so the go command can take into account
these implicit dependencies (e.g. go mod tidy or go mod vendor).

We use tag `mobile_implicit`.

Updates golang/go#43736

Change-Id: I09c519556ffe8e8c4db0754571c5173b1613c210
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/377754
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
@hyangah
Copy link
Contributor

hyangah commented Jan 12, 2022

This should be fixed at golang.org/x/mobile@v0.0.0-20220112015953-858099ff7816

% cat main.go
package doc

import (
        _ "golang.org/x/mobile/cmd/gobind"
)
% go mod vendor
% tree vendor/golang.org/x/mobile/bind
vendor/golang.org/x/mobile/bind
├── bind.go
├── gen.go
├── genclasses.go
├── gengo.go
├── genjava.go
├── genobjc.go
├── genobjcw.go
├── implicit.go
├── java
│   ├── ClassesTest.java
│   ├── CustomPkgTest.java
│   ├── Seq.java
│   ├── SeqBench.java
....

@hyangah hyangah closed this as completed Jan 12, 2022
@golang golang locked and limited conversation to collaborators Jan 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants