added LTO, fixed wrong permission on open()

This commit is contained in:
2021-11-04 11:59:57 +01:00
parent 97efc03abb
commit 7eb1be8371
2 changed files with 20 additions and 15 deletions

18
main.go
View File

@@ -29,13 +29,13 @@ import (
)
var (
conf = Conf{}
conf *Conf
repos []string
alpmHandle *alpm.Handle
reMarch = regexp.MustCompile(`(-march=)(.+?) `)
rePkgRel = regexp.MustCompile(`(?m)^pkgrel\s*=\s*(.+)$`)
rePkgFile = regexp.MustCompile(`^(.*)-.*-.*-(?:x86_64|any)\.pkg\.tar\.zst(?:\.sig)*$`)
buildManager BuildManager
buildManager *BuildManager
db *ent.Client
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)")
@@ -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())
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)
_, 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())
b.failedMutex.Unlock()
check(os.MkdirAll(filepath.Join(conf.Basedir.Repo, "logs"), os.ModePerm))
check(os.WriteFile(filepath.Join(conf.Basedir.Repo, "logs", pkg.Pkgbase+".log"), out.Bytes(), 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(), 0644))
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")
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(f.Close())
@@ -448,7 +448,7 @@ func (b *BuildManager) repoWorker(repo string) {
}
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++ {
go b.buildWorker(i)
@@ -586,7 +586,7 @@ func main() {
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)
if conf.Db.Driver == "pgx" {
@@ -611,7 +611,7 @@ func main() {
log.Panicf("Automigrate failed: %v", err)
}
buildManager = BuildManager{
buildManager = &BuildManager{
build: make(chan *BuildPackage, 10000),
parse: make(chan *BuildPackage, 10000),
repoPurge: make(map[string]chan *BuildPackage),

View File

@@ -167,7 +167,7 @@ func gitClean(pkg *BuildPackage) {
}
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 {
return err
}
@@ -364,7 +364,7 @@ func isPkgFailed(pkg *BuildPackage) bool {
buildManager.failedMutex.Lock()
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)
defer func(file *os.File) {
check(file.Close())
@@ -433,7 +433,7 @@ func setupChroot() error {
return fmt.Errorf("Unable to update chroot: %v\n%s", err, string(res))
}
} else if os.IsNotExist(err) {
err := os.MkdirAll(conf.Basedir.Chroot, os.ModePerm)
err := os.MkdirAll(conf.Basedir.Chroot, 0755)
check(err)
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) {
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 {
@@ -615,19 +615,24 @@ func syncMarchs() {
func setupMakepkg(march string) {
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)
check(err)
makepkgStr := string(t)
makepkgStr = strings.ReplaceAll(makepkgStr, "-mtune=generic", "")
makepkgStr = strings.ReplaceAll(makepkgStr, "!lto", "")
makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3")
makepkgStr = strings.ReplaceAll(makepkgStr, " check ", " !check ")
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 = 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) {