Prevent users from searching for standard tools

I am currently setting up SCons to cross-compile with Windows as the host OS. I create a custom Environment for the cross-compiler, but SCons insists on finding Visual Studio every time I start it (and displays a warning that it cannot find it because I don't have one). Can I stop him from looking for standard tools that I know I will not use?

+7
source share
3 answers

There are at least 2 ways to do this, the first way is the easiest, try creating an environment that defines the compiler, as follows:

 env = Environment(CC = '/path/to/the/compiler') 

You will probably need to add paths for the linker and other tools. Then the SCons should not look for them.

Another way to do this would be to create a tool definition for the cross-compiler using the tools argument of the Environment() function, as described in the FILE REFERENCE CONFIGURATIONS section of the SCons user page section, which states the following:

In addition, a specific set of tools for initializing the environment can be specified as an optional keyword argument:

env = Environment(tools = ['msvc', 'lex'])

Non-built-in tools can be specified using the pathpath argument:

env = Environment(tools = ['default', 'foo'], toolpath = ['tools'])

...

The individual elements of the tool list can also be the two-element form lists themselves (tool name, kw_dict). SCons looks for the tool name specification file, as described above, and passes kw_dict, which should be a dictionary, as keyword arguments for the tool generation function. The generate function can use arguments to change the behavior of the tool by setting up the environment in different ways or otherwise changing its initialization.

tools / my_tool.py:

 def generate(env, **kw): # Sets MY_TOOL to the value of keyword argument 'arg1' or 1. env['MY_TOOL'] = kw.get('arg1', '1') def exists(env): return 1 

SConstruct:

 env = Environment(tools = ['default', ('my_tool', {'arg1': 'abc'})], toolpath=['tools']) 
+6
source

You can suppress warnings like this

 env.SetOption('warn', 'no-visual-c-missing') 

For example, to cross-compile for ARM Cortex-M microcontrollers, I do this

 cross = 'arm-none-eabi-' toolchain = { 'CC': cross + 'gcc', 'CXX': cross + 'g++', 'AR': cross + 'ar', 'AS': cross + 'gcc', 'OBJCOPY': cross + 'objcopy', 'SIZE': cross + 'size', 'PROGSUFFIX': '.elf', } env = Environment(tools=('gcc', 'g++', 'gnulink', 'ar', 'as'), ENV=os.environ) env.SetOption('warn', 'no-visual-c-missing') env.Replace(**toolchain) 
+1
source

Try overriding DefaultEnvironment instead of defining Environment .

All the Builder functions that we have introduced so far, such as Program and Library, actually use the default build environment, which contains settings for various compilers and other tools that SCons sets up by default or otherwise knows and finds on your system ., The purpose of the default build environment is to make many configurations "just work" for building software using readily available tools with minimal configuration changes.

Therefore, SCons will not attempt to make predictions based on common usage and apply them in their project. For example:

 PATH = {'PATH' : ['C:/cygwin/bin']} env = Environment(ENV=PATH) env.Program('helloworld.c++') 

will make assumptions based on what he considers the most likely case, and try to find Visual Studio before resorting to what it finds in PATH, whereas:

 PATH = {'PATH' : ['C:/cygwin/bin']} env = DefaultEnvironment(ENV=PATH) env.Program('helloworld.c++') 

He will not make such an assumption and will go directly to what he finds in PATH without looking for Visual Studio.

0
source

All Articles