distro-manifest-generator: add support for JSON output format
[AGL/meta-agl.git] / meta-agl-profile-core / recipes-core / distro-build-manifest / distro-build-manifest.bb
1 SUMMARY = "Distribution build manifest"
2 DESCRIPTION = "The folder /etc/platform-info contains build manifest (SPEC-720)."
3 LICENSE = "MIT"
4
5 # information distributed by the package is machine specific
6 PACKAGE_ARCH = "${MACHINE_ARCH}"
7
8 # dependencies of ${DISTRO_MANIFEST_GENERATOR}
9 DEPENDS = "coreutils-native bash-native git-native gawk-native sed-native jq-native"
10
11 # force a rebuild everytime a build is started
12 do_compile[nostamp] = "1"
13
14 # borrowed to os-release.bb (output format is very close)
15 python do_compilestep1 () {
16    import shutil
17    with open(d.expand('${B}/bbinfo-deploy'),'w') as f:
18       allkeys=[]
19       for field in d.getVar('BUILD_MANIFEST_FIELDS_DEPLOY').split():
20          key='DIST_BB_{0}'.format(field)
21          allkeys.append(key)
22          value=d.getVar(field)
23          if value:
24             f.write('{0}="{1}"\n'.format(key,value))
25       f.write('declare -A BITBAKE_VARS\nBITBAKE_VARS[deploy]="%s"' % ' '.join(allkeys))
26
27    with open(d.expand('${B}/bbinfo-target'),'w') as f:
28       allkeys=[]
29       for field in d.getVar('BUILD_MANIFEST_FIELDS_TARGET').split():
30          key='DIST_BB_{0}'.format(field)
31          allkeys.append(key)
32          value=d.getVar(field)
33          if value:
34             f.write('{0}="{1}"\n'.format(key,value))
35       f.write('declare -A BITBAKE_VARS\nBITBAKE_VARS[target]="%s"' % ' '.join(allkeys))
36
37    with open(d.expand('${B}/bbinfo-sdk'),'w') as f:
38       allkeys=[]
39       for field in d.getVar('BUILD_MANIFEST_FIELDS_SDK').split():
40          key='DIST_BB_{0}'.format(field)
41          allkeys.append(key)
42          value=d.getVar(field)
43          if value:
44             f.write('{0}="{1}"\n'.format(key,value))
45       f.write('declare -A BITBAKE_VARS\nBITBAKE_VARS[sdk]="%s"' % ' '.join(allkeys))
46 }
47
48 do_compilestep2 () {
49     rc=99
50     outfile=${B}/build-info
51     if [ -x "${DISTRO_MANIFEST_GENERATOR}" -a -f "${DISTRO_SETUP_MANIFEST}" ]; then
52                 rc=0
53                 for     format in bash json; do
54                         if [ "$format" = "json" ]; then
55                                 ext=".json"
56                         else
57                                 ext=""
58                         fi
59                         for mode in deploy target sdk; do
60                                 ${DISTRO_MANIFEST_GENERATOR} -m $mode -f $format -s ${B}/bbinfo-${mode} ${DISTRO_SETUP_MANIFEST} >${outfile}-${mode}${ext}
61                                 rc=$?
62                                 if [ $rc -ne 0 ]; then
63                                         break
64                                 fi
65                         done
66                 done
67     else
68         if [ -z "${DISTRO_MANIFEST_GENERATOR}" ]; then
69             echo "The name of the generation script is not defined."
70         elif [ ! -f "${DISTRO_MANIFEST_GENERATOR}" ]; then
71             echo "Generation script ${DISTRO_MANIFEST_GENERATOR} is missing."
72         elif [ ! -x "${DISTRO_MANIFEST_GENERATOR}" ]; then
73             echo "Generation script ${DISTRO_MANIFEST_GENERATOR} isn't executable."
74         fi
75         if [ -z "${DISTRO_SETUP_MANIFEST}" ]; then
76             echo "The name of the data file is not defined."
77         elif [ ! -f "${DISTRO_SETUP_MANIFEST}" ]; then
78             echo "Data file ${DISTRO_SETUP_MANIFEST} is missing."
79         fi
80         echo "You can try to rerun aglsetup.sh to solve that issue."
81         echo "You can also try to source agl-init-build-env instead of oe-init-build-env."
82     fi
83
84     if [ "$rc" -ne  0 ]; then
85         echo "distro-build-manifest generation failed."
86     fi
87     return $rc
88 }
89
90 do_compilestep1[vardeps] += " ${BUILD_MANIFEST_FIELDS_DEPLOY}"
91 do_compilestep1[vardeps] += " ${BUILD_MANIFEST_FIELDS_TARGET}"
92 do_compilestep1[vardeps] += " ${BUILD_MANIFEST_FIELDS_SDK}"
93
94 # combine the two steps
95 python do_compile() {
96    bb.build.exec_func("do_compilestep1",d)
97    bb.build.exec_func("do_compilestep2",d)
98 }
99
100 do_install () {
101     # install in target dir
102     install -d ${D}${sysconfdir}/platform-info
103     install -m 0644 build-info-target ${D}${sysconfdir}/platform-info/build
104     install -m 0644 build-info-target.json ${D}${sysconfdir}/platform-info/build.json
105
106     # also copy in deploy dir
107     install -d ${DEPLOY_DIR_IMAGE}
108     install -m 0644 build-info-deploy ${DEPLOY_DIR_IMAGE}/build-info
109     install -m 0644 build-info-deploy.json ${DEPLOY_DIR_IMAGE}/build-info.json
110
111     # copy into sdk deploy dir
112     install -d ${DEPLOY_DIR}/sdk
113     install -m 0644 build-info-sdk ${DEPLOY_DIR}/sdk/${SDK_NAME}.build-info
114     install -m 0644 build-info-sdk.json ${DEPLOY_DIR}/sdk/${SDK_NAME}.build-info.json
115
116     # and copy to nativesdk package
117     # TODO
118 }
119
120 # list of variables to add to the various manifests
121 # smalles one is 'target', then 'deploy' and finally 'sdk'
122 BUILD_MANIFEST_FIELDS_TARGET = "\
123     MACHINE_ARCH \
124     MACHINEOVERRIDES \
125     MACHINE_FEATURES \
126     DISTRO_CODENAME \
127     DISTRO_FEATURES \
128     DISTRO_BRANCH_VERSION_TAG \
129     AGLVERSION \
130     AGL_BRANCH \
131     AGLRELEASETYPE \
132 "
133
134 BUILD_MANIFEST_FIELDS_DEPLOY = "\
135     ${BUILD_MANIFEST_FIELDS_TARGET} \
136     DISTRO \
137     DISTRO_VERSION \
138     DISTROOVERRIDES \
139     TUNE_FEATURES \
140     TUNE_PKGARCH \
141     ALL_MULTILIB_PACKAGE_ARCHS \
142 "
143
144 BUILD_MANIFEST_FIELDS_SDK = "\
145     ${BUILD_MANIFEST_FIELDS_DEPLOY} \
146     HOST_SYS \
147     TARGET_SYS \
148     TARGET_VENDOR \
149     SDK_ARCH \
150     SDK_VENDOR \
151     SDK_VERSION \
152     SDK_OS \
153 "
154
155 # dont exec useless tasks
156 do_fetch[noexec] = "1"
157 do_unpack[noexec] = "1"
158 do_patch[noexec] = "1"
159 do_configure[noexec] = "1"
160