Skip to content

Commit

Permalink
some samll improvements (#626)
Browse files Browse the repository at this point in the history
1. make go plugin higher priority
2. rename and fix bug in build script
  • Loading branch information
yuyang0 committed Nov 7, 2023
1 parent e298668 commit e7ba647
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build-goplugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ -z "$pkg" ]; then
exit 1
fi

if [ -z "$codeDir" ]; then
if [ -z "$codeDIR" ]; then
echo "error: plugin code dir is null"
echo "usage: "
echo " bash build-goplugin.sh pkg codeDir"
Expand Down
30 changes: 15 additions & 15 deletions resource/cobalt/cobalt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ func (m *Manager) LoadPlugins(ctx context.Context, t *testing.T) error {
return nil
}

pluginFiles, err := utils.ListAllExecutableFiles(m.config.ResourcePlugin.Dir)
if err != nil {
logger.Errorf(ctx, err, "failed to list all executable files dir: %+v", m.config.ResourcePlugin.Dir)
return err
}

cache := map[string]struct{}{}
for _, plugin := range m.plugins {
cache[plugin.Name()] = struct{}{}
}

for _, file := range pluginFiles {
logger.Infof(ctx, "load binary plugin: %+v", file)
b, err := binary.NewPlugin(ctx, file, m.config)
sharedLibFiles, err := utils.ListAllSharedLibFiles(m.config.ResourcePlugin.Dir)
if err != nil {
logger.Errorf(ctx, err, "failed to list all share lib files dir: %+v", m.config.ResourcePlugin.Dir)
return err
}

for _, file := range sharedLibFiles {
logger.Infof(ctx, "load go plugin: %+v", file)
b, err := goplugin.NewPlugin(ctx, file, m.config)
if err != nil {
return err
}
Expand All @@ -65,15 +65,15 @@ func (m *Manager) LoadPlugins(ctx context.Context, t *testing.T) error {
}
m.AddPlugins(b)
}
shareLibFiles, err := utils.ListAllShareLibFiles(m.config.ResourcePlugin.Dir)

pluginFiles, err := utils.ListAllExecutableFiles(m.config.ResourcePlugin.Dir)
if err != nil {
logger.Errorf(ctx, err, "failed to list all share lib files dir: %+v", m.config.ResourcePlugin.Dir)
logger.Errorf(ctx, err, "failed to list all executable files dir: %+v", m.config.ResourcePlugin.Dir)
return err
}

for _, file := range shareLibFiles {
logger.Infof(ctx, "load go plugin: %+v", file)
b, err := goplugin.NewPlugin(ctx, file, m.config)
for _, file := range pluginFiles {
logger.Infof(ctx, "load binary plugin: %+v", file)
b, err := binary.NewPlugin(ctx, file, m.config)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ListAllExecutableFiles(basedir string) ([]string, error) {
return files, err
}

func ListAllShareLibFiles(basedir string) ([]string, error) {
func ListAllSharedLibFiles(basedir string) ([]string, error) {
files := []string{}
err := filepath.Walk(basedir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion utils/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestListAllShareLibFiles(t *testing.T) {
_, err = os.Create(filepath.Join(subdir, "bcd1.so"))
assert.NoError(t, err)

fs, err := ListAllShareLibFiles(dir)
fs, err := ListAllSharedLibFiles(dir)
assert.NoError(t, err)
assert.Len(t, fs, 1)
assert.Equal(t, filepath.Join(dir, "bcd.so"), fs[0])
Expand Down

0 comments on commit e7ba647

Please sign in to comment.