042c0fa946dc8470ba65e31aaab573b4fb2f7557
[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 # Warning on missing test/debug/coverage packages disabled by default
45 # for now to reduce build output clutter.
46 AGLWGT_PACKAGE_WARN ?= "0"
47
48 # Whether the widget should be auto-installed on first boot
49 AGLWGT_AUTOINSTALL ?= "1"
50
51 # Signature keys
52 # These are default keys for development purposes !
53 # Change it for production.
54 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"
55 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"
56
57 export WGTPKG_AUTOSIGN_0
58 export WGTPKG_AUTOSIGN_1
59
60 python __anonymous () {
61     # NOTE: AGLWGT_CMAKE_CONFIGURE_ARGS is not updated directly here,
62     #       but via the prefunc below to avoid issues around anonymous
63     #       python ordering conflicts with e.g. externalsrc.bbclass.
64     if bb.data.inherits_class("cmake", d):
65         d.appendVarFlag('do_compile', 'prefuncs', ' aglwgt_cmake_configure')
66 }
67
68 python aglwgt_cmake_configure () {
69     # Define CONFIGURE_FLAGS appropriately if cmake.bbclass has been
70     # inherited, see description of AGLWGT_CMAKE_CONFIGURE_ARGS above
71     # for more details.
72     cmake_config_args = d.getVar("AGLWGT_CMAKE_CONFIGURE_ARGS")
73     if bb.data.inherits_class("cmake", d) and cmake_config_args:
74         d.appendVar("AGLWGT_EXTRA_BUILD_ARGS", ' CONFIGURE_ARGS="' + cmake_config_args + '"')
75         d.appendVarFlag("AGLWGT_EXTRA_BUILD_ARGS", "vardeps", " AGLWGT_CMAKE_CONFIGURE_ARGS")
76 }
77
78 # Placeholder to keep things like externalsrc that prefunc or append
79 # do_configure working as expected.
80 aglwgt_do_configure() {
81     true
82 }
83
84 aglwgt_do_compile() {
85     bldcmd=${S}/autobuild/agl/autobuild
86     if [ ! -x "$bldcmd" ]; then
87         bbfatal "Missing autobuild/agl/autobuild script"
88     fi
89
90     if [ "${S}" != "${B}" ]; then
91         rm -rf ${B}
92         mkdir -p ${B}
93         cd ${B}
94     fi
95
96     if ! $bldcmd package BUILD_DIR=${B}/build-release ${AGLWGT_EXTRA_BUILD_ARGS}; then
97         bbwarn "Target: package failed"
98     fi
99
100     if ! $bldcmd package-debug BUILD_DIR_DEBUG=${B}/build-debug ${AGLWGT_EXTRA_BUILD_ARGS}; then
101         bbwarn "Target: package-debug failed"
102     fi
103
104     if echo ${BPN} | grep -q '^agl-service-' || [ "${AGLWGT_HAVE_TESTS}" = "1" ]; then
105         if ! $bldcmd package-test BUILD_DIR_TEST=${B}/build-test ${AGLWGT_EXTRA_BUILD_ARGS}; then
106             bbwarn "Target: package-test failed"
107         fi
108
109         if ! $bldcmd package-coverage BUILD_DIR_COVERAGE=${B}/build-coverage ${AGLWGT_EXTRA_BUILD_ARGS}; then
110             bbwarn "Target: package-coverage failed"
111         fi
112     fi
113 }
114
115 POST_INSTALL_LEVEL ?= "10"
116 POST_INSTALL_SCRIPT ?= "${POST_INSTALL_LEVEL}-${PN}.sh"
117
118 EXTRA_WGT_POSTINSTALL ?= ""
119
120 aglwgt_do_install() {
121     DEST=release
122     if [ "${AGLWGT_AUTOINSTALL_${PN}}" = "0" ]; then
123         DEST=manualinstall
124     fi
125
126     if [ "$(find ${B}/build-release -name '*.wgt' -maxdepth 1)" ]; then
127         install -d ${D}/usr/AGL/apps/$DEST
128         install -m 0644 ${B}/build-release/*.wgt ${D}/usr/AGL/apps/$DEST/
129     else
130         bbfatal "no package found in widget directory"
131     fi
132
133     for t in test debug coverage; do
134         if [ "$(find ${B}/build-${t} -name *-${t}.wgt -maxdepth 1)" ]; then
135             install -d ${D}/usr/AGL/apps/${t}
136             install -m 0644 ${B}/build-${t}/*-${t}.wgt ${D}/usr/AGL/apps/${t}/
137         elif [ "${AGLWGT_PACKAGE_WARN}" = "1" ]; then
138             if [ "$t" != "test" -a "$t" != "coverage" ]; then
139                 bbwarn "no package found in ${t} widget directory"
140             elif echo ${BPN} | grep -q '^agl-service-' || [ "${AGLWGT_HAVE_TESTS}" = "1" ]; then
141                 bbwarn "no package found in ${t} widget directory"
142             fi
143         fi
144     done
145
146     if [ "${AGLWGT_AUTOINSTALL}" != "0" ]; then
147         # For now assume autoinstall of the release versions
148         rm -rf ${D}/usr/AGL/apps/autoinstall
149         ln -sf release ${D}/usr/AGL/apps/autoinstall
150
151         APP_FILES=""
152         for file in ${D}/usr/AGL/apps/autoinstall/*.wgt; do
153             APP_FILES="${APP_FILES} $(basename $file)";
154         done
155         install -d ${D}/${sysconfdir}/agl-postinsts
156         cat > ${D}/${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT} <<EOF
157 #!/bin/sh -e
158 for file in ${APP_FILES}; do
159     /usr/bin/afm-install install /usr/AGL/apps/autoinstall/\$file
160 done
161 sync
162 ${EXTRA_WGT_POSTINSTALL}
163 EOF
164         chmod a+x ${D}/${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT}
165     fi
166 }
167
168 PACKAGES += "${PN}-test ${PN}-debug ${PN}-coverage"
169
170 FILES_${PN} += " \
171     /usr/AGL/apps/release/*.wgt \
172     /usr/AGL/apps/autoinstall \
173     /usr/AGL/apps/manualinstall \
174     ${sysconfdir}/agl-postinsts/${POST_INSTALL_SCRIPT} \
175 "
176 FILES_${PN}-test = "/usr/AGL/apps/test/*.wgt"
177 FILES_${PN}-debug = "/usr/AGL/apps/debug/*.wgt"
178 FILES_${PN}-coverage = "/usr/AGL/apps/coverage/*.wgt"
179
180 # Test widgets need the parent widget and the test framework
181 RDEPENDS_${PN}-test = "${PN} afb-test"
182
183 EXPORT_FUNCTIONS do_configure do_compile do_install