meta-agl: split wireplumber to run in multiple instances
[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     wgt="$(find ${B}/build-release -maxdepth 1 -name '*.wgt'| head -n 1)"
118     if [ -n "$wgt" ]; then
119         install -d ${D}/usr/AGL/apps/$DEST
120         install -m 0644 $wgt ${D}/usr/AGL/apps/$DEST/
121     else
122         bbfatal "no package found in widget directory"
123     fi
124
125     for t in debug coverage test; do
126         if [ "$(find ${B}/build-${t} -maxdepth 1 -name *-${t}.wgt)" ]; then
127             install -d ${D}/usr/AGL/apps/${t}
128             install -m 0644 ${B}/build-${t}/*-${t}.wgt ${D}/usr/AGL/apps/${t}/
129         elif [ "$t" = "debug" ]; then
130             # HTML5 widgets complicate things here, need to detect them and
131             # not error out in that case.  ATM this requires looking in the
132             # config.xml of the release widget.
133             rm -rf ${B}/tmp
134             unzip $wgt config.xml -d ${B}/tmp
135             if [ -f ${B}/tmp/config.xml -a \
136                  ! cat ${B}/tmp/config.xml | \
137                      grep -q '^[[:space:]]*<content[[:space:]]\+src="[^\"]*"[[:space:]]\+type="text/html"' ]; then
138                 bbfatal "no package found in ${t} widget directory"
139             fi
140             rm -rf ${B}/tmp
141         elif echo ${BPN} | grep -q '^agl-service-' || [ "${AGLWGT_HAVE_TESTS}" = "1" ]; then
142             if [ "$t" = "coverage" -o -f ${S}/test/CMakeLists.txt ]; then
143                 bbfatal "no package found in ${t} widget directory"
144             fi
145         fi
146     done
147
148     if [ "${AGLWGT_AUTOINSTALL}" != "0" ]; then
149         # For now assume autoinstall of the release versions
150         rm -rf ${D}/usr/AGL/apps/autoinstall
151         ln -sf release ${D}/usr/AGL/apps/autoinstall
152
153         APP_FILES=""
154         for file in ${D}/usr/AGL/apps/autoinstall/*.wgt; do
155             APP_FILES="${APP_FILES} $(basename $file)";
156         done
157         install -d ${D}/${sysconfdir}/agl-postinsts
158         cat > ${D}/${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT} <<EOF
159 #!/bin/sh -e
160 for file in ${APP_FILES}; do
161     /usr/bin/afm-install install /usr/AGL/apps/autoinstall/\$file
162 done
163 sync
164 ${EXTRA_WGT_POSTINSTALL}
165 EOF
166         chmod a+x ${D}/${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT}
167     fi
168 }
169
170 PACKAGES += "${PN}-test ${PN}-debug ${PN}-coverage"
171
172 FILES:${PN} += " \
173     /usr/AGL/apps/release/*.wgt \
174     /usr/AGL/apps/autoinstall \
175     /usr/AGL/apps/manualinstall \
176     ${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT} \
177 "
178 FILES:${PN}-test = "/usr/AGL/apps/test/*.wgt"
179 FILES:${PN}-debug = "/usr/AGL/apps/debug/*.wgt"
180 FILES:${PN}-coverage = "/usr/AGL/apps/coverage/*.wgt"
181
182 # Test widgets need the parent widget and the test framework
183 RDEPENDS:${PN}-test = "${PN} afb-test"
184
185 EXPORT_FUNCTIONS do_configure do_compile do_install