Skip to content

Commit

Permalink
Don't panic on missing pkg.Module
Browse files Browse the repository at this point in the history
  • Loading branch information
podtserkovskiy committed Nov 1, 2024
1 parent 4e8264a commit 470d58f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ scip-go --version

## Indexing a Go project

### Standard `go.mod` project

From the root of your project, you can run:

```
Expand All @@ -39,6 +41,18 @@ If this doesn't solve the problem, check the rest of the available flags in:
scip-go --help
```

### Other build systems

The other build systems Buck/Bazel/Please/etc are supported via [Go Packages Driver Protocol](https://pkg.go.dev/golang.org/x/tools/go/packages#hdr-The_driver_protocol).


Usage:
```
GOPACKAGESDRIVER=your_driver scip-go
```

Note: Due to the current protocol design cross-repo navigation will not work.

### Common Problems:

- Unable to navigate to Go standard library.
Expand All @@ -54,7 +68,7 @@ scip-go --help

`scip-go` by default uses a few different `go` commands from the command line to
gain information about the project and module. To avoid running `go` directly
(perhaps you have some other build system), you will need to supply the folling args.
(perhaps you have some other build system), you will need to supply the following args.

```
scip-go --module-name="<my modules name here>"
Expand Down
25 changes: 17 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import "path/filepath"
import (
"os"
"path/filepath"
)

type IndexOpts struct {
ModuleRoot string
Expand All @@ -9,6 +12,8 @@ type IndexOpts struct {
// Path for the current module we are indexing. Same as packages.Package.Module.Path
ModulePath string

IsGoPackagesDriverSet bool

// Go version. Used for linking to the Go standard library
GoStdlibVersion string

Expand All @@ -25,13 +30,17 @@ func New(ModuleRoot, ModuleVersion, ModulePath, GoStdlibVersion string, IsIndexi
panic(err)
}

driver := os.Getenv("GOPACKAGESDRIVER")
isGoPackagesDriverSet := driver != "" && driver != "off"

return IndexOpts{
ModuleRoot: ModuleRoot,
ModuleVersion: ModuleVersion,
ModulePath: ModulePath,
GoStdlibVersion: GoStdlibVersion,
SkipImplementations: SkipImplementations,
SkipTests: SkipTests,
IsIndexingStdlib: IsIndexingStdlib,
ModuleRoot: ModuleRoot,
ModuleVersion: ModuleVersion,
ModulePath: ModulePath,
GoStdlibVersion: GoStdlibVersion,
SkipImplementations: SkipImplementations,
SkipTests: SkipTests,
IsIndexingStdlib: IsIndexingStdlib,
IsGoPackagesDriverSet: isGoPackagesDriverSet,
}
}
18 changes: 17 additions & 1 deletion internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ func normalizePackage(opts *config.IndexOpts, pkg *packages.Package) *packages.P
// Path string = "github.com/efritz/pentimento"
// Version string = "v0.0.0-20190429011147-ade47d831101"

if opts.IsGoPackagesDriverSet {
pkg.Module = &packages.Module{
Path: ".",
Version: ".",
}

if opts.ModulePath != "" {
pkg.Module.Path = opts.ModulePath
}

if opts.ModuleVersion != "" {
pkg.Module.Version = opts.ModuleVersion
}

return pkg
}

if IsStandardLib(pkg) || opts.IsIndexingStdlib {
pkg.Module = &packages.Module{
Path: "github.com/golang/go/src",
Expand All @@ -183,7 +200,6 @@ func normalizePackage(opts *config.IndexOpts, pkg *packages.Package) *packages.P
pkg.PkgPath,
))
}

}

// Follow replaced modules
Expand Down

0 comments on commit 470d58f

Please sign in to comment.