1 Star 1 Fork 0

Spock/vmake

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
compiler.go 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
package plugin
import (
"fmt"
"os"
"path/filepath"
"gitee.com/spock2300/vmake/internal/fs"
"gitee.com/spock2300/vmake/internal/gocompile"
)
type CompileResult struct {
gocompile.CompileResult
PluginDir string
PluginName string
}
func Compile(pluginDir string, force bool) CompileResult {
info, err := LoadPluginInfo(pluginDir)
if err != nil {
return CompileResult{CompileResult: gocompile.NewFailResult(err), PluginDir: pluginDir}
}
entryPath := filepath.Join(pluginDir, info.Entry)
if !fs.FileExists(entryPath) {
return CompileResult{CompileResult: gocompile.NewFailResult(fmt.Errorf("entry file not found: %s", entryPath)), PluginDir: pluginDir, PluginName: info.Name}
}
outputPath := filepath.Join(pluginDir, "plugin.so")
if force {
os.Remove(outputPath)
}
if fs.FileExists(outputPath) {
return CompileResult{CompileResult: gocompile.NewOkResult(outputPath), PluginDir: pluginDir, PluginName: info.Name}
}
entryFile := filepath.Base(filepath.Join(pluginDir, "src", "main.go"))
workDir := filepath.Dir(entryPath)
opts := gocompile.PluginOptions{
WorkDir: workDir,
OutputPath: outputPath,
EntryFile: entryFile,
ModuleName: info.Name,
Prefix: "vmake_plugin_",
}
if err := gocompile.CompilePlugin(opts); err != nil {
return CompileResult{CompileResult: gocompile.NewFailResultAt(err, outputPath), PluginDir: pluginDir, PluginName: info.Name}
}
return CompileResult{CompileResult: gocompile.NewOkResult(outputPath), PluginDir: pluginDir, PluginName: info.Name}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/spock2300/vmake.git
git@gitee.com:spock2300/vmake.git
spock2300
vmake
vmake
v1.0.1

搜索帮助