Discussion:
[Scons-users] Print out messages only if target is building
Anna Cheremnykh
2018-08-01 12:19:24 UTC
Permalink
Hi,

I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory with
separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer doesn't have
such env var - sample build should be just skipped without errors.
So in sconsripts we added something like this:

if not os.getenv('SOME_SDK_ROOT'):
    print('SOME_SDK_ROOT  not found, ' + sample_name + ' build skipped')
    Return()

I understand that scons read all sconsript files first. And I see this
message every time even if I build another samples or another
components. So my question how NOT to print messages if I call another
target from another Sconscript? Thanks!
--
Anna Ch.
Mats Wichmann
2018-08-01 16:28:03 UTC
Permalink
Post by Anna Cheremnykh
Hi,
I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory with
separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer doesn't have
such env var - sample build should be just skipped without errors.
    print('SOME_SDK_ROOT  not found, ' + sample_name + ' build skipped')
    Return()
I understand that scons read all sconsript files first. And I see this
message every time even if I build another samples or another
components. So my question how NOT to print messages if I call another
target from another Sconscript? Thanks!
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to maybe
figure something out?

https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-command-line-targets
Bill Deegan
2018-08-01 17:03:41 UTC
Permalink
SConscripts are not targets.

Can you provide more detail?
Do you want some text output when a give program is built? Or a library? or
something else?
Post by Mats Wichmann
Post by Anna Cheremnykh
Hi,
I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory with
separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer doesn't have
such env var - sample build should be just skipped without errors.
print('SOME_SDK_ROOT not found, ' + sample_name + ' build skipped')
Return()
I understand that scons read all sconsript files first. And I see this
message every time even if I build another samples or another
components. So my question how NOT to print messages if I call another
target from another Sconscript? Thanks!
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to maybe
figure something out?
https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-command-line-targets
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Jack Brennen
2018-08-01 17:24:59 UTC
Permalink
You should be able to make the SConscript inclusion conditional.

I would do something like this, which feels a little cleaner to me:

if 'SOME_SDK_ROOT' in os.environ:
#
# Include subsidiary SConscript, but only if SOME_SDK_ROOT env var is set.
#
SConscript(...)

