introduction to s cons

30
02/29/12 Introduction to SCons 1 Introduction to SCons Steve Christensen [email protected] Presented to Utah Python Users Group http://www.utahpython.org

Upload: dcshi

Post on 02-Jul-2015

4.664 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Introduction to s cons

02/29/12 Introduction to SCons 1

Introduction to SCons

Steve Christensen

[email protected]

Presented to Utah Python Users Group http://www.utahpython.org

Page 2: Introduction to s cons

02/29/12 Introduction to SCons 2

What is SCons?

SCons is an Open Source software construction tool

Think of SCons as an improved, cross-platform substitute for the classic Make utility with integrated functionality similar to autoconf/automake and compiler caches such as ccache.

In short, SCons is an easier, more reliable way to build software.

Page 3: Introduction to s cons

02/29/12 Introduction to SCons 3

SCons Benefits

Both SCons configuration files and user-created extensions to SCons are Python scripts

Global view of dependencies for entire project.

Support for sharing cached build results among developers

Page 4: Introduction to s cons

02/29/12 Introduction to SCons 4

SCons Benefits (continued)

Improved support for parallel builds -- like ‘make –j’ but keeps N jobs running simultaneously regardless of directory hierarchy.

Reliable detection of build changes using MD5 signatures (signatures track file content as well as command-line options)

Page 5: Introduction to s cons

02/29/12 Introduction to SCons 5

SCons Benefits (continued)

Reliable, automatic dependency analysis for C, C++, and Fortran. (extendible)

Built-in support for C, C++, D, Java, Fortran, Yacc, Lex, Qt, SWIG, building TeX and LaTeX documents, and many others. (extendible)

Great way for Python to infiltrate your C/C++ work environment

Page 6: Introduction to s cons

02/29/12 Introduction to SCons 6

SCons Drawbacks Java support isn’t as complete as the C/C++

support Incremental / no-op build performance is bad.

Compared to other tools, SCons can be significantly slower (e.g. 1-2 minute no-op build?)

Recipes on the Wiki / Mail Lists for speed ups

Complex builds require a fair amount of Python code to achieve the functionality built- in to some other build tools (e.g. variant builds ala BoostJam)

Page 7: Introduction to s cons

02/29/12 Introduction to SCons 7

SCons Basics

At startup, SCons will look for a file named ‘SConstruct’ in the current directory.

SConstruct is a Python script. SCons processes the script to build a dependency graph. Any nodes in the dependency graph that are out-of-date will be rebuilt.

SCons tracks dependencies by creating ‘.sconsign’ files to store build signatures.

Page 8: Introduction to s cons

02/29/12 Introduction to SCons 8

Example #1: HelloWorld

Simple helloworld.c :

int main() {

printf(“Hello, world!\n”);

}

Simple SConstruct:

Program('helloworld.c')

Page 9: Introduction to s cons

02/29/12 Introduction to SCons 9

Example #2: Static Libraries

Page 10: Introduction to s cons

02/29/12 Introduction to SCons 10

Example #2.1 : Shared Libraries

Page 11: Introduction to s cons

02/29/12 Introduction to SCons 11

Example #3: Builders return Lists

Page 12: Introduction to s cons

02/29/12 Introduction to SCons 12

Example #3.1 : Why lists?

In addition to file prefix / suffix problems, the same builder may produce a different number of output files on different platforms / compilers.

E.g. SharedLibrary(‘foo’,foo_sources) will return a single-item list on win32/cygwin [<Node: ‘foo.dll’>], and a three-item list on win32/msvc [<Node: ‘foo.dll’>,<Node: ‘foo.lib’>, <Node: ‘foo.exp’>]

Page 13: Introduction to s cons

02/29/12 Introduction to SCons 13

Example #4: Construction Environments

What if we want to compile the program in multiple ways?

Page 14: Introduction to s cons

02/29/12 Introduction to SCons 14

Example #4.2: Modifying a Construction Environment

Result:gcc -DFIRST -DDEFINE2 -DLAST -c -o helloworld.o helloworld.cgcc -o helloworld.exe helloworld.o

Page 15: Introduction to s cons

02/29/12 Introduction to SCons 15

Hierarchical Builds

Source files of large projects are typically organized into a hierarchy of directories. Builds with SCons use a hierarchy of SCons build scripts.

The top-level build script remains named ‘SConstruct’

The lower-level build scripts are conventionally named ‘SConscript’, and are executed via SConscript() method in the calling script(s).

Page 16: Introduction to s cons

02/29/12 Introduction to SCons 16

Example #5: Heirarchical Builds

Page 17: Introduction to s cons

02/29/12 Introduction to SCons 17

Example #6: Source vs. Build Directories?

Page 18: Introduction to s cons

02/29/12 Introduction to SCons 18

Variant Builds

BuildDir is cool, but I want release / debug and win32 / cygwin binaries and objects built into separate trees.

And, I want separate bin/lib/obj directories.

Page 19: Introduction to s cons

02/29/12 Introduction to SCons 19

Example #7: Variant Builds

Page 20: Introduction to s cons

02/29/12 Introduction to SCons 20

Example #7: Variant Builds (cont’d)

Page 21: Introduction to s cons

02/29/12 Introduction to SCons 21

Example #7: Variant Builds (cont’d)

Page 22: Introduction to s cons

02/29/12 Introduction to SCons 22

Example #8: Caching Built Files

Need a network share with read/write access for all your developers

Add ‘CacheDir(“/my/fancy/bulidcache”)’ to your build script.

Command-line options can be used to enable or disable uploads/downloads from the cache.

Page 23: Introduction to s cons

02/29/12 Introduction to SCons 23

Example #9: Extending SCons

Page 24: Introduction to s cons

02/29/12 Introduction to SCons 24

Example #9: Extending SCons

sed 's/x/y/' < baz.in > baz.out

Page 25: Introduction to s cons

02/29/12 Introduction to SCons 25

Example #9: Extending SCons

sed 's/x/y/' < baz.input > baz.output

Page 26: Introduction to s cons

02/29/12 Introduction to SCons 26

Example #9: Extending SCons

Page 27: Introduction to s cons

02/29/12 Introduction to SCons 27

Example #10: Java Builds

Page 28: Introduction to s cons

02/29/12 Introduction to SCons 28

Example #11: MSVC PDB, PCH, Resources

Page 29: Introduction to s cons

02/29/12 Introduction to SCons 29

More examples?

Options? Configuration?

Page 30: Introduction to s cons

02/29/12 Introduction to SCons 30

References

SCons Homepage SCons Wiki Article (Freshmeat.net): Make Alternatives Article (Games from Within): The Quest for

the Perfect Build System