SPEC-3723: restructure meta-agl-demo
[AGL/meta-agl-demo.git] / 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     timestamp=${DATETIME}
51     outfile=${B}/build-info
52     if [ -x "${DISTRO_MANIFEST_GENERATOR}" -a -f "${DISTRO_SETUP_MANIFEST}" ]; then
53                 rc=0
54                 for     format in bash json; do
55                         if [ "$format" = "json" ]; then
56                                 ext=".json"
57                         else
58                                 ext=""
59                         fi
60                         for mode in deploy target sdk; do
61                                 ${DISTRO_MANIFEST_GENERATOR} -m $mode -f $format -t $timestamp -s ${B}/bbinfo-${mode} ${DISTRO_SETUP_MANIFEST} >${outfile}-${mode}${ext}
62                                 rc=$?
63                                 if [ $rc -ne 0 ]; then
64                                         break
65                                 fi
66                         done
67                 done
68     else
69         if [ -z "${DISTRO_MANIFEST_GENERATOR}" ]; then
70             echo "The name of the generation script is not defined."
71         elif [ ! -f "${DISTRO_MANIFEST_GENERATOR}" ]; then
72             echo "Generation script ${DISTRO_MANIFEST_GENERATOR} is missing."
73         elif [ ! -x "${DISTRO_MANIFEST_GENERATOR}" ]; then
74             echo "Generation script ${DISTRO_MANIFEST_GENERATOR} isn't executable."
75         fi
76         if [ -z "${DISTRO_SETUP_MANIFEST}" ]; then
77             echo "The name of the data file is not defined."
78         elif [ ! -f "${DISTRO_SETUP_MANIFEST}" ]; then
79             echo "Data file ${DISTRO_SETUP_MANIFEST} is missing."
80         fi
81         echo "You can try to rerun aglsetup.sh to solve that issue."
82         echo "You can also try to source agl-init-build-env instead of oe-init-build-env."
83     fi
84
85     if [ "$rc" -ne  0 ]; then
86         echo "distro-build-manifest generation failed."
87     fi
88     return $rc
89 }
90
91 do_compilestep1[vardeps] += " ${BUILD_MANIFEST_FIELDS_DEPLOY}"
92 do_compilestep1[vardeps] += " ${BUILD_MANIFEST_FIELDS_TARGET}"
93 do_compilestep1[vardeps] += " ${BUILD_MANIFEST_FIELDS_SDK}"
94
95 # avoid errors "ERROR: When reparsing .../distro-build-manifest/distro-build-manifest.bb.do_compile, the basehash value changed from .... to .... . The metadata is not deterministic and this needs to be fixed."
96 do_compilestep2[vardepsexclude] = "DATETIME"
97
98 # combine the two steps
99 python do_compile() {
100    bb.build.exec_func("do_compilestep1",d)
101    bb.build.exec_func("do_compilestep2",d)
102 }
103
104 do_install () {
105     # install in target dir
106     install -d ${D}${sysconfdir}/platform-info
107     install -m 0644 build-info-target ${D}${sysconfdir}/platform-info/build
108     install -m 0644 build-info-target.json ${D}${sysconfdir}/platform-info/build.json
109
110     # also copy in deploy dir
111     install -d ${DEPLOY_DIR_IMAGE}
112     install -m 0644 build-info-deploy ${DEPLOY_DIR_IMAGE}/build-info
113     install -m 0644 build-info-deploy.json ${DEPLOY_DIR_IMAGE}/build-info.json
114
115     # copy into sdk deploy dir
116     install -d ${DEPLOY_DIR}/sdk
117     install -m 0644 build-info-sdk ${DEPLOY_DIR}/sdk/${SDK_NAME}.build-info
118     install -m 0644 build-info-sdk.json ${DEPLOY_DIR}/sdk/${SDK_NAME}.build-info.json
119
120     # and copy to nativesdk package
121     # TODO
122 }
123
124 # list of variables to add to the various manifests
125 # smalles one is 'target', then 'deploy' and finally 'sdk'
126 BUILD_MANIFEST_FIELDS_TARGET = "\
127     MACHINE_ARCH \
128     MACHINEOVERRIDES \
129     MACHINE_FEATURES \
130     DISTRO_CODENAME \
131     DISTRO_FEATURES \
132     DISTRO_BRANCH_VERSION_TAG \
133     AGLVERSION \
134     AGL_BRANCH \
135     AGLRELEASETYPE \
136 "
137
138 BUILD_MANIFEST_FIELDS_DEPLOY = "\
139     ${BUILD_MANIFEST_FIELDS_TARGET} \
140     DISTRO \
141     DISTRO_VERSION \
142     DISTROOVERRIDES \
143     TUNE_FEATURES \
144     TUNE_PKGARCH \
145     ALL_MULTILIB_PACKAGE_ARCHS \
146 "
147
148 BUILD_MANIFEST_FIELDS_SDK = "\
149     ${BUILD_MANIFEST_FIELDS_DEPLOY} \
150     HOST_SYS \
151     TARGET_SYS \
152     TARGET_VENDOR \
153     SDK_ARCH \
154     SDK_VENDOR \
155     SDK_VERSION \
156     SDK_OS \
157 "
158
159 # dont exec useless tasks
160 do_fetch[noexec] = "1"
161 do_unpack[noexec] = "1"
162 do_patch[noexec] = "1"
163 do_configure[noexec] = "1"
164