Skip to content

Commit

Permalink
rtthread目录按照env-windows调整成为一致了,可以兼容rt-thread工程
Browse files Browse the repository at this point in the history
  • Loading branch information
ComerLater committed Aug 12, 2024
1 parent 681e42f commit 9eb52b4
Show file tree
Hide file tree
Showing 42 changed files with 836 additions and 460 deletions.
119 changes: 0 additions & 119 deletions rtthread/env/cmds/cmd_package/__init__.py

This file was deleted.

Empty file added rtthread/local_pkgs/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
# MarkDown
*.md text eol=crlf

*.bat text eol=crlf
*.ps1 text eol=crlf
File renamed without changes.
15 changes: 15 additions & 0 deletions rtthread/tools/scripts/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"

config TARGET_FILE
string
default ""

config HOSTOS
string
option env="HOSTOS"
default "Linux"

source "$PKGS_DIR/sdk/$HOSTOS/Kconfig"
File renamed without changes.
Empty file.
13 changes: 4 additions & 9 deletions rtthread/env/README.md → rtthread/tools/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ chmod 777 install_ubuntu.sh
```

对于中国大陆用户,请使用以下命令

```
wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_ubuntu.sh
chmod 777 install_ubuntu.sh
Expand All @@ -26,9 +27,10 @@ chmod 777 install_ubuntu.sh
PLAN A: Whenever start the ubuntu system, you need to type command `source ~/.env/env.sh` to activate the environment variables.

or PLAN B: open `~/.bashrc` file, and attach the command `source ~/.env/env.sh` at the end of the file. It will be automatically executed when you log in the ubuntu, and you don't need to execute that command any more.

### Use Env

Please see: https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md#bsp-configuration-menuconfig
Please see: <https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md#bsp-configuration-menuconfig>

## Usage under Windows

