简体   繁体   English

如何调试 SCons 脚本

[英]How to debug SCons script

I have a SCons script that I need to debug.我有一个需要调试的 SCons 脚本。 Somewhere down inside of everything that is happening, I have a problem and I need to find out where it is going bad.在正在发生的一切事情的内部某个地方,我遇到了问题,我需要找出问题出在哪里。

I'd like to debug the SCons script, but I'm not sure how to get it set up.我想调试 SCons 脚本,但我不确定如何设置它。 I have both PyCharm and Komodo IDEs, but I couldn't figure out how to make those work.我同时拥有 PyCharm 和 Komodo IDE,但我不知道如何让它们工作。

I've tried this:我试过这个:

scons --debug=pdb <args...>

but that just gets me inside of SCons;但这让我进入了 SCons; I need to be inside of the scripts that I've created that SCons runs.我需要在我创建的 SCons 运行的脚本中。

Can someone show me how to set up PyCharm or Komodo to debug a SCons script?有人可以告诉我如何设置 PyCharm 或 Komodo 来调试 SCons 脚本吗? If that isn't possible, I'm open to other debugging options.如果那不可能,我愿意接受其他调试选项。

In your SConstruct: 在您的SConstruct中:

import pdb
pdb.set_trace()

And you'll drop into the debugger inside your SConstruct (or SConscript if that's what you're trying to debug). 你将进入SConstruct内部的调试器(或SConscript,如果你正在尝试调试)。

From my experience, it is really difficult to debug if you are thinking about using step-by-step debugging in SCons. 根据我的经验,如果您正考虑在SCons中使用逐步调试,则很难进行调试。

My advice is to add a good logging system in your SConstruct file(or adding one). 我的建议是在SConstruct文件中添加一个好的日志记录系统(或添加一个)。 For example, level debug-detailed will log the variables in your custom builder fonction, level debug will only log the most crucial variables, level production(default) will only log when there is a warning or error, in order to minimize the impact on performance. 例如,level debug-detailed将在自定义构建器中记录变量,level debug只会记录最关键的变量,level production(默认)只会在出现警告或错误时记录,以便最大限度地减少对性能。

Personally, I think it's common practice to depend on logging system for debugging in a complicated system. 就个人而言,我认为在复杂系统中依赖日志系统进行调试是很常见的做法。

With PyCharm you can use remote debugging. 使用PyCharm,您可以使用远程调试。

Find the remote debugger package in your PyCharm installation: 在PyCharm安装中找到远程调试器包:

  • Python 2.x: pycharm-debug.egg Python 2.x:pycharm-debug.egg
  • Python 3.x: pycharm-debug-py3k.egg Python 3.x:pycharm-debug-py3k.egg

Install the egg using easy_install. 使用easy_install安装egg。 It should be found in your Python deployment. 它应该在Python部署中找到。 On Windows look into the Scripts folder. 在Windows上查看Scripts文件夹。

Follow the Remote Debugging HowTo. 按照远程调试方式进行操作

Run the Python code you would like to debug in any way you want, it will connect to PyCharm's debug server and stop in the script. 以您想要的任何方式运行您想要调试的Python代码,它将连接到PyCharm的调试服务器并在脚本中停止。

Screenshot of debugging Godot's SConstruct file: 调试Godot的SConstruct文件的屏幕截图: 在此输入图像描述

Scons was executed from a Visual Studio command line in order to receive the right environment variables for the build (not from PyCharm). Scons是从Visual Studio命令行执行的,以便为构建接收正确的环境变量(而不是来自PyCharm)。

UPDATE: A simpler solution is to add a run configuration directly for scons.py itself. 更新:更简单的解决方案是直接为scons.py本身添加运行配置。 You can issue a SET command in an Visual Studio command prompt, copy all environment variables printed and paste into the Environment setting of the run configuration inside PyCharm. 您可以在Visual Studio命令提示符中发出SET命令,复制打印的所有环境变量并粘贴到PyCharm内运行配置的Environment设置中。 With that configuration you can debug the whole scons based build, including your SConstruct file. 使用该配置,您可以调试整个基于scons的构建,包括SConstruct文件。

If you use VS Code, you can debug SCons script like a usual python script, just create a configuration in .vscode/launch.json :如果你使用 VS Code,你可以像通常的 python 脚本一样调试 SCons 脚本,只需在.vscode/launch.json中创建一个配置:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: SCons",
            "type": "python",
            "request": "launch",
            "program": "c:/apps/python38/lib/site-packages/SCons/__main__.py",
            "args": [],
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}

The program should be set to the path where your SCons is installed.program应设置为安装 SCons 的路径。 You can get it by scons --version .您可以通过scons --version获取它。 Don't forget to add __main__.py as the entry script.不要忘记添加__main__.py作为入口脚本。 It's recommended to set justMyCode to false so that you can set breakpoints at Scons' source code.建议将justMyCode设置为false ,以便您可以在 Scons 的源代码处设置断点。

You can set arguments in args if necessary:如有必要,您可以在args中设置 arguments:

            "args": [
                "--tree=prune",
                "--debug=explain",
                "hello.elf"
            ],

VSCode brings debugging features such as inspecting variables, setting breakpoints, and other activities with GUI. VSCode 带来了调试功能,例如检查变量、设置断点和其他带有 GUI 的活动。 For details, goto Python debugging in VS Code具体在VS Code中调试Python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM