forked from Plemya-x/ALR
feat: add import info from alr-repo.toml
This commit is contained in:
@ -24,6 +24,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/logger"
|
||||
@ -32,6 +33,7 @@ import (
|
||||
var pluginMap = map[string]plugin.Plugin{
|
||||
"script-executor": &ScriptExecutorPlugin{},
|
||||
"installer": &InstallerExecutorPlugin{},
|
||||
"repos": &ReposExecutorPlugin{},
|
||||
}
|
||||
|
||||
var HandshakeConfig = plugin.HandshakeConfig{
|
||||
@ -57,6 +59,19 @@ func setCommonCmdEnv(cmd *exec.Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetPluginServeCommonConfig() *plugin.ServeConfig {
|
||||
return &plugin.ServeConfig{
|
||||
HandshakeConfig: HandshakeConfig,
|
||||
Logger: hclog.New(&hclog.LoggerOptions{
|
||||
Name: "plugin",
|
||||
Output: os.Stderr,
|
||||
Level: hclog.Trace,
|
||||
JSONFormat: true,
|
||||
DisableTime: true,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
func GetSafeInstaller() (InstallerExecutor, func(), error) {
|
||||
return getSafeExecutor[InstallerExecutor]("_internal-installer", "installer")
|
||||
}
|
||||
@ -65,6 +80,10 @@ func GetSafeScriptExecutor() (ScriptExecutor, func(), error) {
|
||||
return getSafeExecutor[ScriptExecutor]("_internal-safe-script-executor", "script-executor")
|
||||
}
|
||||
|
||||
func GetSafeReposExecutor() (ReposExecutor, func(), error) {
|
||||
return getSafeExecutor[ReposExecutor]("_internal-repos", "repos")
|
||||
}
|
||||
|
||||
func getSafeExecutor[T any](subCommand, pluginName string) (T, func(), error) {
|
||||
var err error
|
||||
|
||||
|
@ -21,9 +21,10 @@ import (
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
|
||||
)
|
||||
|
||||
//go:generate go run ../../generators/plugin-generator InstallerExecutor ScriptExecutor
|
||||
//go:generate go run ../../generators/plugin-generator InstallerExecutor ScriptExecutor ReposExecutor
|
||||
|
||||
// The Executors interfaces must use context.Context as the first parameter,
|
||||
// because the plugin-generator cannot generate code without it.
|
||||
@ -53,3 +54,7 @@ type ScriptExecutor interface {
|
||||
basePkg string,
|
||||
) ([]*BuiltDep, error)
|
||||
}
|
||||
|
||||
type ReposExecutor interface {
|
||||
PullOneAndUpdateFromConfig(ctx context.Context, repo *types.Repo) (types.Repo, error)
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"context"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
)
|
||||
|
||||
@ -67,6 +68,26 @@ func (p *ScriptExecutorPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
|
||||
return &ScriptExecutorRPCServer{Impl: p.Impl}, nil
|
||||
}
|
||||
|
||||
type ReposExecutorPlugin struct {
|
||||
Impl ReposExecutor
|
||||
}
|
||||
|
||||
type ReposExecutorRPCServer struct {
|
||||
Impl ReposExecutor
|
||||
}
|
||||
|
||||
type ReposExecutorRPC struct {
|
||||
client *rpc.Client
|
||||
}
|
||||
|
||||
func (p *ReposExecutorPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
|
||||
return &ReposExecutorRPC{client: c}, nil
|
||||
}
|
||||
|
||||
func (p *ReposExecutorPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
|
||||
return &ReposExecutorRPCServer{Impl: p.Impl}, nil
|
||||
}
|
||||
|
||||
type InstallerExecutorInstallLocalArgs struct {
|
||||
Paths []string
|
||||
Opts *manager.Opts
|
||||
@ -316,3 +337,33 @@ func (s *ScriptExecutorRPCServer) ExecuteSecondPass(args *ScriptExecutorExecuteS
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ReposExecutorPullOneAndUpdateFromConfigArgs struct {
|
||||
Repo *types.Repo
|
||||
}
|
||||
|
||||
type ReposExecutorPullOneAndUpdateFromConfigResp struct {
|
||||
Result0 types.Repo
|
||||
}
|
||||
|
||||
func (s *ReposExecutorRPC) PullOneAndUpdateFromConfig(ctx context.Context, repo *types.Repo) (types.Repo, error) {
|
||||
var resp *ReposExecutorPullOneAndUpdateFromConfigResp
|
||||
err := s.client.Call("Plugin.PullOneAndUpdateFromConfig", &ReposExecutorPullOneAndUpdateFromConfigArgs{
|
||||
Repo: repo,
|
||||
}, &resp)
|
||||
if err != nil {
|
||||
return types.Repo{}, err
|
||||
}
|
||||
return resp.Result0, nil
|
||||
}
|
||||
|
||||
func (s *ReposExecutorRPCServer) PullOneAndUpdateFromConfig(args *ReposExecutorPullOneAndUpdateFromConfigArgs, resp *ReposExecutorPullOneAndUpdateFromConfigResp) error {
|
||||
result0, err := s.Impl.PullOneAndUpdateFromConfig(context.Background(), args.Repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*resp = ReposExecutorPullOneAndUpdateFromConfigResp{
|
||||
Result0: result0,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
37
internal/build/repos_executor.go
Normal file
37
internal/build/repos_executor.go
Normal file
@ -0,0 +1,37 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 The ALR Authors
|
||||
//
|
||||
// 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/>.
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/repos"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
|
||||
)
|
||||
|
||||
type reposExecutor struct{ r *repos.Repos }
|
||||
|
||||
func NewRepos(r *repos.Repos) ReposExecutor {
|
||||
return &reposExecutor{r}
|
||||
}
|
||||
|
||||
func (r *reposExecutor) PullOneAndUpdateFromConfig(ctx context.Context, repo *types.Repo) (types.Repo, error) {
|
||||
if err := r.r.PullOneAndUpdateFromConfig(ctx, repo); err != nil {
|
||||
return *repo, err
|
||||
}
|
||||
return *repo, nil
|
||||
}
|
Reference in New Issue
Block a user