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

import from Go module #1

Open
orangecms opened this issue Jan 16, 2023 · 1 comment
Open

import from Go module #1

orangecms opened this issue Jan 16, 2023 · 1 comment

Comments

@orangecms
Copy link

Hey, I'm trying to use the codegen in Fiano, but I have cloned the repo somewhere in my projects directory, not in ~/go/src:

$ go run ./pkg/intel/metadata/common/manifestcodegen/cmd/manifestcodegen -package bg ./pkg/intel/metadata/bg/bgkey            
2023/01/15 17:54:56 an error: unable to analyze path './pkg/intel/metadata/bg/bgkey': unable to get the package from directory './pkg/intel/metadata/bg/bgkey': unable to open go directory: unable to normalize pkg path '': unable to find directory './pkg/intel/metadata/bg/bgkey' in paths [/usr/lib/go-1.18/src /home/dama/go/src]

So I ended up here:

https://github.com/xaionaro-go/gosrc/blob/master/directory.go#L148-L156

Coming from:
https://github.com/linuxboot/fiano/blob/8a127a636eef8e937572f050fad083972dff737a/pkg/intel/metadata/common/manifestcodegen/pkg/analyze/scan.go#L46

So I tried the following:

adding this

// essentially https://stackoverflow.com/a/67997080
func lookup(name string) (io.ReadCloser, error) {
    f, err := os.Open(name)
    if err != nil {
        return nil, err
    }
    // f implements io.ReadCloser interface as *os.File
    // has Read and Close methods.
    return f, nil
}

and then later, instead of nil, passing the above function to the importer:

  conf = types.Config{Importer: importer.ForCompiler(token.NewFileSet(), "source", lookup)}

However, this errors:

panic: source importer for custom import path lookup not supported (issue #13847).

Indeed, this is not yet supported: https://github.com/golang/go/blob/1c65b69bd1dbc930c6246877f6c21c81f2a60d55/src/go/importer/importer.go#L62

However, said issue is closed: golang/go#13847

Do you have any idea how to solve this? It looks to me like the Go compiler needs a fix. Not sure though.

@xaionaro
Copy link
Member

xaionaro commented Jan 17, 2023

Initially the code of gosrc was written for pre-gomodules environment :(
So basically it works only with GO111MODULE=off. I've provided a bit more details in the initial task.

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

No branches or pull requests

2 participants