wscript 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #! /usr/bin/env python3.1
  2. import os, shutil
  3. from waflib import Node, Build, Utils, Logs
  4. def exists(path):
  5. try:
  6. os.stat(path)
  7. except:
  8. return 'no'
  9. else:
  10. return 'yes'
  11. def remove(path):
  12. try:
  13. try:
  14. os.listdir(path)
  15. except OSError:
  16. os.remove(path)
  17. else:
  18. shutil.rmtree(path)
  19. except:
  20. pass
  21. def create(path):
  22. try:
  23. os.makedirs(path)
  24. except:
  25. os.listdir(path)
  26. def configure(ctx):
  27. pass
  28. def test(ctx):
  29. bld = Build.BuildContext()
  30. errors = []
  31. def tt(msg, result, expected):
  32. color = 'RED'
  33. if result == expected:
  34. color = 'GREEN'
  35. else:
  36. errors.append(result)
  37. Logs.pprint(color, msg.ljust(20) + " %r" % result)
  38. # 1. absdir is wrong, keep the drive letter
  39. # 2. split should use os.sep
  40. # 3. replace / in d1 from d2
  41. # 4. use os.sep in find_node
  42. absdir = os.getcwd().split(os.sep)
  43. dd = bld.root.make_node(absdir)
  44. pp = dd.parent
  45. tt('dir printed', repr(dd), os.getcwd())
  46. tt('parent', repr(pp), os.path.split(os.getcwd())[0])
  47. tt('path_from', dd.path_from(pp), os.path.split(os.getcwd())[1])
  48. tt('path_from (reverse)', pp.path_from(dd), '..')
  49. tt('same path', pp.path_from(pp), '.')
  50. tt('path from root is abspath()', pp.path_from(bld.root), pp.abspath())
  51. tt('root from root', bld.root.path_from(bld.root), bld.root.abspath())
  52. tt('root height', bld.root.height(), 0)
  53. tt('self height', dd.height(), len(absdir))
  54. d1 = dd.make_node(['a', 'b'])
  55. d2 = dd.make_node(['c', 'd'])
  56. tt('compare height', d1.height() - pp.height(), 3)
  57. tt('d1 from d2', d1.path_from(d2), '../../a/b'.replace('/', os.sep))
  58. tt('d2 from d1', d2.path_from(d1), '../../c/d'.replace('/', os.sep))
  59. d1.parent.delete()
  60. tt('d1.parent exists', exists(d1.parent.abspath()), 'no')
  61. tt('d1 exists', exists(d1.abspath()), 'no')
  62. d1.parent.mkdir()
  63. d1.parent.mkdir()
  64. tt('d1.parent exists', exists(d1.parent.abspath()), 'yes')
  65. tt('d1 exists', exists(d1.abspath()), 'no')
  66. d1.mkdir()
  67. kp = d1.make_node(['ah-ha'])
  68. ini = "this is a test"
  69. kp.write(ini)
  70. kp.chmod(493)
  71. fin = kp.read()
  72. tt('read and write text', fin, ini)
  73. rama = ['1234', '5', '6', '7']
  74. remove('1234')
  75. create('/'.join(rama))
  76. rr = dd.find_node(rama)
  77. tt('find a node', repr(rr), os.sep.join([os.getcwd()]+rama))
  78. remove('src/build')
  79. create('src/build')
  80. ss = dd.find_node(['src'])
  81. bb = dd.find_node(['src', 'build'])
  82. bld.top_dir = ss.abspath()
  83. bld.out_dir = bb.abspath()
  84. bld.init_dirs()
  85. #remove(dd.abspath() + '/' +"xyz")
  86. tt('find ["xyz"]', dd.find_node(['xyz']), None)
  87. tt('bld.srcnode is src', bld.srcnode.is_src(), True)
  88. tt('bld.srcnode is bld', bld.srcnode.is_bld(), False)
  89. tt('bld.bldnode is src', bld.bldnode.is_src(), False)
  90. tt('bld.bldnode is bld', bld.bldnode.is_bld(), True)
  91. tt('bld.root is bld', bld.root.is_bld(), False)
  92. tt('bld.root is src', bld.root.is_src(), False)
  93. nf = bld.srcnode.make_node('abc')
  94. nf.write("aha")
  95. nf.get_bld_sig()
  96. tt('find_resource src/abc', bld.srcnode.find_resource(['abc']), nf)
  97. tt('find_or_declare src/abc', bld.srcnode.find_or_declare(['abc']), bld.bldnode.make_node(['abc']))
  98. tt('src.get_bld()', bld.srcnode.get_bld(), bld.bldnode)
  99. tt('bld.get_src()', bld.bldnode.get_src(), bld.srcnode)
  100. stupid_build = bld.bldnode.make_node(['abc'])
  101. stupid_build.write("heheh")
  102. tt('find_or_declare src/abc', bld.srcnode.find_or_declare(['abc']), stupid_build)
  103. tt('find_resource src/abc', bld.srcnode.find_resource(['abc']), stupid_build)
  104. bld = Build.BuildContext()
  105. bld.top_dir = ss.abspath()
  106. bld.out_dir = bb.abspath()
  107. bld.init_dirs()
  108. create('src/a.txt')
  109. create('src/b.txt')
  110. nd = bld.srcnode.make_node('c.txt')
  111. nd.write("test")
  112. create('d.TXT')
  113. nd2 = bld.srcnode.make_node('d.TXT')
  114. nd2.write("test")
  115. tt("ant_glob ->", len(bld.srcnode.ant_glob('*.txt', flat=False)), 1)
  116. tt("ant_glob (icase) ->", len(bld.srcnode.ant_glob('*.txt', flat=False, ignorecase=True)), 2)
  117. #print("ant_glob src ->", bld.srcnode.ant_glob('*.txt'))
  118. def abspath(self):
  119. try:
  120. return self.cache_abspath
  121. except AttributeError:
  122. pass
  123. if not self.parent:
  124. val = ''
  125. elif not self.parent.name:
  126. val = self.name + '\\'
  127. else:
  128. val = self.parent.abspath().rstrip('\\') + '\\' + self.name
  129. self.cache_abspath = val
  130. return val
  131. # the local class will be unused soon enough
  132. old_abspath = bld.node_class.abspath
  133. bld.node_class.abspath = abspath
  134. unc1 = '\\\\computer\\share\\file'
  135. lst = Utils.split_path_win32(unc1)
  136. node = bld.root.make_node(lst)
  137. tt('UNC head node', lst[0], '\\\\computer')
  138. tt('UNC share path', node.abspath(), unc1)
  139. unc2 = '\\\\?\\C:\\foo'
  140. lst = Utils.split_path_win32(unc2)
  141. node = bld.root.make_node(lst)
  142. tt('UNC long path', node.abspath(), 'C:\\foo')
  143. if errors:
  144. bld.fatal('There are test failures ^^')