lure/build.go

101 lines
2.6 KiB
Go
Raw Permalink Normal View History

2022-09-26 19:28:21 +00:00
/*
* LURE - Linux User REpository
2023-09-20 22:38:22 +00:00
* Copyright (C) 2023 Elara Musayelyan
2022-09-26 19:28:21 +00:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-09-25 21:00:15 +00:00
package main
import (
"os"
"path/filepath"
"github.com/urfave/cli/v2"
2023-10-08 00:34:39 +00:00
"lure.sh/lure/internal/config"
"lure.sh/lure/internal/osutils"
"lure.sh/lure/internal/types"
"lure.sh/lure/pkg/build"
"lure.sh/lure/pkg/loggerctx"
"lure.sh/lure/pkg/manager"
"lure.sh/lure/pkg/repos"
2022-09-25 21:00:15 +00:00
)
2023-09-19 21:28:05 +00:00
var buildCmd = &cli.Command{
Name: "build",
Usage: "Build a local package",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "script",
Aliases: []string{"s"},
Value: "lure.sh",
Usage: "Path to the build script",
},
&cli.StringFlag{
Name: "package",
Aliases: []string{"p"},
Usage: "Name of the package to build and its repo (example: default/go-bin)",
},
&cli.BoolFlag{
Name: "clean",
Aliases: []string{"c"},
Usage: "Build package from scratch even if there's an already built package available",
},
},
Action: func(c *cli.Context) error {
2023-10-06 21:21:12 +00:00
ctx := c.Context
log := loggerctx.From(ctx)
2023-09-19 21:28:05 +00:00
script := c.String("script")
if c.String("package") != "" {
2023-10-06 21:21:12 +00:00
script = filepath.Join(config.GetPaths(ctx).RepoDir, c.String("package"), "lure.sh")
}
2022-09-25 21:00:15 +00:00
2023-10-06 21:21:12 +00:00
err := repos.Pull(ctx, config.Config(ctx).Repos)
if err != nil {
2023-09-19 21:28:05 +00:00
log.Fatal("Error pulling repositories").Err(err).Send()
}
2023-09-19 21:28:05 +00:00
mgr := manager.Detect()
if mgr == nil {
log.Fatal("Unable to detect a supported package manager on the system").Send()
}
2023-10-06 21:21:12 +00:00
pkgPaths, _, err := build.BuildPackage(ctx, types.BuildOpts{
2023-09-19 21:28:05 +00:00
Script: script,
Manager: mgr,
Clean: c.Bool("clean"),
Interactive: c.Bool("interactive"),
})
if err != nil {
2023-09-19 21:28:05 +00:00
log.Fatal("Error building package").Err(err).Send()
}
2023-09-19 21:28:05 +00:00
wd, err := os.Getwd()
if err != nil {
2023-09-19 21:28:05 +00:00
log.Fatal("Error getting working directory").Err(err).Send()
}
2023-09-19 21:28:05 +00:00
for _, pkgPath := range pkgPaths {
name := filepath.Base(pkgPath)
err = osutils.Move(pkgPath, filepath.Join(wd, name))
2022-09-25 21:00:15 +00:00
if err != nil {
2023-09-19 21:28:05 +00:00
log.Fatal("Error moving the package").Err(err).Send()
2022-09-25 21:00:15 +00:00
}
2022-11-29 21:30:58 +00:00
}
2022-09-25 21:00:15 +00:00
return nil
2023-09-19 21:28:05 +00:00
},
2022-12-01 18:53:03 +00:00
}