meta-app-framework: Make autobuild failures fatal in aglwgt.bbclass
[AGL/meta-agl.git] / meta-app-framework / classes / aglwgt.bbclass
1 #
2 # aglwgt bbclass
3 #
4 # Jan-Simon Moeller, jsmoeller@linuxfoundation.org
5 #
6 # This class expects a "make package" target in the makefile
7 # which creates the wgt files in the package/ subfolder.
8 # The makefile needs to use wgtpkg-pack.
9 #
10
11 # 'wgtpkg-pack' in af-main-native is required.
12 DEPENDS_append = " af-main-native"
13
14 # for bindings af-binder is required.
15 DEPENDS_append = " af-binder"
16
17 # for bindings that use the cmake-apps-module
18 DEPENDS_append = " cmake-apps-module-native"
19
20 # for hal bindings genskel is required.
21 DEPENDS_append = " af-binder-devtools-native"
22
23 # Re-enable strip for qmake based projects (default value is "echo")
24 OE_QMAKE_STRIP = "${STRIP}"
25
26 # Extra build arguments passed to the autobuild script invocations
27 AGLWGT_EXTRA_BUILD_ARGS ?= 'VERBOSE=TRUE BUILD_ARGS="${PARALLEL_MAKE}"'
28
29 # CMake based widgets that inherit cmake.bbclass will have the
30 # following automatically appended to AGLWGT_EXTRA_BUILD_ARGS as
31 # the value of CONFIGURE_FLAGS.  This definition may need to be
32 # extended to include more of what is passed in cmake.bbclass's
33 # do_configure if it is found insufficient.  Using the generated
34 # toolchain.cmake file does fix issues with respect to finding the
35 # Qt5 CMake modules that seem difficult to fix otherwise, so at the
36 # very minimum it should be present.
37 AGLWGT_CMAKE_CONFIGURE_ARGS ?= "-DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake ${EXTRA_OECMAKE}"
38
39 # Only widgets with recipe names starting with agl-service- are
40 # assumed to have tests by default, set this to "1" to force
41 # building/packaging of the test widget for other widgets.
42 AGLWGT_HAVE_TESTS ?= "0"
43
44 # Whether the widget should be auto-installed on first boot
45 AGLWGT_AUTOINSTALL ?= "1"
46
47 # Signature keys
48 # These are default keys for development purposes !
49 # Change it for production.
50 WGTPKG_AUTOSIGN_0_agl-sign-wgts ??= "${WORKDIR}/recipe-sysroot-native/usr/share/afm/keys/developer.key.pem:${WORKDIR}/recipe-sysroot-native/usr/share/afm/certs/developer.cert.pem"
51 WGTPKG_AUTOSIGN_1_agl-sign-wgts ??= "${WORKDIR}/recipe-sysroot-native/usr/share/afm/keys/platform.key.pem:${WORKDIR}/recipe-sysroot-native/usr/share/afm/certs/platform.cert.pem"
52
53 export WGTPKG_AUTOSIGN_0
54 export WGTPKG_AUTOSIGN_1
55
56 python __anonymous () {
57     # NOTE: AGLWGT_CMAKE_CONFIGURE_ARGS is not updated directly here,
58     #       but via the prefunc below to avoid issues around anonymous
59     #       python ordering conflicts with e.g. externalsrc.bbclass.
60     if bb.data.inherits_class("cmake", d):
61         d.appendVarFlag('do_compile', 'prefuncs', ' aglwgt_cmake_configure')
62 }
63
64 python aglwgt_cmake_configure () {
65     # Define CONFIGURE_FLAGS appropriately if cmake.bbclass has been
66     # inherited, see description of AGLWGT_CMAKE_CONFIGURE_ARGS above
67     # for more details.
68     cmake_config_args = d.getVar("AGLWGT_CMAKE_CONFIGURE_ARGS")
69     if bb.data.inherits_class("cmake", d) and cmake_config_args:
70         d.appendVar("AGLWGT_EXTRA_BUILD_ARGS", ' CONFIGURE_ARGS="' + cmake_config_args + '"')
71         d.appendVarFlag("AGLWGT_EXTRA_BUILD_ARGS", "vardeps", " AGLWGT_CMAKE_CONFIGURE_ARGS")
72 }
73
74 # Placeholder to keep things like externalsrc that prefunc or append
75 # do_configure working as expected.
76 aglwgt_do_configure() {
77     true
78 }
79
80 aglwgt_do_compile() {
81     bldcmd=${S}/autobuild/agl/autobuild
82     if [ ! -x "$bldcmd" ]; then
83         bbfatal "Missing autobuild/agl/autobuild script"
84     fi
85
86     if [ "${S}" != "${B}" ]; then
87         rm -rf ${B}
88         mkdir -p ${B}
89         cd ${B}
90     fi
91
92     $bldcmd package BUILD_DIR=${B}/build-release ${AGLWGT_EXTRA_BUILD_ARGS}
93     $bldcmd package-debug BUILD_DIR_DEBUG=${B}/build-debug ${AGLWGT_EXTRA_BUILD_ARGS}
94
95     if echo ${BPN} | grep -q '^agl-service-' || [ "${AGLWGT_HAVE_TESTS}" = "1" ]; then
96         # Only try building the test widget if there's source for it, to avoid spurious errors
97         if [ -f ${S}/test/CMakeLists.txt ]; then
98             $bldcmd package-test BUILD_DIR_TEST=${B}/build-test ${AGLWGT_EXTRA_BUILD_ARGS}
99         fi
100
101         # The coverage widget should always build
102         $bldcmd package-coverage BUILD_DIR_COVERAGE=${B}/build-coverage ${AGLWGT_EXTRA_BUILD_ARGS}
103     fi
104 }
105
106 POST_INSTALL_LEVEL ?= "10"
107 POST_INSTALL_SCRIPT ?= "${POST_INSTALL_LEVEL}-${PN}.sh"
108
109 EXTRA_WGT_POSTINSTALL ?= ""
110
111 aglwgt_do_install() {
112     DEST=release
113     if [ "${AGLWGT_AUTOINSTALL_${PN}}" = "0" ]; then
114         DEST=manualinstall
115     fi
116
117     if [ "$(find ${B}/build-release -name '*.wgt' -maxdepth 1)" ]; then
118         install -d ${D}/usr/AGL/apps/$DEST
119         install -m 0644 ${B}/build-release/*.wgt ${D}/usr/AGL/apps/$DEST/
120     else
121         bbfatal "no package found in widget directory"
122     fi
123
124     for t in debug coverage test; do
125         if [ "$(find ${B}/build-${t} -name *-${t}.wgt -maxdepth 1)" ]; then
126             install -d ${D}/usr/AGL/apps/${t}
127             install -m 0644 ${B}/build-${t}/*-${t}.wgt ${D}/usr/AGL/apps/${t}/
128         elif [ "$t" = "debug" ]; then
129             bbfatal "no package found in ${t} widget directory"
130         elif echo ${BPN} | grep -q '^agl-service-' || [ "${AGLWGT_HAVE_TESTS}" = "1" ]; then
131             if [ "$t" = "coverage" -o -f ${S}/test/CMakeLists.txt ]; then
132                 bbfatal "no package found in ${t} widget directory"
133             fi
134         fi
135     done
136
137     if [ "${AGLWGT_AUTOINSTALL}" != "0" ]; then
138         # For now assume autoinstall of the release versions
139         rm -rf ${D}/usr/AGL/apps/autoinstall
140         ln -sf release ${D}/usr/AGL/apps/autoinstall
141
142         APP_FILES=""
143         for file in ${D}/usr/AGL/apps/autoinstall/*.wgt; do
144             APP_FILES="${APP_FILES} $(basename $file)";
145         done
146         install -d ${D}/${sysconfdir}/agl-postinsts
147         cat > ${D}/${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT} <<EOF
148 #!/bin/sh -e
149 for file in ${APP_FILES}; do
150     /usr/bin/afm-install install /usr/AGL/apps/autoinstall/\$file
151 done
152 sync
153 ${EXTRA_WGT_POSTINSTALL}
154 EOF
155         chmod a+x ${D}/${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT}
156     fi
157 }
158
159 PACKAGES += "${PN}-test ${PN}-debug ${PN}-coverage"
160
161 FILES_${PN} += " \
162     /usr/AGL/apps/release/*.wgt \
163     /usr/AGL/apps/autoinstall \
164     /usr/AGL/apps/manualinstall \
165     ${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT} \
166 "
167 FILES_${PN}-test = "/usr/AGL/apps/test/*.wgt"
168 FILES_${PN}-debug = "/usr/AGL/apps/debug/*.wgt"
169 FILES_${PN}-coverage = "/usr/AGL/apps/coverage/*.wgt"
170
171 # Test widgets need the parent widget and the test framework
172 RDEPENDS_${PN}-test = "${PN} afb-test"
173
174 EXPORT_FUNCTIONS do_configure do_compile do_install