Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Build Lite
提交
fe2a638e
B
Build Lite
项目概览
OpenHarmony
/
Build Lite
大约 1 年 前同步成功
通知
22
Star
24
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Build Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fe2a638e
编写于
7月 29, 2021
作者:
O
openharmony_ci
提交者:
Gitee
7月 29, 2021
浏览文件
操作
浏览文件
下载
差异文件
!209 auto download clang, gn and ninja
Merge pull request !209 from yangming_ha/master
上级
f7de9467
de554e92
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
119 addition
and
37 deletion
+119
-37
hb/__init__.py
hb/__init__.py
+21
-1
hb/common/config.py
hb/common/config.py
+45
-34
hb/common/utils.py
hb/common/utils.py
+50
-0
setup.py
setup.py
+3
-2
未找到文件。
hb/__init__.py
浏览文件 @
fe2a638e
...
...
@@ -42,4 +42,24 @@ CONFIG_STRUCT = {
"device_path"
:
None
,
"patch_cache"
:
None
}
VERSION
=
'0.4.2'
VERSION
=
'0.4.3'
BUILD_TOOLS_CFG
=
{
"Linux"
:
{
"build_tools_path"
:
'prebuilts/build-tools/linux-x86/bin'
,
"gn"
:
'https://repo.huaweicloud.com/harmonyos/compiler/gn/'
+
\
'1717/linux/gn-linux-x86-1717.tar.gz'
,
"ninja"
:
'https://repo.huaweicloud.com/harmonyos/compiler/ninja/'
+
\
'1.10.1/linux/ninja-linux-x86-1.10.1.tar.gz'
,
"clang"
:
'https://repo.huaweicloud.com/harmonyos/compiler/clang/'
+
\
'10.0.1-62608/linux/llvm.tar.gz'
},
"Windows"
:
{
"build_tools_path"
:
'prebuilts
\\
build-tools
\\
win-x86
\\
bin'
,
"gn"
:
'https://repo.huaweicloud.com/harmonyos/compiler/gn/'
+
\
'1744/windows/gn-windows-amd64.zip'
,
"ninja"
:
'https://repo.huaweicloud.com/harmonyos/compiler/ninja/'
+
\
'1.9.0/windows/ninja-win.zip'
}
}
hb/common/config.py
浏览文件 @
fe2a638e
...
...
@@ -21,10 +21,13 @@ from distutils.spawn import find_executable
from
hb
import
CONFIG_JSON
from
hb
import
CONFIG_STRUCT
from
hb
import
BUILD_TOOLS_CFG
from
hb.common.utils
import
read_json_file
from
hb.common.utils
import
dump_json_file
from
hb.common.utils
import
Singleton
from
hb.common.utils
import
OHOSException
from
hb.common.utils
import
download_tool
from
hb.common.utils
import
makedirs
class
Config
(
metaclass
=
Singleton
):
...
...
@@ -41,6 +44,7 @@ class Config(metaclass=Singleton):
self
.
_patch_cache
=
config_content
.
get
(
'patch_cache'
,
None
)
self
.
_out_path
=
None
self
.
fs_attr
=
set
()
self
.
platform
=
platform
.
system
()
@
property
def
root_path
(
self
):
...
...
@@ -157,45 +161,41 @@ class Config(metaclass=Singleton):
@
property
def
build_tools_path
(
self
):
platform_name
=
platform
.
system
()
if
platform_name
==
'Linux'
:
return
os
.
path
.
join
(
self
.
root_path
,
'prebuilts'
,
'build-tools'
,
'linux-x86'
,
'bin'
)
if
platform_name
==
'Windows'
:
return
os
.
path
.
join
(
self
.
root_path
,
'prebuilts'
,
'build-tools'
,
'win-x86'
,
'bin'
)
raise
OHOSException
(
f
'unidentified platform:
{
platform_name
}
'
)
try
:
tools_path
=
BUILD_TOOLS_CFG
[
self
.
platform
][
'build_tools_path'
]
return
os
.
path
.
join
(
self
.
root_path
,
tools_path
)
except
KeyError
:
raise
OHOSException
(
f
'unidentified platform:
{
self
.
platform
}
'
)
@
property
def
gn_path
(
self
):
repo_gn_path
=
os
.
path
.
join
(
self
.
build_tools_path
,
'gn'
)
# gn exist.
if
os
.
path
.
isfile
(
repo_gn_path
):
return
repo_gn_path
env_gn_path
=
find_executable
(
'gn'
)
if
env_gn_path
is
not
None
:
return
env_gn_path
# gn not install, download and extract it.
makedirs
(
self
.
build_tools_path
,
exist_ok
=
True
)
raise
OHOSException
(
'gn not found, install it please'
)
gn_url
=
BUILD_TOOLS_CFG
[
self
.
platform
].
get
(
'gn'
)
gn_dst
=
os
.
path
.
join
(
self
.
build_tools_path
,
'gn_pkg'
)
download_tool
(
gn_url
,
gn_dst
,
tgt_dir
=
self
.
build_tools_path
)
return
repo_gn_path
@
property
def
ninja_path
(
self
):
repo_ninja_path
=
os
.
path
.
join
(
self
.
build_tools_path
,
'ninja'
)
# ninja exist.
if
os
.
path
.
isfile
(
repo_ninja_path
):
return
repo_ninja_path
env_ninja_path
=
find_executable
(
'ninja'
)
if
env_ninja_path
is
not
None
:
return
env_ninja_path
# ninja not install, download and extract.
ninja_url
=
BUILD_TOOLS_CFG
[
self
.
platform
].
get
(
'ninja'
)
ninja_dst
=
os
.
path
.
join
(
self
.
build_tools_path
,
'ninja_pkg'
)
download_tool
(
ninja_url
,
ninja_dst
,
tgt_dir
=
self
.
build_tools_path
)
r
aise
OHOSException
(
'ninja not found, install it please'
)
r
eturn
repo_ninja_path
@
property
def
clang_path
(
self
):
...
...
@@ -204,19 +204,30 @@ class Config(metaclass=Singleton):
'ohos'
,
'linux-x86_64'
,
'llvm'
)
# clang exist
if
os
.
path
.
isdir
(
repo_clang_path
):
return
f
'//
{
repo_clang_path
}
'
env_clang_bin_path
=
find_executable
(
'clang'
)
if
env_clang_bin_path
is
not
None
:
env_clang_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
env_clang_bin_path
,
os
.
pardir
,
os
.
pardir
))
if
os
.
path
.
basename
(
env_clang_path
)
==
'llvm'
:
return
env_clang_path
raise
OHOSException
(
'clang not found, install it please'
)
# clang installed manually or auto download
else
:
# already installed manually
env_clang_bin_path
=
find_executable
(
'clang'
)
if
env_clang_bin_path
is
not
None
:
env_clang_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
env_clang_bin_path
,
os
.
pardir
,
os
.
pardir
))
if
os
.
path
.
basename
(
env_clang_path
)
==
'llvm'
:
return
env_clang_path
# need auto download and extract clang.
clang_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
repo_clang_path
,
os
.
pardir
))
makedirs
(
clang_path
,
exist_ok
=
True
)
clang_url
=
BUILD_TOOLS_CFG
[
self
.
platform
].
get
(
'clang'
)
clang_dst
=
os
.
path
.
join
(
clang_path
,
'clang_pkg'
)
download_tool
(
clang_url
,
clang_dst
,
tgt_dir
=
clang_path
)
return
f
'//
{
repo_clang_path
}
'
@
property
def
patch_cache
(
self
):
...
...
hb/common/utils.py
浏览文件 @
fe2a638e
...
...
@@ -25,6 +25,9 @@ import json
from
collections
import
namedtuple
import
yaml
from
datetime
import
datetime
import
requests
import
tarfile
import
zipfile
def
encode
(
data
,
encoding
=
'utf-8'
):
...
...
@@ -230,3 +233,50 @@ class Singleton(type):
class
OHOSException
(
Exception
):
pass
def
download_tool
(
url
,
dst
,
tgt_dir
=
None
):
try
:
res
=
requests
.
get
(
url
,
stream
=
True
,
timeout
=
(
5
,
9
))
except
OSError
:
raise
OHOSException
(
f
'download
{
url
}
timeout!'
)
if
res
.
status_code
==
200
:
hb_info
(
f
'Downloading
{
url
}
...'
)
else
:
hb_error
(
f
'Downloading
{
url
}
failed with code:
{
res
.
status_code
}
!'
)
return
res
.
status_code
total_size
=
int
(
res
.
headers
[
'content-length'
])
download_size
=
0
download_percent
=
0
try
:
with
open
(
dst
,
"wb"
)
as
f
:
for
chunk
in
res
.
iter_content
(
chunk_size
=
1024
):
if
chunk
:
f
.
write
(
chunk
)
download_size
+=
len
(
chunk
)
download_percent
=
round
(
float
(
download_size
/
total_size
*
100
),
2
)
print
(
'Progress: %s%%
\r
'
%
download_percent
,
end
=
' '
)
hb_info
(
'Download complete!'
)
except
OSError
:
raise
OHOSException
(
f
'
{
url
}
download failed, please install it manually!'
)
if
tgt_dir
is
not
None
:
extract_tool
(
dst
,
tgt_dir
)
def
extract_tool
(
src
,
tgt_dir
):
hb_info
(
f
'Extracting to
{
tgt_dir
}
, please wait...'
)
try
:
if
tarfile
.
is_tarfile
(
src
):
ef
=
tarfile
.
open
(
src
)
elif
zipfile
.
is_zipfile
(
src
):
ef
=
zipfile
.
ZipFile
(
src
)
else
:
raise
OHOSException
(
f
'Extract file type not support!'
)
ef
.
extractall
(
tgt_dir
)
ef
.
close
()
except
OSError
:
raise
OHOSException
(
f
'
{
src
}
extract failed, please install it manually!'
)
\ No newline at end of file
setup.py
浏览文件 @
fe2a638e
...
...
@@ -43,11 +43,12 @@ setup(
install_requires
=
[
'prompt_toolkit==1.0.14'
,
'kconfiglib>=14.1.0'
,
'PyYAML'
'PyYAML'
,
'requests'
],
entry_points
=
{
'console_scripts'
:
[
'hb=hb.__main__:main'
,
]
},
)
\ No newline at end of file
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录