7

I have a SCons script that I need to debug. 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. I have both PyCharm and Komodo IDEs, but I couldn't figure out how to make those work.

I've tried this:

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

but that just gets me inside of SCons; I need to be inside of the scripts that I've created that SCons runs.

Can someone show me how to set up PyCharm or Komodo to debug a SCons script? If that isn't possible, I'm open to other debugging options.

jlconlin
  • 14,206
  • 22
  • 72
  • 105
  • possible duplicate of [How to get executable in debug mode using scons](http://stackoverflow.com/questions/15681961/how-to-get-executable-in-debug-mode-using-scons) – Paul Sweatte Sep 04 '14 at 18:03
  • 1
    Not a duplicate as suggested above. The reference article is about building a debug binary. The question is about debugging SConscripts/SConstructs/or other SCons logic. – bdbaddog Sep 20 '16 at 20:44

4 Answers4

2

In your 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).

bdbaddog
  • 3,357
  • 2
  • 22
  • 33
1

With PyCharm you can use remote debugging.

Find the remote debugger package in your PyCharm installation:

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

Install the egg using easy_install. It should be found in your Python deployment. On Windows look into the Scripts folder.

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.

Screenshot of debugging Godot's SConstruct file: enter image description here

Scons was executed from a Visual Studio command line in order to receive the right environment variables for the build (not from PyCharm).

UPDATE: A simpler solution is to add a run configuration directly for scons.py itself. 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. With that configuration you can debug the whole scons based build, including your SConstruct file.

fviktor
  • 2,861
  • 20
  • 24
1

If you use VS Code, you can debug SCons script like a usual python script, just create a configuration in .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. You can get it by scons --version. Don't forget to add __main__.py as the entry script. It's recommended to set justMyCode to false so that you can set breakpoints at Scons' source code.

You can set arguments in args if necessary:

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

VSCode brings debugging features such as inspecting variables, setting breakpoints, and other activities with GUI. For details, goto Python debugging in VS Code

Patrick Z
  • 31
  • 2
0

From my experience, it is really difficult to debug if you are thinking about using step-by-step debugging in SCons.

My advice is to add a good logging system in your SConstruct file(or adding one). 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.

Personally, I think it's common practice to depend on logging system for debugging in a complicated system.

Lucas
  • 75
  • 8