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

Go list to generate build graph #5

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.idea
tmp/
plz-out/
.idea

# Entries below this point are managed by Please (DO NOT EDIT)
plz-out
Expand Down
4 changes: 2 additions & 2 deletions .plzconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
;
; Or you can uncomment the following to pin everyone to a particular version;
; when you change it all users will automatically get updated.
; [please]
; version = 16.5.1
[please]
version = 16.7.0

[go]
gotool = //third_party/go:toolchain|go
Expand Down
14 changes: 11 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ module github.com/jamesjarvis/go-deps
go 1.16

require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/bazelbuild/buildtools v0.0.0-20210824143317-0a897f9af678
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/google/go-licenses v0.0.0-20210816172045-3099c18c36e1
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0
golang.org/x/mod v0.4.2
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/mod v0.4.0
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 // indirect
golang.org/x/tools v0.0.0-20210106214847-113979e3529a
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
207 changes: 201 additions & 6 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
)

// findGoTool attempts to locate the go executable. If GOROOT is set, we'll
// FindGoTool attempts to locate the go executable. If GOROOT is set, we'll
// prefer the one in there; otherwise, we'll rely on PATH. If the wrapper
// script generated by the gazelle rule is invoked by Bazel, it will set
// GOROOT to the configured SDK. We don't want to rely on the host SDK in
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (

"github.com/jamesjarvis/go-deps/host"
"github.com/jamesjarvis/go-deps/module"

"github.com/urfave/cli/v2"
)

const (
moduleFlag = "module"
moduleFlag = "module"
versionFlag = "version"
)

