manifest.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. # Copyright (C) 2003, 2004 Chris Larson
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 2 as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. import os, sys
  19. import bb, bb.data
  20. def getfields(line):
  21. fields = {}
  22. fieldmap = ( "pkg", "src", "dest", "type", "mode", "uid", "gid", "major", "minor", "start", "inc", "count" )
  23. for f in xrange(len(fieldmap)):
  24. fields[fieldmap[f]] = None
  25. if not line:
  26. return None
  27. splitline = line.split()
  28. if not len(splitline):
  29. return None
  30. try:
  31. for f in xrange(len(fieldmap)):
  32. if splitline[f] == '-':
  33. continue
  34. fields[fieldmap[f]] = splitline[f]
  35. except IndexError:
  36. pass
  37. return fields
  38. def parse (mfile, d):
  39. manifest = []
  40. while 1:
  41. line = mfile.readline()
  42. if not line:
  43. break
  44. if line.startswith("#"):
  45. continue
  46. fields = getfields(line)
  47. if not fields:
  48. continue
  49. manifest.append(fields)
  50. return manifest
  51. def emit (func, manifest, d):
  52. #str = "%s () {\n" % func
  53. str = ""
  54. for line in manifest:
  55. emittedline = emit_line(func, line, d)
  56. if not emittedline:
  57. continue
  58. str += emittedline + "\n"
  59. # str += "}\n"
  60. return str
  61. def mangle (func, line, d):
  62. import copy
  63. newline = copy.copy(line)
  64. src = bb.data.expand(newline["src"], d)
  65. if src:
  66. if not os.path.isabs(src):
  67. src = "${WORKDIR}/" + src
  68. dest = newline["dest"]
  69. if not dest:
  70. return
  71. if dest.startswith("/"):
  72. dest = dest[1:]
  73. if func is "do_install":
  74. dest = "${D}/" + dest
  75. elif func is "do_populate":
  76. dest = "${WORKDIR}/install/" + newline["pkg"] + "/" + dest
  77. elif func is "do_stage":
  78. varmap = {}
  79. varmap["${bindir}"] = "${STAGING_DIR}/${HOST_SYS}/bin"
  80. varmap["${libdir}"] = "${STAGING_DIR}/${HOST_SYS}/lib"
  81. varmap["${includedir}"] = "${STAGING_DIR}/${HOST_SYS}/include"
  82. varmap["${datadir}"] = "${STAGING_DATADIR}"
  83. matched = 0
  84. for key in varmap.keys():
  85. if dest.startswith(key):
  86. dest = varmap[key] + "/" + dest[len(key):]
  87. matched = 1
  88. if not matched:
  89. newline = None
  90. return
  91. else:
  92. newline = None
  93. return
  94. newline["src"] = src
  95. newline["dest"] = dest
  96. return newline
  97. def emit_line (func, line, d):
  98. import copy
  99. newline = copy.deepcopy(line)
  100. newline = mangle(func, newline, d)
  101. if not newline:
  102. return None
  103. str = ""
  104. type = newline["type"]
  105. mode = newline["mode"]
  106. src = newline["src"]
  107. dest = newline["dest"]
  108. if type is "d":
  109. str = "install -d "
  110. if mode:
  111. str += "-m %s " % mode
  112. str += dest
  113. elif type is "f":
  114. if not src:
  115. return None
  116. if dest.endswith("/"):
  117. str = "install -d "
  118. str += dest + "\n"
  119. str += "install "
  120. else:
  121. str = "install -D "
  122. if mode:
  123. str += "-m %s " % mode
  124. str += src + " " + dest
  125. del newline
  126. return str