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

BuildInfoCollector.py does not gather any information and fails #44

Open
alexander-titov opened this issue Apr 21, 2017 · 8 comments
Open

Comments

@alexander-titov
Copy link

Hi,

Adding BuildInfoCollector.py to my scons command line leads to a failure.

>/bin/scons/2.5.0/bin/scons -f SConstruct -f BuildInfoCollector.py
scons: Reading SConscript files ...
USER_INCLUDES = []
TypeError: 'NoneType' object is not subscriptable:
  File "/users/atitov/repos/master/BuildInfoCollector.py", line 226:
    write_build_infos(includes, macros, env)
  File "/users/atitov/repos/master/BuildInfoCollector.py", line 186:
    print 'SYS_C_INCLUDES = [%s]' % to_string(collect_sys_includes('cc', environ), environ)
  File "/users/atitov/repos/master/BuildInfoCollector.py", line 91:
    cc_output = invoke_compiler(lang, environ)
  File "/users/atitov/repos/master/BuildInfoCollector.py", line 76:
    [get_compiler(environ), '-v', get_gcc_lang_param(lang)] + get_compiler_flags(lang, environ) + [in_path, '-o', out_path],
  File "/users/atitov/repos/master/BuildInfoCollector.py", line 113:
    if environ['PLATFORM'] == 'win32' and environ['CXX'] == 'g++':

Without BuildInfoCollector.py everything works well.

As I understand the problem is in the method collect_build_infos
(prints were added by me):

def collect_build_infos(super_nodes):
    print('super_nodes', type(super_nodes), super_nodes)
    def no_scan_fun(node, _):
        return node.children(scan=0)

    children_fun = (no_scan_fun if has_build_targets() else SCons.Node.get_children)
    includes, macros = set(), set()
    compiler_env = None

    for snode in super_nodes:
        print ('snode', type(snode), snode)
        walker = SCons.Node.Walker(snode, kids_func=children_fun)
        node = walker.get_next()
        print ('node', type(node), node)
        while node:
            print ('has builder?', node.has_builder())
            if node.has_builder():
                environ = node.get_build_env()

                if 'CPPPATH' in environ:
                    includes.update(collect_user_includes(environ))
                if 'CPPDEFINES' in environ:
                    macros.update(collect_macros_from_cpp_defines(environ))
                if 'CCFLAGS' in environ:
                    macros.update(collect_macros_from_cc_flags(environ))
                if not compiler_env and ('CC' in environ or 'CXX' in environ):
                    compiler_env = environ
            node = walker.get_next()

    return (includes, macros, compiler_env)

The output of my prints:

('super_nodes', <type 'list'>, [<SCons.Node.Alias.Alias object at 0xf8f640>])
('snode', <class 'SCons.Node.Alias.Alias'>, <SCons.Node.Alias.Alias object at 0xf8f640>)
('node', <class 'SCons.Node.Alias.Alias'>, <SCons.Node.Alias.Alias object at 0xf8f640>)
('has builder?', False)

I do not familiar with SCons too much, so I do not know what exactly is going on here.
As I understand, the nodes were not parsed correctly.

Can you please look at this issue?

Regards,
Alexander

@alexander-titov
Copy link
Author

A clarification to my command line. It contains a target:
/bin/scons/2.5.0/bin/scons build_target -f SConstruct -f BuildInfoCollector.py

@mrueegg
Copy link
Contributor

mrueegg commented Apr 24, 2017

Hi,

Could you please describe your development environment regarding the used compiler, version, etc.?

Then, could you please add a break point like follows and inspect the environ variable when you invoke scons build_target -f SConstruct -f BuildInfoCollector.py?

environ = node.get_build_env()
import pdb; pdb.set_trace()

It seams to be None for certain nodes. It would be interesting to see for which file(s) and why.

Best regards,
Michael

@alexander-titov
Copy link
Author

alexander-titov commented Apr 25, 2017

Hi,

I changed the default "get_start_nodes":

def get_start_nodes():
    return (SCons.Script.Alias(SCons.Script.BUILD_TARGETS)
            if has_build_targets() else [SCons.Script.Dir('.')])

to this version:

def get_start_nodes():
    return (SCons.Script.Alias(SCons.Script.File(SCons.Script.BUILD_TARGETS))
            if has_build_targets() else [SCons.Script.Dir('.')])

As I understand, it fixed the issue. At least, there is no failure and script prints some info about my project.

The build_target in my case is a file. I am not sure that my solution is general.

Regarding your comment. Can you specify where exactly I need to put your code?

Regards,
Alexander

@alexander-titov
Copy link
Author

In addition, can you say where BuildInfoCollector.py is located? I would like to change it in order to use in Eclipse.

@alexander-titov
Copy link
Author

Hi, any updates?
Can you please answer my questions above? Let me know if you need some additional info.

@mrueegg
Copy link
Contributor

mrueegg commented May 16, 2017

Hi,

Please excuse my late answer. The place to put the break point is here:

You can just copy that file to your project directory and then execute

scons BUILD_TARGET -f SConstruct -f BuildInfoCollector.py

Hope that helps.

Best regards,
Michael

@alexander-titov
Copy link
Author

Hi Michael,

The node.has_builder() return False in my case, as you can see from the prints in my first message. Therefore, the breakpoint has to be set a line above you specified (I set it before the line 206, e.g., before has_builder() check).

My command line is:

/usr/bin/scons/2.5.0/bin/scons project_folder/binary_name COMP=gcc -u -f SConstruct -f BuildInfoCollector.py

The environment is Null

(Pdb) print (environ)
Null(0x011535D0)
(Pdb) type (environ)
<class 'SCons.Executor.NullEnvironment'>
(Pdb) print(node)
project_folder/binary_name
(Pdb) p node
<SCons.Node.Alias.Alias object at 0x7823680>
(Pdb) print(snode)
project_folder/binary_name
(Pdb) p snode
<SCons.Node.Alias.Alias object at 0x7823680>
(Pdb) continue

and then the script fails, as the next node is Null and collect_build_infos returns Null results.

If I change the method get_start_nodes() to:

def get_start_nodes():
    return (SCons.Script.Alias(SCons.Script.File(SCons.Script.BUILD_TARGETS))
            if has_build_targets() else [SCons.Script.Dir('.')])

The inspection will show the following:

Pdb) print (environ)
Null(0x011535D0)
(Pdb) print (node)
project_folder/subfolder/cpp_file.cc
(Pdb) p node
<SCons.Node.FS.File object at 0x5c73470>
(Pdb) print (snode)
project_folder/binary_name
(Pdb) p snode
<SCons.Node.FS.File object at 0x5dd9da0>
(Pdb) continue
-> import pdb; pdb.set_trace()
(Pdb) print (environ)
<SCons.Script.SConscript.SConsEnvironment object at 0x5b57110>
(Pdb) print (node)
project_folder/subfolder/cpp_file.o
(Pdb) p node
<SCons.Node.FS.Entry object at 0x5bfc770>
(Pdb) print (snode)
project_folder/binary_name
(Pdb) p snode
<SCons.Node.FS.File object at 0x5dd9da0>

...and so on, for all the files of the target.

@alexander-titov
Copy link
Author

Hi,
Is this information sufficient? Do I need to gather anything else?

Regards,
Alexander

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants