Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xavie_
Cef
提交
d35e7e10
C
Cef
项目概览
Xavie_
/
Cef
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cef
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d35e7e10
编写于
12月 04, 2018
作者:
R
Richard Wilkes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add executable to install with
上级
4ca37982
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
187 addition
and
0 deletion
+187
-0
main.go
main.go
+187
-0
未找到文件。
main.go
0 → 100644
浏览文件 @
d35e7e10
package
main
import
(
"archive/tar"
"bufio"
"bytes"
"compress/bzip2"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"regexp"
"runtime"
"strings"
"time"
"github.com/richardwilkes/toolbox/atexit"
"github.com/richardwilkes/toolbox/cmdline"
"github.com/richardwilkes/toolbox/xio"
)
const
desiredCEFVersion
=
"3.3538.1852.gcb937fc"
var
(
cefVersionRegex
=
regexp
.
MustCompile
(
`^\s*#define\s+CEF_VERSION\s+"(\d+\.\d+\.\d+\.\w+)"\s*$`
)
installPrefix
=
"/usr/local/cef"
cefPlatform
string
)
func
main
()
{
cmdline
.
CopyrightYears
=
"2018"
cmdline
.
CopyrightHolder
=
"Richard A. Wilkes"
cmdline
.
AppIdentifier
=
"com.trollworks.cef"
cl
:=
cmdline
.
New
(
true
)
cl
.
Description
=
"Downloads and installs the headers and libraries necessary use the github.com/richardwilkes/cef/cef package."
var
needInstall
bool
cl
.
NewBoolOption
(
&
needInstall
)
.
SetSingle
(
'f'
)
.
SetName
(
"force"
)
.
SetUsage
(
"Force an install"
)
cl
.
Parse
(
os
.
Args
[
1
:
])
switch
runtime
.
GOOS
{
case
"darwin"
:
cefPlatform
=
"macosx64"
case
"windows"
:
if
os
.
Getenv
(
"MSYSTEM"
)
!=
"MINGW64"
{
fmt
.
Println
(
"Windows is only supported through the use of MINGW64"
)
atexit
.
Exit
(
1
)
}
cefPlatform
=
"windows64"
installPrefix
=
path
.
Join
(
path
.
Dir
(
os
.
Getenv
(
"MINGW_PREFIX"
)),
installPrefix
)
default
:
fmt
.
Println
(
"Unsupported OS: "
,
runtime
.
GOOS
)
atexit
.
Exit
(
1
)
}
if
!
needInstall
{
var
existingCEFVersion
string
if
f
,
err
:=
os
.
Open
(
path
.
Join
(
installPrefix
,
"include/cef_version.h"
));
err
==
nil
{
s
:=
bufio
.
NewScanner
(
f
)
for
s
.
Scan
()
{
line
:=
s
.
Text
()
if
result
:=
cefVersionRegex
.
FindStringSubmatch
(
line
);
len
(
result
)
==
2
{
existingCEFVersion
=
result
[
1
]
break
}
}
xio
.
CloseIgnoringErrors
(
f
)
}
needInstall
=
existingCEFVersion
!=
desiredCEFVersion
}
if
needInstall
{
fmt
.
Printf
(
"Installing into %s...
\n
"
,
installPrefix
)
if
err
:=
os
.
RemoveAll
(
installPrefix
);
err
!=
nil
{
fmt
.
Printf
(
"Unable to remove old installation at %s
\n
"
,
installPrefix
)
fmt
.
Println
(
err
)
fmt
.
Println
(
"You may need to run this as root."
)
atexit
.
Exit
(
1
)
}
createDir
(
installPrefix
,
0755
)
untar
(
bytes
.
NewBuffer
(
downloadAndUncompressArchive
()))
if
runtime
.
GOOS
==
"windows"
{
dir
:=
path
.
Join
(
path
.
Dir
(
os
.
Getenv
(
"MINGW_PREFIX"
)),
"lib/pkgconfig"
)
createDir
(
dir
,
0755
)
name
:=
path
.
Join
(
dir
,
"cef.pc"
)
f
,
err
:=
os
.
Create
(
name
)
checkFileError
(
err
,
"create"
,
name
)
_
,
err
=
fmt
.
Fprintf
(
f
,
`Name: cef
Description: Chromium Embedded Framework
Version: %[1]s
Requires:
Libs: -L%[2]s/Release -lcef
Cflags: -I%[2]s
`
,
desiredCEFVersion
,
installPrefix
)
checkFileError
(
err
,
"write"
,
name
)
checkFileError
(
f
.
Close
(),
"write"
,
name
)
}
}
atexit
.
Exit
(
0
)
}
func
createDir
(
dir
string
,
mode
os
.
FileMode
)
{
if
err
:=
os
.
MkdirAll
(
dir
,
mode
);
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
"You may need to run this as root."
)
atexit
.
Exit
(
1
)
}
}
func
checkFileError
(
err
error
,
op
,
name
string
)
{
if
err
!=
nil
{
fmt
.
Printf
(
"Unable to %s file %s
\n
"
,
op
,
name
)
fmt
.
Println
(
err
)
atexit
.
Exit
(
1
)
}
}
func
archiveName
()
string
{
return
fmt
.
Sprintf
(
"cef_binary_%s_%s_minimal"
,
desiredCEFVersion
,
cefPlatform
)
}
func
downloadAndUncompressArchive
()
[]
byte
{
client
:=
http
.
Client
{
Timeout
:
10
*
time
.
Minute
}
url
:=
fmt
.
Sprintf
(
"http://opensource.spotify.com/cefbuilds/%s.tar.bz2"
,
archiveName
())
fmt
.
Println
(
" Downloading..."
)
resp
,
err
:=
client
.
Get
(
url
)
if
err
!=
nil
{
fmt
.
Printf
(
"Unable to download CEF archive at %s
\n
"
,
url
)
fmt
.
Println
(
err
)
atexit
.
Exit
(
1
)
}
buffer
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
xio
.
CloseIgnoringErrors
(
resp
.
Body
)
if
err
!=
nil
{
fmt
.
Printf
(
"Unable to download CEF archive at %s
\n
"
,
url
)
fmt
.
Println
(
err
)
atexit
.
Exit
(
1
)
}
if
resp
.
StatusCode
>
299
{
fmt
.
Printf
(
"Unable to download CEF archive at %s
\n
"
,
url
)
fmt
.
Printf
(
"Status: %s
\n
"
,
resp
.
Status
)
atexit
.
Exit
(
1
)
}
fmt
.
Println
(
" Uncompressing..."
)
buffer
,
err
=
ioutil
.
ReadAll
(
bzip2
.
NewReader
(
bytes
.
NewReader
(
buffer
)))
if
err
!=
nil
{
fmt
.
Printf
(
"Unable to uncompress CEF archive from %s
\n
"
,
url
)
fmt
.
Println
(
err
)
atexit
.
Exit
(
1
)
}
return
buffer
}
func
untar
(
in
io
.
Reader
)
{
prefix
:=
archiveName
()
fmt
.
Println
(
" Unarchiving..."
)
r
:=
tar
.
NewReader
(
in
)
for
{
h
,
err
:=
r
.
Next
()
if
err
!=
nil
{
if
err
==
io
.
EOF
{
break
}
fmt
.
Println
(
"Unable to read tar entry from archive"
)
fmt
.
Println
(
err
)
atexit
.
Exit
(
1
)
}
name
:=
strings
.
Trim
(
strings
.
TrimPrefix
(
h
.
Name
,
prefix
),
"/"
)
if
name
!=
""
&&
!
strings
.
Contains
(
name
,
".."
)
{
name
=
path
.
Join
(
installPrefix
,
name
)
switch
h
.
Typeflag
{
case
tar
.
TypeDir
:
createDir
(
name
,
os
.
FileMode
(
h
.
Mode
|
0555
))
case
tar
.
TypeReg
:
buffer
,
err
:=
ioutil
.
ReadAll
(
r
)
checkFileError
(
err
,
"read archive data for"
,
name
)
checkFileError
(
ioutil
.
WriteFile
(
name
,
buffer
,
os
.
FileMode
(
h
.
Mode
|
0444
)),
"write"
,
name
)
default
:
fmt
.
Printf
(
"Unexpected type flag: %d
\n
"
,
h
.
Typeflag
)
atexit
.
Exit
(
1
)
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录