1 Star 0 Fork 1

liangliang6768/tool_1

forked from liangliang6768/tool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
RK3568_part_compile.py 7.75 KB
一键复制 编辑 原始数据 按行查看 历史
liangliang6768 提交于 2024-05-14 11:15 . 99
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import requests
import json
import os
import subprocess
flag = 0
dep_list = []
indep_list = []
def _wirte_json(file_list,mkdir_text):
data ={
'flag':flag,
'dep_list':dep_list,
'indep_list':indep_list,
'mkdir_text':mkdir_text,
'file_list':file_list
}
json_str = json.dumps(data)
with open('data.json','w') as f:
f.write(json_str)
with open('data.json','r') as f:
print(f.read())
def _get_export_project(export):
list_export = []
if export == 'project_list':
export_button = os.getenv(export)
if export_button == None:
print('The environment variable project_list is none')
return list_export
list_export += export_button.split(',')
return list_export
def _get_export_files(export):
if export == 'PR_FILE_PATHS':
export_button = os.getenv(export)
if export_button == None:
print('The environment variable PR_FILE_PATHS is none')
return export_button
def _get_api_mdkir(param):
post_url = "http://ci.openharmony.cn/api/sple/external/artifact/repo?projectName=openharmony"
fails = 0
while True:
try:
if fails >= 5:
break
headers = {'Content-Type': 'application/json'}
ret = requests.post(post_url, data=param, headers=headers, timeout=10)
if ret.status_code == 200:
mkdir_text = json.loads(ret.text)
else:
continue
except Exception as e:
print(e)
fails += 1
print('Network connection issue, attempting to request again : ',fails)
else:
break
return mkdir_text
def _get_part_list():
list_url = "https://ci.openharmony.cn/api/daily_build/component/check/list"
fails = 0
while True:
try:
if fails >= 5:
break
ret = requests.get(url=list_url, timeout=10)
if ret.status_code == 200:
list_text = json.loads(ret.text)
else:
continue
except:
fails += 1
print('Network connection issue, attempting to request again : ', fails)
else:
break
return list_text
def buildTree(part, list_text):
global flag
if len(part) == 0:
flag = 0
print('Path :matching 0')
return 0
if len(part) == 1:
if list_text.get('data').get('indep_list').count(part[0]) == 1:
flag = 1
indep_list.append(part[0])
print('Path :matching 1')
return 1
elif list_text.get('data').get('dep_list').count(part[0]) == 1:
flag = 2
dep_list.append(part[0])
print('Path :matching 2')
return 1
else:
flag = 0
print('Path :matching 0')
return 1
else:
flag = 3
for part_only in part:
for indep in list_text.get('data').get('indep_list'):
if part_only == indep:
indep_list.append(part_only)
print('Path :matching 3')
break
for indep in list_text.get('data').get('dep_list'):
if part_only == indep:
dep_list.append(part_only)
print('Path :matching 3')
break
return 1
def _get_indep_parts(mkdir_text, file_list):
part = []
for key, value in mkdir_text.items():
if len(value) == 0:
continue
if len(value) == 1:
part += list(value.keys())
else:
for k, v in value.items():
long = len(key)
var = v.find(key.split('_')[0])
if var == -1:
continue
v = v[var+long+1:]
if Judgment(key, v, file_list):
part.append(k)
return part
def Judgment(key, mkdir, file_list):
if file_list.get(key) == None:
return False
for file in file_list.get(key):
if file.startswith(mkdir):
return True
return False
def mvfile():
filename = './code/base/startup/init/bundle.json'
temp_filename = './code/base/startup/init/bundle_temp.json'
char_to_find = '@ohos'
replacement_char = '@build_test'
with open(filename, 'r', encoding='utf-8') as read_file, open(temp_filename, 'w', encoding='utf-8') as write_file:
for line in read_file:
modified_line = line.replace(char_to_find, replacement_char)
write_file.write(modified_line)
os.remove(filename)
os.rename(temp_filename, filename)
def _export_hb_tool(mkdir, part):
script_path = 'export.sh'
script_part = 'hb_build.sh'
os.chmod(script_path, 0o755)
os.chmod(script_part, 0o755)
bash_path = '/bin/bash'
script_mkdir = [mkdir]
command1 = [bash_path, script_path] + script_mkdir
subprocess.run(command1, check=True)
#try:
# mvfile()
#except Exception as e:
# print(f'{e}')
script_args = [part]
command2 = [bash_path, script_part] + script_args
subprocess.run(command2, check=True)
def _find_mkdir(mkdir):
current_directory = os.getcwd()
if os.path.exists(current_directory+'/code/out/default/'+mkdir):
directory = current_directory+'/code/out/default/'+mkdir
command = "cp -r "+directory+"/* ../out/part_so"
subprocess.run(command, shell=True, check=True)
print(directory)
return
mkdir=mkdir.split("/")[1]
if os.path.exists(current_directory+'/code/out/default/'+mkdir):
directory = current_directory+'/code/out/default/'+mkdir
command = "cp -r "+directory+"/* ../out/part_so"
subprocess.run(command, shell=True, check=True)
print(directory)
return
if __name__ == '__main__':
try:
request_param = _get_export_project('project_list')
project_list_json = json.dumps(request_param)
mkdir_text = _get_api_mdkir(project_list_json)
file_list = _get_export_files('PR_FILE_PATHS')
parts = _get_indep_parts(mkdir_text, file_list)
whitelist_parts = _get_part_list()
buildTree(parts, whitelist_parts)
_wirte_json(file_list,mkdir_text)
print(flag)
if flag == 2 or flag == 3:
dep_list += indep_list
_str = ",".join(dep_list)
#subprocess.run('cd ..;bash build/prebuilts_config.sh;cd tool;python initialize.py', shell=True, check=True)
#subprocess.run('cd ..;export PATH=/root/.prebuilts_cache/hpm/node_modules/.bin:$PATH;python build/templates/common/generate_component_package.py -rp ./ -op out/rk3568 -cl '+_str, shell=True, check=True)
subprocess.run('cd ..;python build/templates/common/generate_component_package.py -rp ./ -bt 1 -op out/rk3568 -cl '+_str, shell=True, check=True)
except Exception as e:
print('warning : make hpm package error')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liangliang6768/tool_1.git
[email protected]:liangliang6768/tool_1.git
liangliang6768
tool_1
tool_1
master

搜索帮助