forked from ALHP/ALHP.GO
added LTO, fixed wrong permission on open()
This commit is contained in:
18
main.go
18
main.go
@@ -29,13 +29,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
conf = Conf{}
|
conf *Conf
|
||||||
repos []string
|
repos []string
|
||||||
alpmHandle *alpm.Handle
|
alpmHandle *alpm.Handle
|
||||||
reMarch = regexp.MustCompile(`(-march=)(.+?) `)
|
reMarch = regexp.MustCompile(`(-march=)(.+?) `)
|
||||||
rePkgRel = regexp.MustCompile(`(?m)^pkgrel\s*=\s*(.+)$`)
|
rePkgRel = regexp.MustCompile(`(?m)^pkgrel\s*=\s*(.+)$`)
|
||||||
rePkgFile = regexp.MustCompile(`^(.*)-.*-.*-(?:x86_64|any)\.pkg\.tar\.zst(?:\.sig)*$`)
|
rePkgFile = regexp.MustCompile(`^(.*)-.*-.*-(?:x86_64|any)\.pkg\.tar\.zst(?:\.sig)*$`)
|
||||||
buildManager BuildManager
|
buildManager *BuildManager
|
||||||
db *ent.Client
|
db *ent.Client
|
||||||
journalLog = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
|
journalLog = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
|
||||||
checkInterval = flag.Int("interval", 5, "How often svn2git should be checked in minutes (default: 5)")
|
checkInterval = flag.Int("interval", 5, "How often svn2git should be checked in minutes (default: 5)")
|
||||||
@@ -111,7 +111,7 @@ func (b *BuildManager) buildWorker(id int) {
|
|||||||
log.Warningf("[%s/%s] Build failed, exit code %d", pkg.FullRepo, pkg.Pkgbase, cmd.ProcessState.ExitCode())
|
log.Warningf("[%s/%s] Build failed, exit code %d", pkg.FullRepo, pkg.Pkgbase, cmd.ProcessState.ExitCode())
|
||||||
|
|
||||||
b.failedMutex.Lock()
|
b.failedMutex.Lock()
|
||||||
f, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, pkg.FullRepo+"_failed.txt"), os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC, os.ModePerm)
|
f, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, pkg.FullRepo+"_failed.txt"), os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC, 0644)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
_, err = f.WriteString(fmt.Sprintf("%s==%s\n", pkg.Pkgbase, constructVersion(pkg.Srcinfo.Pkgver, pkg.Srcinfo.Pkgrel, pkg.Srcinfo.Epoch)))
|
_, err = f.WriteString(fmt.Sprintf("%s==%s\n", pkg.Pkgbase, constructVersion(pkg.Srcinfo.Pkgver, pkg.Srcinfo.Pkgrel, pkg.Srcinfo.Epoch)))
|
||||||
@@ -119,8 +119,8 @@ func (b *BuildManager) buildWorker(id int) {
|
|||||||
check(f.Close())
|
check(f.Close())
|
||||||
b.failedMutex.Unlock()
|
b.failedMutex.Unlock()
|
||||||
|
|
||||||
check(os.MkdirAll(filepath.Join(conf.Basedir.Repo, "logs"), os.ModePerm))
|
check(os.MkdirAll(filepath.Join(conf.Basedir.Repo, "logs"), 0755))
|
||||||
check(os.WriteFile(filepath.Join(conf.Basedir.Repo, "logs", pkg.Pkgbase+".log"), out.Bytes(), os.ModePerm))
|
check(os.WriteFile(filepath.Join(conf.Basedir.Repo, "logs", pkg.Pkgbase+".log"), out.Bytes(), 0644))
|
||||||
|
|
||||||
dbPkg.Update().SetStatus(dbpackage.StatusFailed).SetBuildTimeEnd(time.Now()).SetHash(pkg.Hash).ExecX(context.Background())
|
dbPkg.Update().SetStatus(dbpackage.StatusFailed).SetBuildTimeEnd(time.Now()).SetHash(pkg.Hash).ExecX(context.Background())
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ func (b *BuildManager) htmlWorker() {
|
|||||||
statusTpl, err := template.ParseFiles("tpl/packages.html")
|
statusTpl, err := template.ParseFiles("tpl/packages.html")
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
f, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, "packages.html"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
|
f, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, "packages.html"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
check(statusTpl.Execute(f, gen))
|
check(statusTpl.Execute(f, gen))
|
||||||
check(f.Close())
|
check(f.Close())
|
||||||
|
|
||||||
@@ -448,7 +448,7 @@ func (b *BuildManager) repoWorker(repo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BuildManager) syncWorker() {
|
func (b *BuildManager) syncWorker() {
|
||||||
check(os.MkdirAll(conf.Basedir.Upstream, os.ModePerm))
|
check(os.MkdirAll(conf.Basedir.Upstream, 0755))
|
||||||
|
|
||||||
for i := 0; i < conf.Build.Worker; i++ {
|
for i := 0; i < conf.Build.Worker; i++ {
|
||||||
go b.buildWorker(i)
|
go b.buildWorker(i)
|
||||||
@@ -586,7 +586,7 @@ func main() {
|
|||||||
log.Warningf("Failed to drop priority: %v", err)
|
log.Warningf("Failed to drop priority: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(conf.Basedir.Repo, os.ModePerm)
|
err = os.MkdirAll(conf.Basedir.Repo, 0755)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
if conf.Db.Driver == "pgx" {
|
if conf.Db.Driver == "pgx" {
|
||||||
@@ -611,7 +611,7 @@ func main() {
|
|||||||
log.Panicf("Automigrate failed: %v", err)
|
log.Panicf("Automigrate failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
buildManager = BuildManager{
|
buildManager = &BuildManager{
|
||||||
build: make(chan *BuildPackage, 10000),
|
build: make(chan *BuildPackage, 10000),
|
||||||
parse: make(chan *BuildPackage, 10000),
|
parse: make(chan *BuildPackage, 10000),
|
||||||
repoPurge: make(map[string]chan *BuildPackage),
|
repoPurge: make(map[string]chan *BuildPackage),
|
||||||
|
17
utils.go
17
utils.go
@@ -167,7 +167,7 @@ func gitClean(pkg *BuildPackage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func increasePkgRel(pkg *BuildPackage) error {
|
func increasePkgRel(pkg *BuildPackage) error {
|
||||||
f, err := os.OpenFile(pkg.Pkgbuild, os.O_RDWR, os.ModePerm)
|
f, err := os.OpenFile(pkg.Pkgbuild, os.O_RDWR, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -364,7 +364,7 @@ func isPkgFailed(pkg *BuildPackage) bool {
|
|||||||
buildManager.failedMutex.Lock()
|
buildManager.failedMutex.Lock()
|
||||||
defer buildManager.failedMutex.Unlock()
|
defer buildManager.failedMutex.Unlock()
|
||||||
|
|
||||||
file, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, pkg.FullRepo+"_failed.txt"), os.O_RDWR|os.O_CREATE|os.O_SYNC, os.ModePerm)
|
file, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, pkg.FullRepo+"_failed.txt"), os.O_RDWR|os.O_CREATE|os.O_SYNC, 0664)
|
||||||
check(err)
|
check(err)
|
||||||
defer func(file *os.File) {
|
defer func(file *os.File) {
|
||||||
check(file.Close())
|
check(file.Close())
|
||||||
@@ -433,7 +433,7 @@ func setupChroot() error {
|
|||||||
return fmt.Errorf("Unable to update chroot: %v\n%s", err, string(res))
|
return fmt.Errorf("Unable to update chroot: %v\n%s", err, string(res))
|
||||||
}
|
}
|
||||||
} else if os.IsNotExist(err) {
|
} else if os.IsNotExist(err) {
|
||||||
err := os.MkdirAll(conf.Basedir.Chroot, os.ModePerm)
|
err := os.MkdirAll(conf.Basedir.Chroot, 0755)
|
||||||
check(err)
|
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.Chroot, pristineChroot), "base-devel")
|
||||||
@@ -594,7 +594,7 @@ func syncMarchs() {
|
|||||||
|
|
||||||
if _, err := os.Stat(filepath.Join(filepath.Join(conf.Basedir.Repo, fRepo, "os", conf.Arch))); os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Join(filepath.Join(conf.Basedir.Repo, fRepo, "os", conf.Arch))); os.IsNotExist(err) {
|
||||||
log.Debugf("Creating path %s", filepath.Join(conf.Basedir.Repo, fRepo, "os", conf.Arch))
|
log.Debugf("Creating path %s", filepath.Join(conf.Basedir.Repo, fRepo, "os", conf.Arch))
|
||||||
check(os.MkdirAll(filepath.Join(conf.Basedir.Repo, fRepo, "os", conf.Arch), os.ModePerm))
|
check(os.MkdirAll(filepath.Join(conf.Basedir.Repo, fRepo, "os", conf.Arch), 0755))
|
||||||
}
|
}
|
||||||
|
|
||||||
if i := find(eRepos, fRepo); i != -1 {
|
if i := find(eRepos, fRepo); i != -1 {
|
||||||
@@ -615,19 +615,24 @@ func syncMarchs() {
|
|||||||
func setupMakepkg(march string) {
|
func setupMakepkg(march string) {
|
||||||
lMakepkg := filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf("makepkg-%s.conf", march))
|
lMakepkg := filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf("makepkg-%s.conf", march))
|
||||||
|
|
||||||
check(os.MkdirAll(conf.Basedir.Makepkg, os.ModePerm))
|
check(os.MkdirAll(conf.Basedir.Makepkg, 0755))
|
||||||
t, err := os.ReadFile(makepkgConf)
|
t, err := os.ReadFile(makepkgConf)
|
||||||
check(err)
|
check(err)
|
||||||
makepkgStr := string(t)
|
makepkgStr := string(t)
|
||||||
|
|
||||||
makepkgStr = strings.ReplaceAll(makepkgStr, "-mtune=generic", "")
|
makepkgStr = strings.ReplaceAll(makepkgStr, "-mtune=generic", "")
|
||||||
|
makepkgStr = strings.ReplaceAll(makepkgStr, "!lto", "")
|
||||||
makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3")
|
makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3")
|
||||||
makepkgStr = strings.ReplaceAll(makepkgStr, " check ", " !check ")
|
makepkgStr = strings.ReplaceAll(makepkgStr, " check ", " !check ")
|
||||||
makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ")
|
makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ")
|
||||||
|
// Add LTO. Since it's (!lto) not in devtools yet, add it instead.
|
||||||
|
// See https://git.harting.dev/anonfunc/ALHP.GO/issues/52 for more
|
||||||
|
makepkgStr = strings.ReplaceAll(makepkgStr, "!debug", "!debug lto")
|
||||||
|
|
||||||
makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"")
|
makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"")
|
||||||
makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march)
|
makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march)
|
||||||
|
|
||||||
check(os.WriteFile(lMakepkg, []byte(makepkgStr), os.ModePerm))
|
check(os.WriteFile(lMakepkg, []byte(makepkgStr), 0644))
|
||||||
}
|
}
|
||||||
|
|
||||||
func isMirrorLatest(h *alpm.Handle, buildPkg *BuildPackage) (bool, alpm.IPackage, string, error) {
|
func isMirrorLatest(h *alpm.Handle, buildPkg *BuildPackage) (bool, alpm.IPackage, string, error) {
|
||||||
|
Reference in New Issue
Block a user