SCons env.Command() doesn't work as expected, no command executed - command

I've got a simple SConstruct file as below:
import os,sys
env = Environment()
env.Command([], [], "echo abc")
I expected that this will output "abc", but in fact, nothing extra is printed, the screen output is:
$scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
So how should I fix it? Thanks a lot.

Since you've called a builder with no source and no targets, it's never out of date, and so won't be run.
So you want it to run right away, in which case you should use Execute()
env = Environment()
env.Execute("echo abc")
or just
Execute("echo abc")
The latter yields
$ scons
scons: Reading SConscript files ...
echo abc
abc
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.

Related

Light Service Framework Fails to build if original readme followed

If we follow original readme for building LSF, its keep failing at the first step.
As soon as I run "scons" I get:
scons: Reading SConscript files ... Checking c++ compiler support for
-std=c++11 flag... yes Using OpenSSL crypto GTEST_DIR not specified skipping common unit test build GTEST_DIR not specified skipping About
Service unit test build GTEST_DIR not specified skipping alljoyn_core
unit test build
scons: warning: Ignoring missing SConscript
'/home/dms/lighting_alljoyn_poligon/base/config/cpp/SConscript' File
"/home/dms/lighting_alljoyn_poligon/core/service_framework/SConscript",
line 28, in GTEST_DIR not specified skipping LSF unit test
build
scons: warning: Ignoring missing SConscript
'/home/dms/lighting_alljoyn_poligon/core/ajtcl/SConscript' File
"/home/dms/lighting_alljoyn_poligon/core/service_framework/SConscript",
line 164, in AttributeError: 'NoneType' object has no
attribute 'Append': File
"/home/dms/lighting_alljoyn_poligon/core/service_framework/SConstruct",
line 5: env.SConscript('SConscript') File
"/usr/lib/scons/SCons/Script/SConscript.py", line 546: return
_SConscript(self.fs, *files, **subst_kw) File "/usr/lib/scons/SCons/Script/SConscript.py", line 260: exec file
in call_stack[-1].globals File
"/home/dms/lighting_alljoyn_poligon/core/service_framework/SConscript",
line 166: lamp_service_env.Append(LIBPATH = [
lamp_service_env.Dir('../ajtcl') ])
The warnings can be ignored, but at the bottom the append related issues are causing the stop of building process.
By the way I have built alljoyn framework including base services and it works perfect.
Any hint is welcomed!
The problem was in the structure of the files.
The original SConsript file of LSF tries to access ../../base_tcl folder, but the base_tcl folder was located under services/ folder.
I have tried two solutions and both worked:
1. Either you change the path to the base_tcl folder in the SConscript
2. Or the folder base_tcl can moved to the proper path
I think this issue was caused because of version problem. The difference between 15.04 and 15.09

How to use SCons lex builder with variant directories

I'm trying to build a complex application with flex lexer using SCons. To build debug/release variants I'm using VariantDir().
The problem is that I can't force lex builder to generate lexer header in variant build directory. It isn't a big problem itself but it forces SCons to think that lexer is always out of date.
SConstruct contents:
VariantDir('build', '.', duplicate=0)
SConscript('build/SConscript')
SConscript contents:
env = Environment(LEXFLAGS='--header-file=scanner.h')
env.Program(target='scanner', source='scanner.l')
Full source to represent this problem is here: https://gist.github.com/g7r/4257f273715cadcf0d36
First scons.py --debug=explain run gives us this:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
scons: building `build/scanner.c' because it doesn't exist
flex --header-file=scanner.h -t scanner.l > build/scanner.c
scons: building `build/scanner.o' because it doesn't exist
gcc -o build/scanner.o -c build/scanner.c
scons: building `build/scanner' because it doesn't exist
gcc -o build/scanner build/scanner.o
scons: done building targets.
Second run gives this:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
scons: building `build/scanner.h' because it doesn't exist
flex --header-file=scanner.h -t scanner.l > build/scanner.c
scons: done building targets.
So second run rebuilds the lexer because scanner.h was generated in root directory instead of build directory.
Am I doing something wrong? Is there any way to do it right?
Consider combining the call to VariantDir() with the call to SConscript() which usually makes the paths in the build scripts more intuitive. Also, I suspect (unfortunately) the call to VariantDir() is confusing the SCons flex builder.
Here is an example:
SConscript('SConscript', variant_dir='build', duplicate=0)
Chapters 14 and 15 of the SCons user's guide give a good explanation of the SConscript() function.
For anyone hitting this old problem via a search - the problem isn't variant dirs per se, it's the use of the --header-file option and being in a subdirectory: SCons passes LEXFLAGS on as is when flex is called, but also extracts the header file name you asked for and adds it as a target - at which point it's subject to the SCons path interpretation rules, as in "relative to the directory of the SConscript", so flex generates the file one place via the issued command and SCons thinks it's a different place, thus the "always out of date". There's more on this topic at https://github.com/SCons/scons/issues/4154.

