add --recursive

This commit is contained in:
Jeff Carr 2024-03-21 19:43:26 -05:00
parent f09d0fbfa9
commit 7a095d1566
4 changed files with 76 additions and 31 deletions

View File

@ -7,6 +7,9 @@ run: build
# test using --no-work against ~/go/src # test using --no-work against ~/go/src
homeGoSrc: build homeGoSrc: build
-rm ~/go/src/go.work*
go clean -cache -modcache
-rm -rf ../basicwindow/
./go-clone --no-work go.wit.com/apps/basicwindow ./go-clone --no-work go.wit.com/apps/basicwindow
modernc: build modernc: build
@ -20,7 +23,11 @@ no-gui: build
./go-clone --no-gui ./go-clone --no-gui
build: build:
GO111MODULE=off go build -v -ldflags "-X main.VERSION=${VERSION}" -ldflags "-X main.GUIVERSION=${VERSION}" GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
build-go-1.21:
@#GO111MODULE=off /usr/lib/go-1.21/bin/go build -v -ldflags "-X main.VERSION=${VERSION}"
@# GO111MODULE=off /usr/lib/go-1.21/bin/go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
@# GO111MODULE=off go build -v -ldflags "-X main.GUIVERSION=${VERSION}" @# GO111MODULE=off go build -v -ldflags "-X main.GUIVERSION=${VERSION}"
install: install:

View File

@ -1 +1,36 @@
# go-clone # go-clone
5 years earlier, [gohack](https://github.com/rogpeppe/gohack) was written for the same reasons
this tool was written. gohack has a good justification for this kind of tool so here it is:
## Gohack: mutable checkouts of Go module dependencies
The new Go module system is awesome. It ensures repeatable, deterministic
builds of Go code. External module code is cached locally in a read-only
directory, which is great for reproducibility. But if you're used to the
global mutable namespace that is `$GOPATH`, there's an obvious question:
what if I'm hacking on my program and I *want* to change one of those
external modules?
You might want to put a sneaky `log.Printf` statement to find out how
some internal data structure works, or perhaps try out a bug fix to see
if it solves your latest problem. But since all those external modules
are in read-only directories, it's hard to change them. And you really
don't want to change them anyway, because that will break the integrity
checking that the Go tool does when building.
Luckily the modules system provides a way around this: you can add a
`replace` statement to the `go.mod` file which substitutes the contents
of a directory holding a module for the readonly cached copy. You can of
course do this manually, but gohack aims to make this process pain-free.
## Install go-glone
go install go.wit.com/apps/go-clone@latest
## go-glone itself
This will make a work directory and download everything needs to compile
go-clone.
go-clone --work go.wit.com/apps/go-clone

16
argv.go
View File

@ -7,19 +7,21 @@ package main
*/ */
type args struct { type args struct {
Repo string `arg:"positional" help:"go import path"` Repo string `arg:"positional" help:"go import path"`
Work bool `arg:"--work" help:"make a work directory"` Work bool `arg:"--work" help:"make a work directory"`
NoWork bool `arg:"--no-work" help:"does not make a go.work file"` NoWork bool `arg:"--no-work" help:"do not make or modify the go.work file"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Recursive bool `arg:"--recursive" help:"resursively clone all dependencies"`
} }
func (a args) Description() string { func (a args) Description() string {
return ` return `
Example usage: "go-clone go.wit.com/apps/go-clone" This will recursively clone the sources for this app into a work/ directory:
This will pull down the go sources and go-clone --recursive go.wit.com/apps/go-clone
the repositories in the go.sum file using git clone` `
} }
func (args) Version() string { func (args) Version() string {
return "go-clone " + VERSION return "go-clone " + Version
} }

47
main.go
View File

@ -14,20 +14,16 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
var VERSION string var Version string
var rv *repolist.RepoList var rv *repolist.RepoList
var myargs args var myargs args
func main() { func main() {
arg.MustParse(&myargs) pp := arg.MustParse(&myargs)
if myargs.Repo == "" { if myargs.Repo == "" {
// tmp.WriteHelp(os.Stdout) pp.WriteHelp(os.Stdout)
// fmt.Println("hello world")
tmp := myargs.Description()
fmt.Println(tmp)
fmt.Println(myargs.Version())
os.Exit(0) os.Exit(0)
} }
@ -61,32 +57,37 @@ func main() {
} }
godep := newr.Status.GetGoDeps() godep := newr.Status.GetGoDeps()
for gopath, version := range godep { if myargs.Recursive {
repo, err := rv.NewRepo(gopath) for gopath, version := range godep {
if err != nil { repo, err := rv.NewRepo(gopath)
log.Info("git clone failed for", gopath, version) if err != nil {
continue log.Info("git clone failed for", gopath, version)
} continue
repo.Status.MakeRedomod() }
}
for _, repo := range rv.AllRepos() {
if ! repo.Status.Exists("go.mod") {
repo.Status.MakeRedomod() repo.Status.MakeRedomod()
} }
} }
log.Info("all repositories are cloned") var count int
for _, repo := range rv.AllRepos() {
count += 1
if !repo.Status.Exists("go.mod") {
repo.Status.MakeRedomod()
}
}
log.Info("Total repositories:", count)
if !myargs.NoWork { if !myargs.NoWork {
log.Info("Creating", wdir+"/go.work") log.Info("Creating", wdir+"/go.work")
rv.MakeGoWork() rv.MakeGoWork()
shell.RunPath(wdir, []string{"go", "work", "use"}) shell.RunPath(wdir, []string{"go", "work", "use"})
} }
for _, repo := range rv.AllRepos() { /*
log.Info("found repo", repo.GoPath(), repo.Status.Path()) for _, repo := range rv.AllRepos() {
} log.Info("found repo", repo.GoPath(), repo.Status.Path())
}
*/
} }
// look for or make a go.work file // look for or make a go.work file