package.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # File : package.py
  3. # This file is part of RT-Thread RTOS
  4. # COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
  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 as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. # Change Logs:
  21. # Date Author Notes
  22. # 2015-04-10 Bernard First version
  23. #
  24. # this script is used to build group with package.json instead of SConscript
  25. import os
  26. import json
  27. from building import *
  28. def ExtendPackageVar(package, var):
  29. v = []
  30. if var not in package:
  31. return v
  32. for item in package[var]:
  33. v = v + [item]
  34. return v
  35. def BuildPackage(package = None):
  36. if package is None:
  37. package = os.path.join(GetCurrentDir(), 'package.json')
  38. if not os.path.isfile(package):
  39. print("%s/package.json not found" % GetCurrentDir())
  40. return []
  41. f = open(package)
  42. package_json = f.read()
  43. # get package.json path
  44. cwd = os.path.dirname(package)
  45. package = json.loads(package_json)
  46. # check package name
  47. if 'name' not in package or 'type' not in package or package['type'] != 'rt-package':
  48. return []
  49. # get depends
  50. depend = ExtendPackageVar(package, 'depends')
  51. src = []
  52. if 'source_files' in package:
  53. for src_file in package['source_files']:
  54. src_file = os.path.join(cwd, src_file)
  55. src += Glob(src_file)
  56. CPPPATH = []
  57. if 'CPPPATH' in package:
  58. for path in package['CPPPATH']:
  59. if path.startswith('/') and os.path.isdir(path):
  60. CPPPATH = CPPPATH + [path]
  61. else:
  62. CPPPATH = CPPPATH + [os.path.join(cwd, path)]
  63. CPPDEFINES = ExtendPackageVar(package, 'CPPDEFINES')
  64. objs = DefineGroup(package['name'], src, depend = depend, CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
  65. return objs