scons build in eclipse

I have converted a static library project and an exe project to Scons project in ECLIPSE. These were building fine by Makefile.
But when I am building the static library project it gives an error as below -
=== Running SCons at 18/11/13 8:55 PM ====
Command line: /usr/bin/scons -u --jobs=8
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: Debug
o Debug/add.o -c add.cpp
sh: o: not found
ar rc Debug/libadd.a Debug/add.o
ar: Debug/add.o: No such file or directory
scons: *** [Debug/libadd.a] Error 1
scons: building terminated because of errors.
Duration 301 ms.
1) my main objective is to a trigger a build once somehow (in the exe project) and both the project will be compiled in ECLIPSE. Is there a way to see and edit a SConscript in eclipse.
2) How do I do it? By manually writing SConscript and SConstruct file? :(
It looks from the SCons output like SCons can't find the compiler on your system. What OS are you using? And what version of SCons? (Type scons --version to see that.)

Why is Netbeans complaining about my GNUmakefile?

I am making a Netbeans C++ project with an existing GNUmakefile. I went to File -> New Project -> C/C++ with Existing Sources and selected the folder with my current files (including the GNUmakefile).
However, when I run my app, I get the following error.
make: Makefile: No such file or directory
make: *** No rule to make target `Makefile'. Stop.
BUILD FAILED (exit value 2, total time: 67 ms)
I suspect that my Makefile is named "GNUmakefile", which differs from "Makefile." However, I do not want to rename "GNUmakefile," since I am working on this project with others who want to keep it the same.
Is that why Netbeans complains about my GNUmakefile? How can I tell Netbeans to use GNUmakefile instead?
It looks like you must be invoking make as make -f Makefile, so you are explicitly (whether you realize it or not) saying to use a makefile called Makefile. Otherwise, GNU make would happily use GNUmakefile:
$ ls
GNUmakefile
$ cat GNUmakefile
all: ; #echo done
$ make
done
$ make -f Makefile
make: Makefile: No such file or directory
make: *** No rule to make target `Makefile'. Stop.
Note that you only get the error you reported in the last case. So you just need to change how you are invoking GNU make. Alternatively you could symlink Makefile to GNUmakefile:
$ ln -s GNUmakefile Makefile
$ gmake -f Makefile
done

How to watch and recompile coffee scripts as they change?

Some time ago I used to do
coffee --bare --output . --watch --compile .
This watches the .coffee files in the current dir and recompiles them as they change.
Now, using 1.2.0 of coffeescript this does not seem to work any more. I'm presented with an error:
File not found: --watch.coffee
and the usage documentation for coffee seems rather light.
I'd skip the --output ., as it seems to be unnecessary if you're already in the same directory, and go straight with
coffee -bcw *.coffee
Otherwise, this is a duplicate of Compile CoffeeScript on Save?
BTW, you can also go:
coffee -bcw .
which will not only save a few keystrokes, but also scan subdirectories to compile .coffee files.