xref: /nrf52832-nimble/rt-thread/tools/package.py (revision 104654410c56c573564690304ae786df310c91fc)
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
25# this script is used to build group with package.json instead of SConscript
26import os
27from building import *
28
29def ExtendPackageVar(package, var):
30    v = []
31    if var not in package:
32        return v
33
34    for item in package[var]:
35        v = v + [item]
36
37    return v
38
39def BuildPackage(package):
40    import json
41    f = open(package)
42    package_json = f.read()
43
44    # get package.json path
45    cwd = os.path.dirname(package)
46
47    package = json.loads(package_json)
48
49    # check package name
50    if 'name' not in package:
51        return []
52
53    # get depends
54    depend = ExtendPackageVar(package, 'depends')
55
56    src = []
57    if 'source_files' in package:
58        for src_file in package['source_files']:
59            src_file = os.path.join(cwd, src_file)
60            src += Glob(src_file)
61
62    CPPPATH = []
63    if 'CPPPATH' in package:
64        for path in package['CPPPATH']:
65            if path.startswith('/') and os.path.isdir(path):
66                CPPPATH = CPPPATH + [path]
67            else:
68                CPPPATH = CPPPATH + [os.path.join(cwd, path)]
69
70    CPPDEFINES = ExtendPackageVar(package, 'CPPDEFINES')
71
72    objs = DefineGroup(package['name'], src, depend = depend, CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
73
74    return objs
75