mirror of
https://gitee.com/energye/energy.git
synced 2024-12-01 19:27:43 +08:00
U: 命令行工具 build 命令增加参数: libemfs, args
R: 移除 liblclbinres 内置方式, 方便以后构建liblcl, 兼容低版本到Go1.11 ,更简单使用内置liblcl, 更灵活
This commit is contained in:
parent
01f7787b33
commit
20967d140b
@ -15,7 +15,6 @@ package cef
|
||||
import (
|
||||
"github.com/energye/energy/v2/cef/i18n"
|
||||
"github.com/energye/energy/v2/cef/internal/def"
|
||||
"github.com/energye/energy/v2/cef/internal/version"
|
||||
"github.com/energye/energy/v2/common"
|
||||
"github.com/energye/energy/v2/common/imports"
|
||||
. "github.com/energye/energy/v2/consts"
|
||||
@ -1132,9 +1131,9 @@ func (m *TCEFApplication) LibCefVersion() string {
|
||||
return api.GoStr(r1)
|
||||
}
|
||||
|
||||
// LibVersion 返回 lib-lcl 版本
|
||||
// LibVersion 返回 lib-lcl 版本, TODO 暂时移除
|
||||
func (m *TCEFApplication) LibVersion() string {
|
||||
return version.LibVersion()
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *TCEFApplication) LibCefPath() string {
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"github.com/energye/golcl/pkgs/libname"
|
||||
"github.com/energye/golcl/pkgs/macapp"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// GlobalInit 全局初始化
|
||||
@ -54,7 +53,7 @@ func GlobalInit(libs emfs.IEmbedFS, resources emfs.IEmbedFS) {
|
||||
// 如果使用 liblclbinres 编译则通过该方式加载动态库
|
||||
if dllPath, dllOk := tempdll.CheckAndReleaseDLL(); dllOk {
|
||||
api.SetLoadUILibCallback(func() (path string, ok bool) {
|
||||
if runtime.GOOS == "darwin" {
|
||||
if IsDarwin() {
|
||||
//MacOSX从Frameworks加载
|
||||
libname.LibName = "@executable_path/../Frameworks/" + libname.GetDLLName()
|
||||
} else {
|
||||
@ -86,7 +85,5 @@ func v8init() {
|
||||
if Args.IsMain() || Args.IsRender() {
|
||||
//ipc初始化
|
||||
ipcInit()
|
||||
//bind初始化
|
||||
//bindInit()
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
//----------------------------------------
|
||||
//
|
||||
// Copyright © yanghy. All Rights Reserved.
|
||||
//
|
||||
// Licensed under Apache License Version 2.0, January 2004
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//----------------------------------------
|
||||
|
||||
// Package version Energy framework version config
|
||||
package version
|
||||
|
||||
import "github.com/energye/liblclbinres/v2"
|
||||
|
||||
// LibVersion return lib-lcl version
|
||||
func LibVersion() string {
|
||||
return liblclbinres.LibVersion()
|
||||
}
|
@ -1,51 +1,19 @@
|
||||
### liblcl.xx 动态库字节码存放方式
|
||||
|
||||
### 介绍
|
||||
> 1. 该方式可不必下载`liblcl.xx`动态库, 使用`energy`时,只需安装CEF框架
|
||||
> 2. energy将`liblcl.xx`动态库写入到`liblclbinres/xxx.go`文件中以字节码形式存放
|
||||
> 3. 使用该模式在`liblclbinres/xxx.go`读取`liblcl.xx`动态库字节码并释放到本机目录
|
||||
> 将liblcl打包进执行文件中, 运行时根据TempDllDIR配置释放到指定目录
|
||||
|
||||
### 使用
|
||||
> 1. 编译时增加编译命令参数 `-tags="tempdll [cef version]"`
|
||||
>> `go build -tags="tempdll latest"`
|
||||
> 2. 开发工具中以Goland为例
|
||||
>> 命令行参数 `Go tool arguments` 中配置 `-tags="tempdll latest"`
|
||||
> 3. `TempDLL` 全局变量配置`liblcl.xx`动态库保存目录
|
||||
> 4. `TempDLL` 全局变量根据编译参数`-tags="tempdll latest"`动态初始化
|
||||
#### 该方式在Go编译时将执行文件内置到exe中
|
||||
|
||||
#### 前提条件
|
||||
1. 在Go main函数初始化全局配置时[cef.GlobalInit(libs, resources)]设置libs内嵌对象参数
|
||||
2. 目录名默认 libs
|
||||
|
||||
### 系统
|
||||
```go
|
||||
windows:
|
||||
386: -tags="tempdll latest"
|
||||
amd64: -tags="tempdll latest"
|
||||
windows(Windows 7, 8/8.1 and Windows Server 2012):
|
||||
386: -tags="tempdll 109"
|
||||
amd64: -tags="tempdll 109"
|
||||
linux(gtk3):
|
||||
amd64: -tags="tempdll latest"
|
||||
arm64: -tags="tempdll latest"
|
||||
linux(gtk2):
|
||||
amd64: -tags="tempdll 106"
|
||||
arm64: -tags="tempdll 106"
|
||||
macos:
|
||||
amd64: -tags="tempdll latest"
|
||||
arm64: -tags="tempdll latest"
|
||||
除MacOS都可使用该方式, MacOS采用固定的xxx.app包内加载
|
||||
```
|
||||
|
||||
```go
|
||||
// TempDllDIR
|
||||
// DLL存放目录
|
||||
type TempDllDIR int8
|
||||
|
||||
const (
|
||||
TddInvalid TempDllDIR = iota - 1 // 无效
|
||||
TddTmp // 系统临时目录
|
||||
TddCurrent // 当前执行文件目录
|
||||
TddEnergyHome // Energy环境变量目录, 如果为空,则为系统临时目录
|
||||
TddCustom // 自定义目录, 如果为空,则为系统临时目录
|
||||
)
|
||||
```
|
||||
|
||||
### 发版
|
||||
> 1. `github.com/energye/liblclbinres` vx.x.x 动态库字节码与发行版同步
|
||||
> 2. [github.com/energye/liblclbinres/genbinres](https://github.com/energye/liblclbinres/genbinres) 生成`github.com/energye/liblclbinres`动态库字节码
|
||||
### 配置
|
||||
参考: tempdll.TempDLL
|
@ -8,15 +8,14 @@
|
||||
//
|
||||
//----------------------------------------
|
||||
|
||||
// 动态链接库内置到Go字节码方式
|
||||
// 动态链接库内置到Go执行文件
|
||||
// 如果启用该方式则根据存放目录类型生成动态库并加载
|
||||
// 默认存放在系统临时目录
|
||||
// 通过编译命令 `-tags` 参数指定开启该方式 `go build -tags="tempdll"`
|
||||
// 默认将liblcl释放放在系统临时目录
|
||||
|
||||
package tempdll
|
||||
|
||||
// TempDLL
|
||||
// 通过编译命令 `-tags` 参数控制该变量的初始化 `go build -tags="tempdll"`
|
||||
// 目录释放配置
|
||||
var TempDLL *temdll
|
||||
|
||||
// TempDllDIR
|
||||
@ -32,8 +31,9 @@ const (
|
||||
)
|
||||
|
||||
type temdll struct {
|
||||
dllSaveDirType TempDllDIR
|
||||
dllSaveDir string
|
||||
dllSaveDirType TempDllDIR // 保存类型
|
||||
dllSaveDir string // 保存目录
|
||||
dllFSDir string // dll所在fs目录, 默认libs, 格式为: you/liblcl/path, 目录不允许\\出现
|
||||
}
|
||||
|
||||
// SetDllSaveDirType
|
||||
@ -67,10 +67,18 @@ func (m *temdll) DllSaveDirType() TempDllDIR {
|
||||
}
|
||||
|
||||
// DllSaveDir
|
||||
// 设置动态库保存目录, 默认为空
|
||||
// 返回动态库保存目录, 默认为空
|
||||
func (m *temdll) DllSaveDir() string {
|
||||
if m == nil {
|
||||
return ""
|
||||
}
|
||||
return m.dllSaveDir
|
||||
}
|
||||
|
||||
// SetDllFSDir
|
||||
//
|
||||
// 设置dll所在内置资源目录
|
||||
// 默认libs, 格式为: you/liblcl/path, 目录不允许\\
|
||||
func (m *temdll) SetDllFSDir(dllFSDir string) {
|
||||
m.dllFSDir = dllFSDir
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
//----------------------------------------
|
||||
//
|
||||
// Copyright © yanghy. All Rights Reserved.
|
||||
//
|
||||
// Licensed under Apache License Version 2.0, January 2004
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//----------------------------------------
|
||||
|
||||
//go:build !tempdll
|
||||
// +build !tempdll
|
||||
|
||||
// 编译命令: go build
|
||||
|
||||
package tempdll
|
||||
|
||||
func CheckAndReleaseDLL() (string, bool) {
|
||||
return "", false
|
||||
}
|
@ -8,41 +8,41 @@
|
||||
//
|
||||
//----------------------------------------
|
||||
|
||||
//go:build tempdll
|
||||
// +build tempdll
|
||||
|
||||
// 编译命令: go build -tags="tempdll"
|
||||
|
||||
package tempdll
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"fmt"
|
||||
"github.com/energye/energy/v2/consts"
|
||||
"github.com/energye/golcl/energy/emfs"
|
||||
"github.com/energye/golcl/pkgs/libname"
|
||||
"github.com/energye/liblclbinres/v2"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TempDLL = &temdll{}
|
||||
TempDLL = &temdll{
|
||||
dllFSDir: "libs",
|
||||
}
|
||||
}
|
||||
|
||||
// CheckAndReleaseDLL
|
||||
// 检查动态库并释放
|
||||
func CheckAndReleaseDLL() (string, bool) {
|
||||
if TempDLL == nil || TempDLL.DllSaveDirType() == TddInvalid {
|
||||
if TempDLL == nil || TempDLL.DllSaveDirType() == TddInvalid || emfs.GetLibsFS() == nil {
|
||||
return "", false
|
||||
}
|
||||
// 在内置libs内读取
|
||||
liblclData, err := emfs.GetLibsFS().ReadFile(path.Join(TempDLL.dllFSDir, libname.GetDLLName()))
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
crc32Val := crc32.ChecksumIEEE(liblclData)
|
||||
|
||||
// 动态库保存目录
|
||||
var tempDLLDir string
|
||||
var tempDLLDir = fmt.Sprintf("%s/liblcl/%x", os.TempDir(), crc32Val)
|
||||
switch TempDLL.DllSaveDirType() {
|
||||
case TddTmp: // default
|
||||
tempDLLDir = fmt.Sprintf("%s/liblcl/%x", os.TempDir(), liblclbinres.CRC32Value)
|
||||
case TddCurrent:
|
||||
tempDLLDir = consts.ExeDir
|
||||
case TddEnergyHome:
|
||||
@ -50,14 +50,7 @@ func CheckAndReleaseDLL() (string, bool) {
|
||||
case TddCustom:
|
||||
if TempDLL.DllSaveDir() != "" {
|
||||
tempDLLDir = TempDLL.DllSaveDir()
|
||||
} else {
|
||||
tempDLLDir = fmt.Sprintf("%s/liblcl/%x", os.TempDir(), liblclbinres.CRC32Value)
|
||||
}
|
||||
default:
|
||||
tempDLLDir = fmt.Sprintf("%s/liblcl/%x", os.TempDir(), liblclbinres.CRC32Value)
|
||||
}
|
||||
if tempDLLDir == "" {
|
||||
tempDLLDir = fmt.Sprintf("%s/liblcl/%x", os.TempDir(), liblclbinres.CRC32Value)
|
||||
}
|
||||
|
||||
// create liblcl: $tempdir/liblcl/{crc32}/liblcl.{ext}
|
||||
@ -66,25 +59,25 @@ func CheckAndReleaseDLL() (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
// 设置到tempDllDir
|
||||
// 使用tempdll将最优先从该目录加载
|
||||
// 设置到tempDllDir, 使用tempdll将最优先从该目录加载
|
||||
libname.SetTempDllDir(tempDLLDir)
|
||||
// 如果不是自定义设置目录,在这里设置到DllSaveDir方便使用时获取
|
||||
if TempDLL.DllSaveDirType() != TddCustom {
|
||||
TempDLL.SetDllSaveDir(tempDLLDir)
|
||||
}
|
||||
tempDLLFileName := fmt.Sprintf("%s/%s", tempDLLDir, libname.GetDLLName())
|
||||
// test crc32
|
||||
// 防止liblcl被修改
|
||||
tempDLLFileName := fmt.Sprintf("%s/%s", tempDLLDir, libname.GetDLLName())
|
||||
if fileExists(tempDLLFileName) {
|
||||
bs, err := ioutil.ReadFile(tempDLLFileName)
|
||||
if err == nil {
|
||||
if crc32.ChecksumIEEE(bs) != liblclbinres.CRC32Value {
|
||||
if crc32.ChecksumIEEE(bs) != crc32Val {
|
||||
os.Remove(tempDLLFileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !fileExists(tempDLLFileName) {
|
||||
if err := zlibUnCompressToFile(tempDLLFileName, liblclbinres.LCLBinRes); err != nil {
|
||||
if err := releaseLib(tempDLLFileName, liblclData); err != nil {
|
||||
if os.Remove(tempDLLFileName) != nil {
|
||||
return "", false
|
||||
}
|
||||
@ -93,22 +86,15 @@ func CheckAndReleaseDLL() (string, bool) {
|
||||
return tempDLLFileName, true
|
||||
}
|
||||
|
||||
func zlibUnCompressToFile(destFileName string, input []byte) error {
|
||||
r, err := zlib.NewReader(bytes.NewReader(input))
|
||||
func releaseLib(destFileName string, input []byte) error {
|
||||
var file *os.File
|
||||
file, err := os.OpenFile(destFileName, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
fi, err := os.Create(destFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fi.Close()
|
||||
_, err = io.Copy(fi, r)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
defer file.Close()
|
||||
_, err = file.Write(input)
|
||||
return err
|
||||
}
|
||||
|
||||
func fileExists(path string) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user