Skip to content

Commit

Permalink
fix: --dir not working with generated modules.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
obreitwi committed Nov 17, 2024
1 parent 9832283 commit 8d0a797
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,29 @@ func GeneratePkgs(directory string, goMod2NixPath string, numWorkers int) (*sche
return nil, err
}

// Dependencies is downloaded, run `go mod vendor` to obtain `vendor/modules.txt` without reverse engineering
tmpVendorEnv := filepath.Join(directory, "vendor-gomod2nix")
err = os.RemoveAll(tmpVendorEnv)
// Dependencies are downloaded, run `go mod vendor` to obtain `vendor/modules.txt` without reverse engineering
const tmpVendorEnvRelative = "vendor-gomod2nix"
tmpVendorEnvAbsolute := filepath.Join(directory, tmpVendorEnvRelative)
err = os.RemoveAll(tmpVendorEnvAbsolute)
if err != nil {
return nil, err
}
defer func() {
_ = os.RemoveAll(tmpVendorEnv)
_ = os.RemoveAll(tmpVendorEnvAbsolute)
}()

var modulesTxt string
{
log.Info("Obtaining modules.txt")
cmd := exec.Command(
"go", "mod", "vendor", "-o", tmpVendorEnv,
"go", "mod", "vendor", "-o", tmpVendorEnvRelative,
)
cmd.Dir = directory
err = cmd.Run()
if err != nil {
return nil, err
}
modulesTxtBytes, err := os.ReadFile(filepath.Join(tmpVendorEnv, "modules.txt"))
modulesTxtBytes, err := os.ReadFile(filepath.Join(tmpVendorEnvAbsolute, "modules.txt"))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 8d0a797

Please sign in to comment.