ebdlib.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #! /usr/bin/env python
  2. import os, sys, imp, time
  3. from waflib import Context, Options, Configure, Utils, Logs, TaskGen, Task, Build, ConfigSet
  4. import waflib.Tools.c
  5. """
  6. Create a modified waf file in which tasks use timestamps only
  7. see README.txt
  8. """
  9. # we hard-code a configuration for c but it could be left in the script file too
  10. def configure(conf):
  11. conf.load('gcc')
  12. def recurse_rep(x, y):
  13. f = getattr(Context.g_module, x.cmd or x.fun, Utils.nada)
  14. return f(x)
  15. def start(cwd, version, wafdir):
  16. # this is the entry point of our small build system
  17. Logs.init_log()
  18. Context.waf_dir = wafdir
  19. Context.out_dir = Context.top_dir = Context.run_dir = cwd
  20. Context.g_module = Context.load_module(cwd + os.sep + 'wscript')
  21. Context.g_module.configure = configure
  22. Context.g_module.root_path = cwd
  23. Context.Context.recurse = recurse_rep
  24. Context.g_module.top = Context.g_module.out = '.' # no build directory
  25. # just parse the options and execute a build
  26. Options.OptionsContext().execute()
  27. conf = Context.create_context('configure')
  28. conf.options = Options.options
  29. conf.execute()
  30. bld = Context.create_context('build')
  31. bld.env = conf.env
  32. bld.options = Options.options
  33. bld.environ = os.environ
  34. bld.execute()
  35. # change the build context so it does not need to write any file
  36. class StatelessBuild(Build.BuildContext):
  37. def load_envs(self):
  38. self.env = ConfigSet.ConfigSet()
  39. def store(self):
  40. pass
  41. def restore(self):
  42. self.init_dirs()
  43. def execute_build(self):
  44. # we override this method to hide the messages "leaving directory" (just because)
  45. self.recurse([self.run_dir])
  46. self.pre_build()
  47. self.timer = Utils.Timer()
  48. if Options.options.progress_bar:
  49. sys.stderr.write(Logs.colors.cursor_off)
  50. try:
  51. self.compile()
  52. finally:
  53. if Options.options.progress_bar:
  54. sys.stderr.write(Logs.colors.cursor_on)
  55. print('')
  56. self.post_build()
  57. class SilentConf(Configure.ConfigurationContext):
  58. # silent configuration
  59. def __init__(self, **kw):
  60. # disable the configuration messages from Context.start_msg/end_msg
  61. self.in_msg = 1
  62. super(SilentConf, self).__init__(**kw)
  63. def execute(self):
  64. # copy-paste from the original method, but without the cache file creation
  65. self.init_dirs()
  66. path = os.path.join(self.bldnode.abspath(), 'config.log')
  67. self.logger = Logs.make_logger(path, 'cfg')
  68. app = getattr(Context.g_module, 'APPNAME', '')
  69. if app:
  70. ver = getattr(Context.g_module, 'VERSION', '')
  71. if ver:
  72. app = "%s (%s)" % (app, ver)
  73. now = time.ctime()
  74. pyver = sys.hexversion
  75. systype = sys.platform
  76. args = " ".join(sys.argv)
  77. wafver = Context.WAFVERSION
  78. abi = Context.ABI
  79. self.to_log(Configure.conf_template % vars())
  80. super(Configure.ConfigurationContext, self).execute()
  81. # change the superclass of existing tasks to force timestamps (the build has no state)
  82. def status(self):
  83. for t in self.run_after:
  84. if not t.hasrun:
  85. return Task.ASK_LATER
  86. implicit_deps = []
  87. try:
  88. implicit_deps, _ = self.scan()
  89. except:
  90. pass
  91. # we can add one more node, for example:
  92. implicit_deps.append(self.generator.path.make_node('wscript'))
  93. for x in self.inputs + self.dep_nodes + implicit_deps:
  94. for y in self.outputs:
  95. try:
  96. if os.stat(x.abspath()).st_mtime > os.stat(y.abspath()).st_mtime:
  97. return Task.RUN_ME
  98. except:
  99. return Task.RUN_ME
  100. return Task.SKIP_ME
  101. Task.Task.runnable_status = status
  102. # the post build execution does not need to deal with signatures or anything else
  103. Task.Task.post_run = Utils.nada