(ctx context.Context, cmdBuilder exe.ICmdBuilder, targetDir string, )
| 25 | var ErrNoBuildFiles = errors.New(gotext.Get("cannot find PKGBUILD and .SRCINFO in directory")) |
| 26 | |
| 27 | func srcinfoExists(ctx context.Context, |
| 28 | cmdBuilder exe.ICmdBuilder, targetDir string, |
| 29 | ) error { |
| 30 | srcInfoDir := filepath.Join(targetDir, ".SRCINFO") |
| 31 | pkgbuildDir := filepath.Join(targetDir, "PKGBUILD") |
| 32 | if _, err := os.Stat(srcInfoDir); err == nil { |
| 33 | if _, err := os.Stat(pkgbuildDir); err == nil { |
| 34 | return nil |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if _, err := os.Stat(pkgbuildDir); err == nil { |
| 39 | // run makepkg to generate .SRCINFO |
| 40 | srcinfo, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildMakepkgCmd(ctx, targetDir, "--printsrcinfo")) |
| 41 | if err != nil { |
| 42 | return fmt.Errorf("unable to generate .SRCINFO: %w - %s", err, stderr) |
| 43 | } |
| 44 | |
| 45 | if srcinfo == "" { |
| 46 | return fmt.Errorf("generated .SRCINFO is empty, check your PKGBUILD for errors") |
| 47 | } |
| 48 | |
| 49 | if err := os.WriteFile(srcInfoDir, []byte(srcinfo), 0o600); err != nil { |
| 50 | return fmt.Errorf("unable to write .SRCINFO: %w", err) |
| 51 | } |
| 52 | |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | return fmt.Errorf("%w: %s", ErrNoBuildFiles, targetDir) |
| 57 | } |
| 58 | |
| 59 | func installLocalPKGBUILD( |
| 60 | ctx context.Context, |
no test coverage detected