Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [toolchain] migrate toolchain detection from shell to python #1007

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

Kakueeen
Copy link
Contributor

Refactored the toolchain detection mechanism by replacing the shell script
with a Python implementation for better maintainability and extensibility.

  • Replaced toolchain.sh with main.py as the detection script
  • Updated file paths and script execution logic in toolchain.cpp

Log: refactor toolchain detection implementation

Copy link

  • 检测到敏感词export变动
详情
    {
    "export": {
        "src/scripts/toolchain.sh": {
            "a": [
                "export TOOLCHAINS=$1"
            ]
        }
    }
}

Copy link

  • 检测到敏感词export变动
详情
    {
    "export": {
        "src/scripts/toolchain.sh": {
            "a": [
                "export TOOLCHAINS=$1"
            ]
        }
    }
}

Refactored the toolchain detection mechanism by replacing the shell script
with a Python implementation for better maintainability and extensibility.

- Replaced toolchain.sh with main.py as the detection script
- Updated file paths and script execution logic in toolchain.cpp

Log: refactor toolchain detection implementation
Copy link

  • 检测到敏感词export变动
详情
    {
    "export": {
        "src/scripts/toolchain.sh": {
            "a": [
                "export TOOLCHAINS=$1"
            ]
        }
    }
}

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 命名规范

    • toolchain.sh脚本中,变量名K_HOSTK_TOOLCHAINFILEK_TOOLCHAINFILEK_TOOLCHAINFILE_OS不符合命名规范,建议使用驼峰命名法或下划线命名法,例如K_HOST_TOOLCHAIN_FILE_OS
  2. 代码重复

    • toolchain.sh脚本中存在大量重复代码,例如probe_c_compilersprobe_cxx_compilers等函数,建议将这些重复代码提取到公共函数中,减少代码冗余。
  3. 错误处理

    • toolchain.sh脚本中缺少对命令执行失败的处理,例如ProcessUtil::execute函数执行失败时,应该有相应的错误处理逻辑。
  4. 路径拼接

    • toolchain.cpp中,拼接路径时使用了QDir::separator(),这是一个好的做法,但是应该确保路径拼接的健壮性,例如检查路径是否存在。
  5. 日志记录

    • toolchain.cpp中使用了qInfo()进行日志记录,这是一个好的做法,但是应该确保日志级别和日志内容符合项目的日志策略。
  6. 代码风格

    • toolchain.cpp中,QStringList args { script, "-o", outputFile };这行代码使用了C++11的列表初始化,这是一个好的做法,但是应该确保整个项目都遵循相同的代码风格。
  7. 安全性

    • toolchain.sh脚本中使用了find命令,应该确保search_pathprefix变量是安全的,避免命令注入攻击。
  8. 性能优化

    • toolchain.sh脚本中,probe_c_compilersprobe_cxx_compilers等函数中使用了find命令,这个命令可能会比较耗时,建议使用更高效的文件系统操作方法。
  9. 异常处理

    • main.py脚本中,scan_system方法中使用了try-except来捕获异常,这是一个好的做法,但是应该确保异常处理逻辑是合理的,例如记录日志或者通知用户。
  10. 代码注释

    • main.py脚本中,ToolchainScanner类的scan_system方法缺少注释,应该添加注释说明这个方法的作用和实现细节。
  11. 配置文件

    • toolchain_config.json配置文件中,每个工具链的类型和解析器配置应该有详细的注释,以便其他开发者理解配置的含义。
  12. 代码组织

    • toolchain_factory.py脚本中,_load_parsers方法中使用了动态导入模块的方法,这是一个好的做法,但是应该确保模块路径是正确的,避免导入错误。
  13. 代码可读性

    • toolchain_factory.py脚本中,_load_config方法中使用了大量的if-else语句,建议使用字典映射或者工厂模式来简化代码逻辑。
  14. 依赖管理

    • toolchain_factory.py脚本中,_load_parsers方法中使用了动态导入模块的方法,应该确保所有依赖的模块都已经安装,避免运行时错误。
  15. 代码测试

    • toolchain_factory.py脚本中,应该添加单元测试来验证ToolchainFactory类的功能是否正常,例如测试get_supported_typescreate_toolchain方法。

以上是针对代码审查意见的详细说明,希望能够对您的代码改进有所帮助。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deepin-mozart, Kakueeen

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-mozart
Copy link
Contributor

/retest

Copy link

github-actions bot commented Dec 2, 2024

  • 检测到敏感词export变动
详情
    {
    "export": {
        "src/scripts/toolchain.sh": {
            "a": [
                "export TOOLCHAINS=$1"
            ]
        }
    }
}

@deepin-mozart deepin-mozart merged commit fd5aeae into linuxdeepin:master Dec 2, 2024
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants