Merge lp:~gcollura/phablet-tools/click-buddy-python into lp:phablet-tools

Proposed by Giulio Collura
Status: Needs review
Proposed branch: lp:~gcollura/phablet-tools/click-buddy-python
Merge into: lp:phablet-tools
Diff against target: 344 lines (+142/-190)
1 file modified
click-buddy (+142/-190)
To merge this branch: bzr merge lp:~gcollura/phablet-tools/click-buddy-python
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+239673@code.launchpad.net

Commit message

Rewrite click-buddy in python 3. Add more options.

Description of the change

Rewrite click-buddy in python 3.
Add more options, such as --extra-params, which allows to add custom cmake parameters during compilation time.

Thanks for your time,
Giulio

To post a comment you must log in.

Unmerged revisions

331. By Giulio Collura

Rewrite click-buddy in python, add option to manage more cmake flags

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'click-buddy'
--- click-buddy 2014-09-09 14:46:55 +0000
+++ click-buddy 2014-10-26 22:09:23 +0000
@@ -1,4 +1,4 @@
1#!/bin/sh1#!/usr/bin/python3
2# This program is free software: you can redistribute it and/or modify it2# This program is free software: you can redistribute it and/or modify it
3# under the terms of the the GNU General Public License version 3, as3# under the terms of the the GNU General Public License version 3, as
4# published by the Free Software Foundation.4# published by the Free Software Foundation.
@@ -12,193 +12,145 @@
12# You should have received a copy of the GNU General Public License12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14#14#
15# Copyright (C) 2014 Canonical, Ltd.15# Copyright (C) 2014 Giulio Collura <giulio.collura@gmail.com>
16#16#
17# Author: Sergio Schvezov <sergio.schvezov@canonical.com>17# Author: Giulio Collura <giulio.collura@gmail.com>
1818
19export LC_ALL=C19import argparse
2020import tempfile
21usage() {21import sys
22cat <<EOF22import os
23usage: $0 [OPTIONS]23import shutil
2424import subprocess
25Creates and runs click apps25
2626from phabletutils.device import AndroidBridge
27OPTIONS:27from phabletutils import fileutils
28 -h Show this message28
29 -s Specify the serial of the device to install (see adb $ADBOPTS devices)29from click.chroot import ClickChroot
3030from gi.repository import Click
31 --bzr-source bzr sources used to backreference the package31from click.build import ClickBuildError, ClickBuilder
32 --dir directory holding the package to build32
33 --provision Install resulting click and run tests33
34 --no-clean Don't clean temporary directories34def error(*msgs):
35 --extra-deps Packages required in the chroot which are not part of the SDK35 print("ERROR:", *msgs, file=sys.stderr)
36 --arch Target architecture, requires a created click chroot36
37 (defaults to arch all)37
38 --framework Target click framework, requires a created click chroot38def execute(command):
39 (defaults to ubuntu-sdk-13.10)39 proc = subprocess.Popen(command, stderr=subprocess.STDOUT, shell=True)
40EOF40 return proc.communicate()
41}41
4242
43ADBOPTS=""43def parse_arguments():
44PROVISION=""44 parser = argparse.ArgumentParser(description="Creates and runs click apps")
45SOURCE=""45
46BZR_SOURCE=""46 parser.add_argument("-s", "--serial",
47NO_CLEAN=""47 help="Specify the serial of the device to install (see adb devices)")
48EXTRA_DEPS=""48 parser.add_argument("-d", "--dir",
49ARCH="all"49 help="Directory holding the package to build, it must have a CMakeLists.txt")
50FRAMEWORK="ubuntu-sdk-13.10"50 parser.add_argument("--bzr-source",
51MAINTMODE=""51 help="bzr sources used to backreference the package")
5252 parser.add_argument("-p", "--provision", help="Install resulting click and run tests",
53TEST_DIR='tests/autopilot'53 action="store_true")
54DEVICE_USER='phablet'54 parser.add_argument("-f", "--framework", default="ubuntu-sdk-14.04",
5555 help="Target click framework, requires a created click chroot")
56ARGS=$(getopt -o s:h -l "maint-mode,extra-deps:,bzr-source:,provision,no-clean,framework:,dir:,arch:,help" -n "$0" -- "$@")56 parser.add_argument("--extra-params", default="",
5757 help="Set extra cmake parameters")
58if [ $? -ne 0 ] ; then58 parser.add_argument("-a", "--arch", default="all",
59 exit 159 help="Target architecture, requires a created click chroot")
60fi60 parser.add_argument("--extra-deps",
61eval set -- "$ARGS"61 help="Packages required in the chroot which are not part of the SDK")
6262 parser.add_argument("--maint-mode",
63while true; do63 help="Automatically remove installed packages from the chroot environment",
64 case "$1" in64 action="store_true")
65 -h|--help)65 return parser.parse_args()
66 usage66
67 exit 067
68 ;;68def main(args):
69 -s)69 build_dir_td = tempfile.TemporaryDirectory(prefix='click-buddy-build-')
70 shift70 install_dir_td = tempfile.TemporaryDirectory(prefix='click-buddy-install-')
71 ADBOPTS="-s $1"71
72 shift72 build_dir = build_dir_td.name
73 ;;73 install_dir = install_dir_td.name
74 --provision)74 working_dir = os.getcwd()
75 shift75
76 PROVISION=176 if args.dir:
77 ;;77 source_dir = os.path.realpath(args.dir)
78 --bzr-source)78 else:
79 shift79 source_dir = os.getcwd()
80 BZR_SOURCE="$1"80
81 shift81 if not os.path.isfile(os.path.join(source_dir, "CMakeLists.txt")):
82 ;;82 error("{0} not a valid source dir".format(source_dir))
83 --dir)83 return -1
84 shift84
85 SOURCE="$(readlink -f $1)"85 cmake_params = "-DINSTALL_TESTS=off -DCLICK_MODE=on " + args.extra_params
86 shift86
87 ;;87 os.chdir(source_dir)
88 --no-clean)88 bzr_revno, err = execute("bzr revno")
89 shift89
90 NO_CLEAN=190 if bzr_revno:
91 ;;91 print(bzr_revno)
92 --arch)92 cmake_params += " -DBZR_REVNO={0} ".format(bzr_revno)
93 shift93
94 ARCH="$1"94 if args.bzr_source:
95 shift95 cmake_params += " -DBZR_SOURCE={0} ".format(args.bzr_source)
96 ;;96
97 --framework)97 os.chdir(build_dir)
98 shift98
99 FRAMEWORK="$1"99 if args.arch == 'all':
100 shift100 execute("cmake {source} {params}".format(source=source_dir, params=cmake_params))
101 ;;101 execute("make DESTDIR={destdir} install".format(destdir=install_dir))
102 --extra-deps)102 else:
103 shift103 chroot = ClickChroot(args.arch, args.framework, "click")
104 EXTRA_DEPS="$1"104 if not chroot.exists():
105 shift105 error("create a chroot: click chroot create")
106 ;;106 return -1
107 --maint-mode)107 if args.extra_deps:
108 shift108 chroot.maint(*["apt-get", "update"])
109 MAINTMODE=1109 chroot.maint(*["apt-get", "install", "--yes"] + args.extra_deps.split(" "))
110 ;;110 chroot.run(*["cmake", cmake_params, source_dir])
111 --)111 chroot.run(*["make"])
112 shift112 chroot.run(*["make", "DESTDIR={0}".format(install_dir), "install"])
113 break113
114 ;;114 manifest = os.path.join(install_dir, "manifest.json")
115 esac115 if not os.path.isfile(manifest):
116done116 error("Building failed, check environment")
117117 return -1
118builddir=$(mktemp -d)118
119installdir=$(mktemp -d)119 # execute("click build {dir}".format(dir=install_dir.name))
120if [ -z "$NO_CLEAN" ]; then120 builder = ClickBuilder()
121 trap 'rm -rf "$builddir" "$installdir"' EXIT121 builder.add_file(install_dir, ".")
122fi122
123123 try:
124if [ -z "$SOURCE" ]; then124 click_pkg = builder.build(working_dir, manifest_path=manifest)
125 SOURCE="$(readlink -f $(pwd))"125 except ClickBuildError as e:
126fi126 error(e)
127127 return -1
128if [ ! -f $SOURCE/CMakeLists.txt ]; then128
129 echo "$SOURCE not a valid source dir"129 print("Click package:", click_pkg)
130 usage130 try:
131 exit 1131 print("Validating:", click_pkg)
132fi132 subprocess.check_call(['click-review', click_pkg])
133133 except subprocess.CalledProcessError as e:
134workdir=$(pwd)134 error(e)
135cd $builddir135 return -1
136136
137CMAKE_PARAMS="-DINSTALL_TESTS=off -DCLICK_MODE=on \137 if args.provision:
138 -DBZR_REVNO=$(cd $SOURCE; bzr revno)"138 if args.serial:
139139 adb = AndroidBridge(args.serial)
140if [ -n "$BZR_SOURCE" ]; then140 else:
141 CMAKE_PARAMS="$CMAKE_PARAMS -DBZR_SOURCE=$BZR_SOURCE"141 adb = AndroidBridge()
142fi142 adb.push(click_pkg, "/tmp")
143143 output = adb.shell("pkcon install-local --allow-untrusted /tmp/%s"
144set -e144 % os.path.basename(click_pkg))
145if [ "$ARCH" = "all" ]; then145 print(output.decode('utf-8'))
146 cmake "$SOURCE" $CMAKE_PARAMS146
147 make DESTDIR=$installdir install147 #TODO: add autopilot support
148else148 # Cleanup chroot
149 if [ -n "$EXTRA_DEPS" ] && [ -z "$MAINTMODE" ]; then149 if args.extra_deps and args.maint_mode:
150 echo "click chroot still doesn\'t support sessions and deps outside the"150 chroot.maint(*["apt-get", "autoremove", "--yes"] + args.extra_deps.split(" "))
151 echo "default sdk were requested, you can optionally use click maint"151
152 echo "to install $EXTRA_DEPS by running"152
153 echo " click chroot -a$ARCH -f$FRAMEWORK maint apt-get update"153if __name__ == '__main__':
154 echo " click chroot -a$ARCH -f$FRAMEWORK maint apt-get install $EXTRA_DEPS"154 args = parse_arguments()
155 echo155 sys.exit(main(args))
156 echo "Your chroot will be unclean from then on, so if you want to"156
157 echo "guarantee clean builds the chroot would need to be recreated."
158 echo
159 echo "Use the undocumented --maint-mode if you want this automated."
160 exit 1
161 fi
162 cd "$SOURCE"
163 if [ -n "$MAINTMODE" ]; then
164 trap 'click chroot -a$ARCH -f$FRAMEWORK maint apt-get autoremove --yes $EXTRA_DEPS' \
165 EXIT HUP INT TERM
166 click chroot -a$ARCH -f$FRAMEWORK maint apt-get update
167 click chroot -a$ARCH -f$FRAMEWORK maint apt-get install --yes $EXTRA_DEPS
168 fi
169 click chroot -a$ARCH -f$FRAMEWORK run cmake $CMAKE_PARAMS
170 click chroot -a$ARCH -f$FRAMEWORK run make
171 click chroot -a$ARCH -f$FRAMEWORK run make DESTDIR=$installdir install
172fi
173
174if [ ! -f "$installdir/manifest.json" ]; then
175 echo Building failed, check environment
176 exit 1
177fi
178
179click build $installdir
180if [ "$workdir" != "$(pwd)" ]; then
181 cp *.click $workdir
182fi
183
184if [ -n "$PROVISION" ]; then
185 set -e
186 for click in *.click; do
187 adb $ADBOPTS push "$click" /tmp
188 adb $ADBOPTS shell sudo -u $DEVICE_USER bash -ic "pkcon install-local --allow-untrusted /tmp/$click"
189 done
190
191 adb $ADBOPTS shell mkdir -p /home/$DEVICE_USER/autopilot
192 adb $ADBOPTS push $SOURCE/tests/autopilot /home/$DEVICE_USER/autopilot
193 adb $ADBOPTS shell chown -R "$DEVICE_USER":"$DEVICE_USER" /home/$DEVICE_USER/autopilot
194 set +e
195
196 echo Allowing autopilot to play well with apparmor
197 phablet-config autopilot --dbus-probe enable
198 echo "Ready to run autopilot"
199fi
200
201if [ -n "$NO_CLEAN" ]; then
202 echo build dir was $builddir
203 echo install dir was $installdir
204fi

Subscribers

People subscribed via source and target branches