Expand All @@ -23,9 +24,9 @@ func main() {
Usage: "Add a Go Module to an existing Please Monorepo",
Flags: []cli.Flag{
&cli.StringFlag{
Name: moduleFlag,
Aliases: []string{"m"},
Usage: "Module to add",
Name: moduleFlag,
Aliases: []string{"m"},
Usage: "Module to add",
Required: true,
},
&cli.StringFlag{
Expand All @@ -47,7 +48,7 @@ func main() {
}

m := &module.Module{
Path: c.String(moduleFlag),
Path: c.String(moduleFlag),
Version: c.String(versionFlag),
}

Expand Down
2 changes: 1 addition & 1 deletion module/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ go_library(
visibility = ["PUBLIC"],
deps = [
"//host",
"//third_party/go:mod",
"//third_party/go:golang.org.x.mod",
],
)
Empty file modified pleasew
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions progress/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go_library(
name = "progress",
srcs = ["progress.go"],
visibility = ["PUBLIC"],
)
17 changes: 17 additions & 0 deletions progress/progress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package progress

import (
"fmt"
"os"
)

const clearLineSequence = "\x1b[1G\x1b[2K"

func PrintUpdate(update string, args ...interface{}) {
Clear()
fmt.Fprintf(os.Stderr, update, args...)
}

func Clear() {
fmt.Fprintf(os.Stderr, clearLineSequence)
}
14 changes: 14 additions & 0 deletions resolve/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
go_library(
name = "resolve",
srcs = [
"known_imports.go",
"resolve.go",
],
visibility = ["PUBLIC"],
deps = [
"//progress",
"//resolve/model",
"//third_party/go:github.com.google.go-licenses",
"//third_party/go:golang.org.x.tools",
],
)
8 changes: 8 additions & 0 deletions resolve/cmd/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
go_binary(
name = "cmd",
srcs = ["main.go"],
deps = [
"//resolve",
"//rules",
],
)
27 changes: 27 additions & 0 deletions resolve/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"os"

"github.com/jamesjarvis/go-deps/resolve"
"github.com/jamesjarvis/go-deps/rules"
)



// This is janky and mostly just to test if this thing works.
func main() {
moduleGraph, err := rules.ReadRules(os.Args[1])
if err != nil {
panic(err)
}
err = resolve.UpdateModules(moduleGraph.Modules, os.Args[2:])
if err != nil {
panic(err)
}

err = moduleGraph.Save()
if err != nil {
panic(err)
}
}
205 changes: 205 additions & 0 deletions resolve/known_imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package resolve

// TODO(jpoole): these could come from a .importconfig which might be cleaner
var KnownImports = map[string]struct{}{
"archive/tar": {},
"archive/zip": {},
"bufio": {},
"bytes": {},
"compress/bzip2": {},
"compress/flate": {},
"compress/gzip": {},
"compress/lzw": {},
"compress/zlib": {},
"container/heap": {},
"container/list": {},
"container/ring": {},
"context": {},
"crypto/aes": {},
"crypto/cipher": {},
"crypto/des": {},
"crypto/dsa": {},
"crypto/ecdsa": {},
"crypto/ed25519": {},
"crypto/ed25519/internal/edwards25519": {},
"crypto/elliptic": {},
"crypto/elliptic/internal/fiat/please": {},
"crypto/hmac": {},
"crypto": {},
"crypto/internal/randutil": {},
"crypto/internal/subtle": {},
"crypto/md5": {},
"crypto/rand": {},
"crypto/rc4": {},
"crypto/rsa": {},
"crypto/sha1": {},
"crypto/sha256": {},
"crypto/sha512": {},
"crypto/subtle": {},
"crypto/tls": {},
"crypto/x509": {},
"crypto/x509/pkix": {},
"database/sql/driver": {},
"database/sql": {},
"debug/dwarf": {},
"debug/elf": {},
"debug/gosym": {},
"debug/macho": {},
"debug/pe": {},
"debug/plan9obj": {},
"embed": {},
"encoding/ascii85": {},
"encoding/asn1": {},
"encoding/base32": {},
"encoding/base64": {},
"encoding/binary": {},
"encoding/csv": {},
"encoding/gob": {},
"encoding/hex": {},
"encoding": {},
"encoding/json": {},
"encoding/pem": {},
"encoding/xml": {},
"errors": {},
"expvar": {},
"flag": {},
"fmt": {},
"go/ast": {},
"go/build/constraint": {},
"go/build": {},
"go/constant": {},
"go/doc": {},
"go/format": {},
"go/importer": {},
"go/internal/gccgoimporter": {},
"go/internal/gcimporter": {},
"go/internal/srcimporter": {},
"go/internal/typeparams": {},
"go/parser": {},
"go/printer": {},
"go/scanner": {},
"go/token": {},
"go/types": {},
"hash/adler32": {},
"hash/crc32": {},
"hash/crc64": {},
"hash/fnv": {},
"hash": {},
"hash/maphash": {},
"html": {},
"html/template": {},
"image/color": {},
"image/color/palette": {},
"image/draw": {},
"image/gif": {},
"image": {},
"image/internal/imageutil": {},
"image/jpeg": {},
"image/png": {},
"index/suffixarray": {},
"internal/abi": {},
"internal/buildcfg": {},
"internal/bytealg": {},
"internal/cfg": {},
"internal/cpu": {},
"internal/execabs": {},
"internal/fmtsort": {},
"internal/goexperiment": {},
"internal/goroot": {},
"internal/goversion": {},
"internal/itoa": {},
"internal/lazyregexp": {},
"internal/lazytemplate": {},
"internal/nettrace": {},
"internal/obscuretestdata": {},
"internal/oserror": {},
"internal/poll": {},
"internal/profile": {},
"internal/race": {},
"internal/reflectlite": {},
"internal/singleflight": {},
"internal/syscall/execenv": {},
"internal/syscall/unix": {},
"internal/sysinfo": {},
"internal/testenv": {},
"internal/testlog": {},
"internal/trace": {},
"internal/unsafeheader": {},
"internal/xcoff": {},
"io/fs": {},
"io": {},
"io/ioutil": {},
"log": {},
"log/syslog": {},
"math/big": {},
"math/bits": {},
"math/cmplx": {},
"math": {},
"math/rand": {},
"mime": {},
"mime/multipart": {},
"mime/quotedprintable": {},
"net": {},
"net/http/cgi": {},
"net/http/cookiejar": {},
"net/http/fcgi": {},
"net/http": {},
"net/http/httptest": {},
"net/http/httptrace": {},
"net/http/httputil": {},
"net/http/internal/ascii/please": {},
"net/http/internal": {},
"net/http/internal/testcert/please": {},
"net/http/pprof": {},
"net/internal/socktest": {},
"net/mail": {},
"net/rpc": {},
"net/rpc/jsonrpc": {},
"net/smtp": {},
"net/textproto": {},
"net/url": {},
"os/exec": {},
"os": {},
"os/signal": {},
"os/signal/internal/pty/please": {},
"os/user": {},
"path/filepath": {},
"path": {},
"plugin": {},
"reflect": {},
"reflect/internal/example1": {},
"reflect/internal/example2": {},
"regexp": {},
"regexp/syntax": {},
"runtime/cgo": {},
"runtime/debug": {},
"runtime": {},
"runtime/internal/atomic": {},
"runtime/internal/math": {},
"runtime/internal/sys": {},
"runtime/metrics": {},
"runtime/pprof": {},
"runtime/race": {},
"runtime/trace": {},
"sort": {},
"strconv": {},
"strings": {},
"sync/atomic": {},
"sync": {},
"syscall": {},
"testing/fstest": {},
"testing": {},
"testing/internal/testdeps": {},
"testing/iotest": {},
"testing/quick": {},
"text/scanner": {},
"text/tabwriter": {},
"text/template": {},
"text/template/parse": {},
"time": {},
"time/tzdata": {},
"unicode": {},
"unicode/utf16": {},
"unicode/utf8": {},
"unsafe": {},
}
5 changes: 5 additions & 0 deletions resolve/model/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go_library(
name = "model",
srcs = ["model.go"],
visibility = ["PUBLIC"],
)
Loading