Introduction to s cons

5.229 Aufrufe

Veröffentlicht am

Veröffentlicht in: Technologie
0 Kommentare
3 Gefällt mir
  • Als Erste(r) kommentieren

Keine Downloads
Aufrufe insgesamt
Auf SlideShare
Aus Einbettungen
Anzahl an Einbettungen
Gefällt mir
Einbettungen 0
Keine Einbettungen

Keine Notizen für die Folie

Introduction to s cons

  1. 1. Introduction to SCons Steve Christensen [email_address] Presented to Utah Python Users Group
  2. 2. What is SCons? <ul><li>SCons is an Open Source software construction tool </li></ul><ul><li>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. </li></ul><ul><li>In short, SCons is an easier, more reliable way to build software. </li></ul>
  3. 3. SCons Benefits <ul><li>Both SCons configuration files and user-created extensions to SCons are Python scripts </li></ul><ul><li>Global view of dependencies for entire project. </li></ul><ul><li>Support for sharing cached build results among developers </li></ul>
  4. 4. SCons Benefits (continued) <ul><li>Improved support for parallel builds -- like ‘make –j’ but keeps N jobs running simultaneously regardless of directory hierarchy. </li></ul><ul><li>Reliable detection of build changes using MD5 signatures (signatures track file content as well as command-line options) </li></ul>
  5. 5. SCons Benefits (continued) <ul><li>Reliable, automatic dependency analysis for C, C++, and Fortran. (extendible) </li></ul><ul><li>Built-in support for C, C++, D, Java, Fortran, Yacc, Lex, Qt, SWIG, building TeX and LaTeX documents, and many others. (extendible) </li></ul><ul><li>Great way for Python to infiltrate your C/C++ work environment </li></ul>
  6. 6. SCons Drawbacks <ul><li>Java support isn’t as complete as the C/C++ support </li></ul><ul><li>Incremental / no-op build performance is bad. </li></ul><ul><ul><li>Compared to other tools, SCons can be significantly slower (e.g. 1-2 minute no-op build?) </li></ul></ul><ul><ul><li>Recipes on the Wiki / Mail Lists for speed ups </li></ul></ul><ul><li>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) </li></ul>
  7. 7. SCons Basics <ul><li>At startup, SCons will look for a file named ‘SConstruct’ in the current directory. </li></ul><ul><li>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. </li></ul><ul><li>SCons tracks dependencies by creating ‘.sconsign’ files to store build signatures. </li></ul>
  8. 8. Example #1: HelloWorld <ul><li>Simple helloworld.c : </li></ul><ul><li>int main() { </li></ul><ul><li>printf(“Hello, world!n”); </li></ul><ul><li>} </li></ul><ul><li>Simple SConstruct: </li></ul><ul><li>Program('helloworld.c') </li></ul>
  9. 9. Example #2: Static Libraries
  10. 10. Example #2.1 : Shared Libraries
  11. 11. Example #3: Builders return Lists
  12. 12. Example #3.1 : Why lists? <ul><li>In addition to file prefix / suffix problems, the same builder may produce a different number of output files on different platforms / compilers. </li></ul><ul><li>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’>] </li></ul>
  13. 13. Example #4: Construction Environments <ul><li>What if we want to compile the program in multiple ways? </li></ul>
  14. 14. Example #4.2: Modifying a Construction Environment <ul><li>Result: </li></ul><ul><li>gcc -DFIRST -DDEFINE2 -DLAST -c -o helloworld.o helloworld.c </li></ul><ul><li>gcc -o helloworld.exe helloworld.o </li></ul>
  15. 15. Hierarchical Builds <ul><li>Source files of large projects are typically organized into a hierarchy of directories. Builds with SCons use a hierarchy of SCons build scripts. </li></ul><ul><li>The top-level build script remains named ‘SConstruct’ </li></ul><ul><li>The lower-level build scripts are conventionally named ‘SConscript’, and are executed via SConscript() method in the calling script(s). </li></ul>
  16. 16. Example #5: Heirarchical Builds
  17. 17. Example #6: Source vs. Build Directories?
  18. 18. Variant Builds <ul><li>BuildDir is cool, but I want release / debug and win32 / cygwin binaries and objects built into separate trees. </li></ul><ul><li>And, I want separate bin/lib/obj directories. </li></ul>
  19. 19. Example #7: Variant Builds
  20. 20. Example #7: Variant Builds (cont’d)
  21. 21. Example #7: Variant Builds (cont’d)
  22. 22. Example #8: Caching Built Files <ul><li>Need a network share with read/write access for all your developers </li></ul><ul><li>Add ‘CacheDir(“/my/fancy/bulidcache”)’ to your build script. </li></ul><ul><li>Command-line options can be used to enable or disable uploads/downloads from the cache. </li></ul>
  23. 23. Example #9: Extending SCons
  24. 24. Example #9: Extending SCons <ul><li>sed 's/x/y/' < > baz.out </li></ul>
  25. 25. Example #9: Extending SCons <ul><li>sed 's/x/y/' < baz.input > baz.output </li></ul>
  26. 26. Example #9: Extending SCons
  27. 27. Example #10: Java Builds
  28. 28. Example #11: MSVC PDB, PCH, Resources
  29. 29. More examples? <ul><li>Options? </li></ul><ul><li>Configuration? </li></ul>
  30. 30. References <ul><li>SCons Homepage </li></ul><ul><li>SCons Wiki </li></ul><ul><li>Article ( Make Alternatives </li></ul><ul><li>Article (Games from Within): The Quest for the Perfect Build System </li></ul>