Guest User

Untitled

a guest
Feb 22nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. # Super-Simplified SConstruct to show issue with the scanner running prior to rebuilding the file being scanned.
  2. # Instructions:
  3. #   Create in folder with three empty files: 'source_1.dat', 'source_2.dat', 'source_3.dat'.
  4. #   Run 'scons' once to create a stable state of files
  5. #   Modify the contents of source_1.dat or source_2.dat to be 'source_3.dat' without quotes.
  6. #   Run 'scons -j2'
  7. #   Notice that a 'building' occurs between 'scanning', and panic!
  8.  
  9. import os
  10. import time
  11. import SCons
  12. from SCons.Script import *
  13. SCons.Defaults.DefaultEnvironment(tools = []) # Block default tools; loads quicker.
  14.  
  15. project_file_name = 'project.prj'
  16. version_file_name = 'derp.txt'
  17. binary_file_name = 'out.bin'
  18.  
  19. def scan_prj(node, env, path):
  20.     print 'scanning ' + str(node)
  21.     time.sleep(1)
  22.     component_file_list = []
  23.     for line in node.get_text_contents().splitlines():
  24.         component_file_list.append(File(line))
  25.     print 'done scanning ' + str(node)
  26.     return component_file_list
  27.    
  28. def create_project_file(target, source, env):
  29.     print 'building ' + str(target[0])
  30.     with open(str(target[0]), 'wb') as outfile:
  31.         time.sleep(1)
  32.         for infile in source:
  33.             with open(str(infile)) as file:
  34.                 for line in file:
  35.                     outfile.write(line)
  36.     print 'done building ' + str(target[0])
  37.    
  38. def compiler_action(target, source, env):
  39.     print 'creating ' + str(target[0])
  40.     with open(str(target[0]), 'wb') as outfile:
  41.         outfile.write('abc')
  42.     print 'done creating ' + str(target[0])
  43.  
  44. def version_action(target, source, env):
  45.     with open(str(target[0]), 'wb') as version_file:
  46.         version_file.write('version is 5')
  47.  
  48. # Create the local environment.
  49. envBase = Environment(tools = [],
  50.                       BUILDERS = {'Compile' : SCons.Builder.Builder(action = compiler_action),
  51.                                   'MakeVersion' : SCons.Builder.Builder(action = version_action)},
  52.                       SCANNERS = [Scanner(function = scan_prj, skeys = ['.prj'], path_function=FindPathDirs('.'), recursive=False)])
  53.                      
  54. project_prj = envBase.Command(project_file_name, ['source_1.dat', 'source_2.dat'], create_project_file)
  55. version_file = envBase.MakeVersion(version_file_name, project_prj)
  56. binary_file = envBase.Compile(binary_file_name, [project_prj, version_file])
  57.  
  58. Alias('release', binary_file)
  59.  
  60. Default('release')
Add Comment
Please, Sign In to add comment