- Jack
Post by Bill Deegan
SConscripts are not targets.
Can you provide more detail?
Do you want some text output when a give program is built? Or a
library? or something else?
Post by Anna Cheremnykh
Hi,
I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory
with
Post by Anna Cheremnykh
separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer
doesn't have
Post by Anna Cheremnykh
such env var - sample build should be just skipped without errors.
    print('SOME_SDK_ROOT  not found, ' + sample_name + ' build
skipped')
Post by Anna Cheremnykh
    Return()
I understand that scons read all sconsript files first. And I
see this
Post by Anna Cheremnykh
message every time even if I build another samples or another
components. So my question how NOT to print messages if I call
another
Post by Anna Cheremnykh
target from another Sconscript? Thanks!
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to maybe
figure something out?
https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-command-line-targets
<https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-command-line-targets>
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
<https://pairlist4.pair.net/mailman/listinfo/scons-users>
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Bill Deegan
2018-08-01 18:22:33 UTC
Permalink
+1 to optionally including sconscripts.
Just be forewarned if the sconscripts set CPPPATH or other needed for the
rest of the build, you'll have to work around that.
Post by Jack Brennen
You should be able to make the SConscript inclusion conditional.
#
# Include subsidiary SConscript, but only if SOME_SDK_ROOT env var is set.
#
SConscript(...)
- Jack
SConscripts are not targets.
Can you provide more detail?
Do you want some text output when a give program is built? Or a library?
or something else?
Post by Mats Wichmann
Post by Anna Cheremnykh
Hi,
I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory with
separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer doesn't have
such env var - sample build should be just skipped without errors.
print('SOME_SDK_ROOT not found, ' + sample_name + ' build skipped')
Return()
I understand that scons read all sconsript files first. And I see this
message every time even if I build another samples or another
components. So my question how NOT to print messages if I call another
target from another Sconscript? Thanks!
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to maybe
figure something out?
https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-comman
d-line-targets
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Mats Wichmann
2018-08-01 18:30:26 UTC
Permalink
Post by Bill Deegan
SConscripts are not targets.
Can you provide more detail?
Do you want some text output when a give program is built? Or a library? or
something else?
I understood the question this way, maybe got it wrong:

a bunch of targets defined, each a sample app, including x and y

if I ask for x, y on scons command line, and x cannot build due to
external reason (missing tools), print a message and skip x

if I ask for y then don't print the message about skipping x since it's
irrelevant anyway
Post by Bill Deegan
Post by Mats Wichmann
Post by Anna Cheremnykh
Hi,
I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory with
separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer doesn't have
such env var - sample build should be just skipped without errors.
print('SOME_SDK_ROOT not found, ' + sample_name + ' build skipped')
Return()
I understand that scons read all sconsript files first. And I see this
message every time even if I build another samples or another
components. So my question how NOT to print messages if I call another
target from another Sconscript? Thanks!
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to maybe
figure something out?
https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-command-line-targets
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Matthew Marinets
2018-08-01 20:11:38 UTC
Permalink
This sounds like a build-time change.

I generally think of a SCons build in terms of two time-periods: SConscript time and build time.

In SConscript time, the scripts behave like normal Python and will not build targets. Builders at this stage only format how to build files, but don't actually build them.
In build time, SCons figures out which files it has to build, which among those are out-of-date, and builds them. The build actions and order is controlled by how you ran the builders in SConscript time.

If you're putting a print statement in around a builder, that's SConscript time. It will always run if Python will run that code.
If you only want the message to display in build time, you need to get it into a build action somehow.

How to get a Python print statement into an action? You need to affect the Action objects or the strings they're building their actions from. The simplest example is probably:
print("This will print during SConscript time.")
outputs = env.SomeBuilder(target = target, source = source)
env.AddPreAction(outputs, action = lambda target, source, env: print("This will print during build time."))

The strategy I use for organizing my outputs is to just print a big line of dashes at the bottom of my SConstruct files. It's the last line of Python code, so anything that gets printed after that line has to be printed during build time.

What you probably want to do is modify your builder's action. If it's a SCons built-in or is formatted like a SCons built-in, you should be able to find the (XX)COM variable in the environment (env.Dump() if you don't know what's in your environment). You can then modify this string based on if the SDK exists:

Example: changing ALL Program() builders to print an error if SOME_SDK is not in the external environment.
SConscript:
env = Environment()
# format env
# call SConscript()

if not os.environ.get("SOME_SDK"):
env['LINKCOM'] = "echo Not building $TARGET because SOME_SDK is not formatted"

# everything printed after this line in the SCons output is printed at build-time
print("---------------")

If you want to affect only specific calls to a builder (stop Program() in one SConscript but not another), you're going to have to run those builders with separate environments. At the top of the SConscript, you'd call:
Import("env")
env = env.Clone()
Note that this means that changes to the environment in that SConscript will only affect builders / actions in that SConscript.

-Matthew

-----Original Message-----
From: Scons-users <scons-users-***@scons.org> On Behalf Of Mats Wichmann
Sent: August 1, 2018 11:30
To: scons-***@scons.org
Subject: Re: [Scons-users] Print out messages only if target is building
Post by Bill Deegan
SConscripts are not targets.
Can you provide more detail?
Do you want some text output when a give program is built? Or a
library? or something else?
I understood the question this way, maybe got it wrong:

a bunch of targets defined, each a sample app, including x and y

if I ask for x, y on scons command line, and x cannot build due to external reason (missing tools), print a message and skip x

if I ask for y then don't print the message about skipping x since it's irrelevant anyway
Post by Bill Deegan
Post by Mats Wichmann
Post by Anna Cheremnykh
Hi,
I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory
with separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer doesn't
have such env var - sample build should be just skipped without errors.
print('SOME_SDK_ROOT not found, ' + sample_name + ' build skipped')
Return()
I understand that scons read all sconsript files first. And I see
this message every time even if I build another samples or another
components. So my question how NOT to print messages if I call
another target from another Sconscript? Thanks!
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to
maybe figure something out?
https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-command-line-ta
rgets
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Bill Deegan
2018-08-02 02:43:12 UTC
Permalink
On Wed, Aug 1, 2018 at 1:11 PM, Matthew Marinets <
Post by Matthew Marinets
This sounds like a build-time change.
SConscript time and build time.
In SConscript time, the scripts behave like normal Python and will not
build targets. Builders at this stage only format how to build files, but
don't actually build them.
In build time, SCons figures out which files it has to build, which among
those are out-of-date, and builds them. The build actions and order is
controlled by how you ran the builders in SConscript time.
If you're putting a print statement in around a builder, that's SConscript
time. It will always run if Python will run that code.
If you only want the message to display in build time, you need to get it
into a build action somehow.
How to get a Python print statement into an action? You need to affect the
Action objects or the strings they're building their actions from. The
print("This will print during SConscript time.")
outputs = env.SomeBuilder(target = target, source = source)
print("This will print during build time."))
The strategy I use for organizing my outputs is to just print a big line
of dashes at the bottom of my SConstruct files. It's the last line of
Python code, so anything that gets printed after that line has to be
printed during build time.
What you probably want to do is modify your builder's action. If it's a
SCons built-in or is formatted like a SCons built-in, you should be able to
find the (XX)COM variable in the environment (env.Dump() if you don't know
what's in your environment). You can then modify this string based on if
Example: changing ALL Program() builders to print an error if SOME_SDK is
not in the external environment.
env = Environment()
# format env
# call SConscript()
env['LINKCOM'] = "echo Not building $TARGET because
SOME_SDK is not formatted"
# everything printed after this line in the SCons output is printed at build-time
print("---------------")
If you want to affect only specific calls to a builder (stop Program() in
one SConscript but not another), you're going to have to run those builders
Import("env")
env = env.Clone()
Note that this means that changes to the environment in that SConscript
will only affect builders / actions in that SConscript.
Not entirely true:
env.Program(target,source,....,LINKCOMSTR='my message here')
Should also work.
Another way to go would be to put a Psuedobuilder (see users guide) which
modifies LINKCOMSTR or whatever Action output variable is relevant.

-Bill
Post by Matthew Marinets
-Matthew
-----Original Message-----
Sent: August 1, 2018 11:30
Subject: Re: [Scons-users] Print out messages only if target is building
Post by Bill Deegan
SConscripts are not targets.
Can you provide more detail?
Do you want some text output when a give program is built? Or a
library? or something else?
a bunch of targets defined, each a sample app, including x and y
if I ask for x, y on scons command line, and x cannot build due to
external reason (missing tools), print a message and skip x
if I ask for y then don't print the message about skipping x since it's irrelevant anyway
Post by Bill Deegan
Post by Mats Wichmann
Post by Anna Cheremnykh
Hi,
I stuck with a problem: I want to print message only when given
target(Scinscript) is building.
What we have: several samples, each sample in separate directory
with separate Sconscript. Some of samples require 3rdparty SDKs and
environment variables set to these SDKs. But if developer doesn't
have such env var - sample build should be just skipped without errors.
print('SOME_SDK_ROOT not found, ' + sample_name + ' build
skipped')
Post by Bill Deegan
Post by Mats Wichmann
Post by Anna Cheremnykh
Return()
I understand that scons read all sconsript files first. And I see
this message every time even if I build another samples or another
components. So my question how NOT to print messages if I call
another target from another Sconscript? Thanks!
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to
maybe figure something out?
https://scons.org/doc/3.0.1/HTML/scons-user.html#sect-command-line-ta
rgets
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Anna Cheremnykh
2018-08-02 06:09:12 UTC
Permalink
Post by Mats Wichmann
a bunch of targets defined, each a sample app, including x and y
if I ask for x, y on scons command line, and x cannot build due to
external reason (missing tools), print a message and skip x
if I ask for y then don't print the message about skipping x since it's
irrelevant anyway
Exactly.
Post by Mats Wichmann
I think you can look at COMMAND_LINE_TARGETS and BUILD_TARGETS to maybe
figure something out?
I think it is suitable solution. Trying to add "if target in
COMMAND_LINE_TARGETS" statement and it seems to work as expected. Thanks!
--
Anna Cheremnykh
Loading...