Expand Down Expand Up @@ -58,6 +60,7 @@ set-executionpolicy remotesigned
```

注意:

1. Powershell要以管理员身份运行。
2. 将其设置为 remotesigned 后,您可以作为普通用户运行 PowerShell。( After setting it to remotesigned, you can run PowerShell as a normal user.)
3. 一定要关闭杀毒软件,否则安装过程可能会被杀毒软件强退
Expand All @@ -67,11 +70,3 @@ set-executionpolicy remotesigned
方案 A:每次重启 PowerShell 时,都需要输入命令 `~/.env/env.ps1`,以激活环境变量。(PLAN A: Each time you restart PowerShell, you need to enter the command `~/.env/env.ps1` to activate the environment variable.)

方案 B (推荐):打开 `C:\Users\user\Documents\WindowsPowerShell`,如果没有`WindowsPowerShell`则新建该文件夹。新建文件 `Microsoft.PowerShell_profile.ps1`,然后写入 `~/.env/env.ps1` 内容即可,它将在你重启 PowerShell 时自动执行,无需再执行方案 A 中的命令。(or PLAN B (recommended): Open `C:\Users\user\Documents\WindowsPowerShell` and create a new file `Microsoft.PowerShell_profile.ps1`. Then write `~/.env/env.ps1` to the file. It will be executed automatically when you restart PowerShell, without having to execute the command in scenario A.)

如果还需要使 scons 命令有效以及能使用 QEMU,则需要再添加工具链路径和 QEMU 路径。(If you also need the scons command to work and to use QEMU, you need to add the following two commands to add your toolchain path and the QEMU path.)

```
~/.env/env.ps1
$env:RTT_EXEC_PATH="your toolchain path"
$env:path="your QEMU path;$env:path"
```
103 changes: 61 additions & 42 deletions rtthread/env/archive.py → rtthread/tools/scripts/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,70 @@
import zipfile
import pkgsdb
from cmds.cmd_package.cmd_package_utils import is_windows, remove_folder
from tqdm import tqdm


def unpack(archive_filename, bsp_package_path, package_info, package_name):
if ".tar.bz2" in archive_filename:
arch = tarfile.open(archive_filename, "r:bz2")
for tarinfo in arch:
arch.extract(tarinfo, bsp_package_path)
a = tarinfo.name
if not os.path.isdir(os.path.join(bsp_package_path, a)):
if is_windows():
right_path = a.replace('/', '\\')
else:
right_path = a
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
if archive_filename.endswith(".zip"):
return handle_zip_package(archive_filename, bsp_package_path, package_name, package_info)

pkgsdb.save_to_database(a, archive_filename)
arch.close()
if ".tar." in archive_filename:
return handle_tar_package(archive_filename, bsp_package_path, package_name, package_info)

return True


def handle_tar_package(archive_filename, bsp_package_path, package_name, package_info):
package_version = package_info['ver']
package_temp_path = os.path.join(bsp_package_path, "package_temp")

try:
if remove_folder(package_temp_path):
os.makedirs(package_temp_path)
except Exception as e:
logging.warning('Error message : {0}'.format(e))

logging.info("BSP packages path {0}".format(bsp_package_path))
logging.info("BSP package temp path: {0}".format(package_temp_path))
logging.info("archive filename : {0}".format(archive_filename))

try:
flag = True
package_folder_name = ""
package_name_with_version = ""
arch = tarfile.open(archive_filename, "r")
for item in tqdm(arch.getnames()):
arch.extract(item, package_temp_path)
if not os.path.isdir(os.path.join(package_temp_path, item)):
# Gets the folder name and changed folder name only once
if flag:
package_folder_name = item.split('/')[0]
package_name_with_version = package_name + '-' + package_version
flag = False

if ".tar.gz" in archive_filename:
arch = tarfile.open(archive_filename, "r:gz")
for tarinfo in arch:
arch.extract(tarinfo, bsp_package_path)
a = tarinfo.name
if not os.path.isdir(os.path.join(bsp_package_path, a)):
if is_windows():
right_path = a.replace('/', '\\')
right_path = item.replace('/', '\\')
else:
right_path = a
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
pkgsdb.save_to_database(a, archive_filename)
right_path = item

right_name_to_db = right_path.replace(package_folder_name, package_name_with_version, 1)
right_path = os.path.join("package_temp", right_path)
pkgsdb.save_to_database(right_name_to_db, archive_filename, right_path)
arch.close()

if ".zip" in archive_filename:
if not handle_zip_package(archive_filename, bsp_package_path, package_name, package_info):
if not move_package_to_bsp_packages(
package_folder_name, package_name, package_temp_path, package_version, bsp_package_path
):
return False

except Exception as e:
logging.warning('unpack error message : {0}'.format(e))
logging.warning('unpack {0} failed'.format(os.path.basename(archive_filename)))
# remove temp folder and archive file
remove_folder(package_temp_path)
os.remove(archive_filename)
return False

return True


Expand All @@ -89,7 +117,7 @@ def handle_zip_package(archive_filename, bsp_package_path, package_name, package
package_folder_name = ""
package_name_with_version = ""
arch = zipfile.ZipFile(archive_filename, "r")
for item in arch.namelist():
for item in tqdm(arch.namelist()):
arch.extract(item, package_temp_path)
if not os.path.isdir(os.path.join(package_temp_path, item)):
# Gets the folder name and changed folder name only once
Expand All @@ -107,8 +135,9 @@ def handle_zip_package(archive_filename, bsp_package_path, package_name, package
pkgsdb.save_to_database(right_name_to_db, archive_filename, right_path)
arch.close()

if not move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version,
bsp_package_path):
if not move_package_to_bsp_packages(
package_folder_name, package_name, package_temp_path, package_version, bsp_package_path
):
return False
except Exception as e:
logging.warning('unpack error message : {0}'.format(e))
Expand All @@ -121,8 +150,7 @@ def handle_zip_package(archive_filename, bsp_package_path, package_name, package
return True


def move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version,
bsp_packages_path):
def move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version, bsp_packages_path):
"""move package in temp folder to bsp packages folder."""
origin_package_folder_path = os.path.join(package_temp_path, package_folder_name)
package_name_with_version = package_name + '-' + package_version
Expand Down Expand Up @@ -153,7 +181,7 @@ def move_package_to_bsp_packages(package_folder_name, package_name, package_temp
def package_integrity_test(path):
ret = True

if path.find(".zip") != -1:
if path.endswith(".zip"):
try:
if zipfile.is_zipfile(path):
# Test zip again to make sure it's a right zip file.
Expand All @@ -170,17 +198,8 @@ def package_integrity_test(path):
arch.close()
ret = False

# if ".tar.bz2" in path:.
if path.find(".tar.bz2") != -1:
try:
if not tarfile.is_tarfile(path):
ret = False
except Exception as e:
print('Error message:%s' % e)
ret = False

# if ".tar.gz" in path:
if path.find(".tar.gz") != -1:
# if ".tar.*" in path:.
if path.endswith(".tar.bz2") or path.endswith(".tar.gz") or path.endswith(".tar.xz"):
try:
if not tarfile.is_tarfile(path):
ret = False
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@
# 2018-5-28 SummerGift Add copyright information
#

__all__ = ['cmd_package', 'cmd_system', 'cmd_menuconfig']
__all__ = ['cmd_package', 'cmd_system', 'cmd_menuconfig', 'cmd_sdk']

try:
import requests
except ImportError:
print("****************************************\n"
"* Import requests module error.\n"
"* Please install requests module first.\n"
"* pip install step:\n"
"* $ pip install requests\n"
"* command install step:\n"
"* $ sudo apt-get install python-requests\n"
"****************************************\n")
print(
"****************************************\n"
"* Import requests module error.\n"
"* Please install requests module first.\n"
"* pip install step:\n"
"* $ pip install requests\n"
"* command install step:\n"
"* $ sudo apt-get install python-requests\n"
"****************************************\n"
)
Loading

0 comments on commit 9eb52b4

Please sign in to comment.