From d453a705da63e430f11b818257d9e7a44ec6fdc8 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sun, 19 Dec 2021 16:37:10 +0100 Subject: [PATCH] moved all working dirs into a workdir structure --- config_dist.yaml | 5 +---- main.go | 14 +++++++------- utils.go | 28 ++++++++++++++++------------ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/config_dist.yaml b/config_dist.yaml index 695d608..0f1b3b0 100644 --- a/config_dist.yaml +++ b/config_dist.yaml @@ -27,10 +27,7 @@ db: basedir: repo: /var/lib/alhp/repo/ - chroot: /var/lib/alhp/chroot/ - makepkg: /var/lib/alhp/makepkg/ - upstream: /var/lib/alhp/upstream/ - build: /var/lib/alhp/build/ + work: /var/lib/alhp/chroot/ march: - x86-64-v3 diff --git a/main.go b/main.go index a88ca6e..bf4cd07 100644 --- a/main.go +++ b/main.go @@ -124,8 +124,8 @@ func (b *BuildManager) buildWorker(id int, march string) { makepkgFile = "makepkg-%s.conf" } cmd := exec.Command("sh", "-c", - "cd "+filepath.Dir(pkg.Pkgbuild)+"&&makechrootpkg -c -D "+conf.Basedir.Makepkg+" -l worker-"+march+"-"+strconv.Itoa(id)+" -r "+conf.Basedir.Chroot+" -- "+ - "-m --noprogressbar --config "+filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf(makepkgFile, pkg.March))) + "cd "+filepath.Dir(pkg.Pkgbuild)+"&&makechrootpkg -c -D "+filepath.Join(conf.Basedir.Work, makepkgDir)+" -l worker-"+march+"-"+strconv.Itoa(id)+" -r "+filepath.Join(conf.Basedir.Work, chrootDir)+" -- "+ + "-m --noprogressbar --config "+filepath.Join(conf.Basedir.Work, makepkgDir, fmt.Sprintf(makepkgFile, pkg.March))) var out bytes.Buffer cmd.Stdout = &out cmd.Stderr = &out @@ -603,7 +603,7 @@ func (b *BuildManager) repoWorker(repo string) { } func (b *BuildManager) syncWorker() { - check(os.MkdirAll(conf.Basedir.Upstream, 0755)) + check(os.MkdirAll(filepath.Join(conf.Basedir.Work, upstreamDir), 0755)) for i := 0; i < runtime.NumCPU(); i++ { go b.parseWorker() @@ -613,7 +613,7 @@ func (b *BuildManager) syncWorker() { b.buildWG.Wait() for gitDir, gitURL := range conf.Svn2git { - gitPath := filepath.Join(conf.Basedir.Upstream, gitDir) + gitPath := filepath.Join(conf.Basedir.Work, upstreamDir, gitDir) if _, err := os.Stat(gitPath); os.IsNotExist(err) { cmd := exec.Command("git", "clone", "--depth=1", gitURL, gitPath) @@ -659,7 +659,7 @@ func (b *BuildManager) syncWorker() { err = setupChroot() } - alpmHandle, err = initALPM(filepath.Join(conf.Basedir.Chroot, pristineChroot), filepath.Join(conf.Basedir.Chroot, pristineChroot, "/var/lib/pacman")) + alpmHandle, err = initALPM(filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot), filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot, "/var/lib/pacman")) check(err) b.alpmMutex.Unlock() @@ -668,7 +668,7 @@ func (b *BuildManager) syncWorker() { b.queued = map[string]int{} b.queuedLock.Unlock() - pkgBuilds, err := Glob(filepath.Join(conf.Basedir.Upstream, "/**/PKGBUILD")) + pkgBuilds, err := Glob(filepath.Join(conf.Basedir.Work, upstreamDir, "/**/PKGBUILD")) check(err) // Shuffle pkgbuilds to spread out long-running builds, otherwise pkgBuilds is alphabetically-sorted @@ -798,7 +798,7 @@ func main() { } syncMarchs() - alpmHandle, err = initALPM(filepath.Join(conf.Basedir.Chroot, pristineChroot), filepath.Join(conf.Basedir.Chroot, pristineChroot, "/var/lib/pacman")) + alpmHandle, err = initALPM(filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot), filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot, "/var/lib/pacman")) check(err) go buildManager.syncWorker() diff --git a/utils.go b/utils.go index 82a4620..dd73d9b 100644 --- a/utils.go +++ b/utils.go @@ -32,7 +32,11 @@ const ( makepkgConf = "/usr/share/devtools/makepkg-x86_64.conf" logDir = "logs" pristineChroot = "root" + buildDir = "build" lastUpdate = "lastupdate" + upstreamDir = "upstream" + chrootDir = "chroot" + makepkgDir = "makepkg" ) var ( @@ -78,7 +82,7 @@ type Conf struct { Repos, March []string Svn2git map[string]string Basedir struct { - Repo, Chroot, Makepkg, Upstream, Build string + Repo, Work string } Db struct { Driver string @@ -221,7 +225,7 @@ func cleanBuildDir(dir string) error { } func (p *BuildPackage) setupBuildDir() (string, error) { - buildDir := filepath.Join(conf.Basedir.Build, p.March, p.Pkgbase+"-"+p.Version) + buildDir := filepath.Join(conf.Basedir.Work, buildDir, p.March, p.Pkgbase+"-"+p.Version) err := cleanBuildDir(buildDir) if err != nil { @@ -516,7 +520,7 @@ func (p *BuildPackage) SVN2GITVersion(h *alpm.Handle) (string, error) { } // upstream/upstream-core-extra/extra-cmake-modules/repos/extra-any/PKGBUILD - pkgBuilds, _ := Glob(filepath.Join(conf.Basedir.Upstream, "**/"+p.Pkgbase+"/repos/*/PKGBUILD")) + pkgBuilds, _ := Glob(filepath.Join(conf.Basedir.Work, upstreamDir, "**/"+p.Pkgbase+"/repos/*/PKGBUILD")) var fPkgbuilds []string for _, pkgbuild := range pkgBuilds { @@ -569,7 +573,7 @@ func (p *BuildPackage) SVN2GITVersion(h *alpm.Handle) (string, error) { } log.Infof("%s: resolving successful: MirrorRepo=%s; PKGBUILD chosen: %s", p.Pkgbase, iPackage.DB().Name(), fPkgbuilds[0]) } else if len(fPkgbuilds) == 0 { - return "", fmt.Errorf("%s: no matching PKGBUILD found (searched: %s, canidates: %s)", p.Pkgbase, filepath.Join(conf.Basedir.Upstream, "**/"+p.Pkgbase+"/repos/*/PKGBUILD"), pkgBuilds) + return "", fmt.Errorf("%s: no matching PKGBUILD found (searched: %s, canidates: %s)", p.Pkgbase, filepath.Join(conf.Basedir.Work, upstreamDir, "**/"+p.Pkgbase+"/repos/*/PKGBUILD"), pkgBuilds) } cmd := exec.Command("sh", "-c", "cd "+filepath.Dir(fPkgbuilds[0])+"&&"+"makepkg --printsrcinfo") @@ -627,19 +631,19 @@ func (p *BuildPackage) genSrcinfo() error { } func setupChroot() error { - if _, err := os.Stat(filepath.Join(conf.Basedir.Chroot, pristineChroot)); err == nil { + if _, err := os.Stat(filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot)); err == nil { //goland:noinspection SpellCheckingInspection - cmd := exec.Command("arch-nspawn", filepath.Join(conf.Basedir.Chroot, pristineChroot), "pacman", "-Syuu", "--noconfirm") + cmd := exec.Command("arch-nspawn", filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot), "pacman", "-Syuu", "--noconfirm") res, err := cmd.CombinedOutput() log.Debug(string(res)) if err != nil { return fmt.Errorf("Unable to update chroot: %v\n%s", err, string(res)) } } else if os.IsNotExist(err) { - err := os.MkdirAll(conf.Basedir.Chroot, 0755) + err := os.MkdirAll(filepath.Join(conf.Basedir.Work, chrootDir), 0755) check(err) - cmd := exec.Command("mkarchroot", "-C", pacmanConf, filepath.Join(conf.Basedir.Chroot, pristineChroot), "base-devel") + cmd := exec.Command("mkarchroot", "-C", pacmanConf, filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot), "base-devel") res, err := cmd.CombinedOutput() log.Debug(string(res)) if err != nil { @@ -725,7 +729,7 @@ func housekeeping(repo string, wg *sync.WaitGroup) error { case dbpackage.RepositoryCommunity: upstream = "upstream-community" } - pkg.Pkgbuild = filepath.Join(conf.Basedir.Upstream, upstream, dbPkg.Pkgbase, "repos", pkg.DbPackage.Repository.String()+"-"+conf.Arch, "PKGBUILD") + pkg.Pkgbuild = filepath.Join(conf.Basedir.Work, upstreamDir, upstream, dbPkg.Pkgbase, "repos", pkg.DbPackage.Repository.String()+"-"+conf.Arch, "PKGBUILD") // check if package is still part of repo dbs, err := alpmHandle.SyncDBs() @@ -882,10 +886,10 @@ func syncMarchs() { //goland:noinspection SpellCheckingInspection func setupMakepkg(march string) error { - lMakepkg := filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf("makepkg-%s.conf", march)) - lMakepkgLTO := filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf("makepkg-%s-lto.conf", march)) + lMakepkg := filepath.Join(conf.Basedir.Work, makepkgDir, fmt.Sprintf("makepkg-%s.conf", march)) + lMakepkgLTO := filepath.Join(conf.Basedir.Work, makepkgDir, fmt.Sprintf("makepkg-%s-lto.conf", march)) - err := os.MkdirAll(conf.Basedir.Makepkg, 0755) + err := os.MkdirAll(filepath.Join(conf.Basedir.Work, makepkgDir), 0755) if err != nil { return err }