Skip to content

Commit ff871b9

Browse files
committed
Merge pull request #2 from kivy/master
Test
2 parents 15cb4ca + 982ff8b commit ff871b9

13 files changed

Lines changed: 141 additions & 41 deletions

File tree

pythonforandroid/bootstrap.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,24 @@ def get_bootstrap_from_recipes(cls, recipes, ctx):
135135
for name in cls.list_bootstraps()]
136136
acceptable_bootstraps = []
137137
for bs in bootstraps:
138-
ok = True
139138
if not bs.can_be_chosen_automatically:
140-
ok = False
141-
for recipe in bs.recipe_depends:
142-
recipe = Recipe.get_recipe(recipe, ctx)
143-
if any([conflict in recipes for conflict in recipe.conflicts]):
144-
ok = False
145-
break
146-
for recipe in recipes:
147-
recipe = Recipe.get_recipe(recipe, ctx)
148-
if any([conflict in bs.recipe_depends
149-
for conflict in recipe.conflicts]):
150-
ok = False
151-
break
152-
if ok:
153-
acceptable_bootstraps.append(bs)
139+
continue
140+
possible_dependency_lists = expand_dependencies(bs.recipe_depends)
141+
for possible_dependencies in possible_dependency_lists:
142+
ok = True
143+
for recipe in possible_dependencies:
144+
recipe = Recipe.get_recipe(recipe, ctx)
145+
if any([conflict in recipes for conflict in recipe.conflicts]):
146+
ok = False
147+
break
148+
for recipe in recipes:
149+
recipe = Recipe.get_recipe(recipe, ctx)
150+
if any([conflict in possible_dependencies
151+
for conflict in recipe.conflicts]):
152+
ok = False
153+
break
154+
if ok:
155+
acceptable_bootstraps.append(bs)
154156
info('Found {} acceptable bootstraps: {}'.format(
155157
len(acceptable_bootstraps),
156158
[bs.name for bs in acceptable_bootstraps]))
@@ -264,3 +266,20 @@ def fry_eggs(self, sitepackages):
264266
if files:
265267
shprint(sh.mv, '-t', sitepackages, *files)
266268
shprint(sh.rm, '-rf', d)
269+
270+
271+
def expand_dependencies(recipes):
272+
recipe_lists = [[]]
273+
for recipe in recipes:
274+
if isinstance(recipe, (tuple, list)):
275+
new_recipe_lists = []
276+
for alternative in recipe:
277+
for old_list in recipe_lists:
278+
new_list = [i for i in old_list]
279+
new_list.append(alternative)
280+
new_recipe_lists.append(new_list)
281+
recipe_lists = new_recipe_lists
282+
else:
283+
for old_list in recipe_lists:
284+
old_list.append(recipe)
285+
return recipe_lists

pythonforandroid/bootstraps/sdl2/build/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,8 @@ def make_package(args):
311311
entrypoint = spec[1]
312312
options = spec[2:]
313313

314-
foreground = False
315-
if 'foreground' in options:
316-
foreground = True
314+
foreground = 'foreground' in options
315+
sticky = 'sticky' in options
317316

318317
service_names.append(name)
319318
render(
@@ -323,6 +322,7 @@ def make_package(args):
323322
entrypoint=entrypoint,
324323
args=args,
325324
foreground=foreground,
325+
sticky=sticky,
326326
service_id=sid + 1,
327327
)
328328

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonService.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,23 @@ public class PythonService extends Service implements Runnable {
2929
private String serviceEntrypoint;
3030
// Argument to pass to Python code,
3131
private String pythonServiceArgument;
32-
public static Service mService = null;
32+
public static PythonService mService = null;
33+
private Intent startIntent = null;
34+
35+
private boolean autoRestartService = false;
36+
37+
public void setAutoRestartService(boolean restart) {
38+
autoRestartService = restart;
39+
}
3340

3441
public boolean canDisplayNotification() {
3542
return true;
3643
}
3744

45+
public int startType() {
46+
return START_NOT_STICKY;
47+
}
48+
3849
@Override
3950
public IBinder onBind(Intent arg0) {
4051
return null;
@@ -52,6 +63,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
5263
return START_NOT_STICKY;
5364
}
5465

66+
startIntent = intent;
5567
Bundle extras = intent.getExtras();
5668
androidPrivate = extras.getString("androidPrivate");
5769
androidArgument = extras.getString("androidArgument");
@@ -64,31 +76,35 @@ public int onStartCommand(Intent intent, int flags, int startId) {
6476
pythonThread = new Thread(this);
6577
pythonThread.start();
6678

67-
doStartForeground(extras);
79+
if (canDisplayNotification()) {
80+
doStartForeground(extras);
81+
}
6882

69-
return START_NOT_STICKY;
83+
return startType();
7084
}
7185

7286
protected void doStartForeground(Bundle extras) {
73-
if (canDisplayNotification()) {
74-
String serviceTitle = extras.getString("serviceTitle");
75-
String serviceDescription = extras.getString("serviceDescription");
76-
77-
Context context = getApplicationContext();
78-
Notification notification = new Notification(context.getApplicationInfo().icon,
79-
serviceTitle, System.currentTimeMillis());
80-
Intent contextIntent = new Intent(context, PythonActivity.class);
81-
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
82-
PendingIntent.FLAG_UPDATE_CURRENT);
83-
notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent);
84-
startForeground(1, notification);
85-
}
87+
String serviceTitle = extras.getString("serviceTitle");
88+
String serviceDescription = extras.getString("serviceDescription");
89+
90+
Context context = getApplicationContext();
91+
Notification notification = new Notification(context.getApplicationInfo().icon,
92+
serviceTitle, System.currentTimeMillis());
93+
Intent contextIntent = new Intent(context, PythonActivity.class);
94+
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
95+
PendingIntent.FLAG_UPDATE_CURRENT);
96+
notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent);
97+
startForeground(1, notification);
8698
}
8799

88100
@Override
89101
public void onDestroy() {
90102
super.onDestroy();
91103
pythonThread = null;
104+
if (autoRestartService && startIntent != null) {
105+
Log.v("python service", "service restart requested");
106+
startService(startIntent);
107+
}
92108
Process.killProcess(Process.myPid());
93109
}
94110

pythonforandroid/bootstraps/sdl2/build/templates/Service.tmpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010

1111

1212
public class Service{{ name|capitalize }} extends PythonService {
13+
{% if sticky %}
14+
@Override
15+
public int startType() {
16+
return START_STICKY;
17+
}
18+
{% endif %}
19+
20+
{% if not foreground %}
21+
@Override
22+
public boolean canDisplayNotification() {
23+
return false;
24+
}
25+
{% endif %}
26+
1327
@Override
1428
protected void doStartForeground(Bundle extras) {
1529
Context context = getApplicationContext();

pythonforandroid/build.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
212212
android_api = int(android_api)
213213
self.android_api = android_api
214214

215+
if self.android_api >= 21 and self.archs[0].arch == 'armeabi':
216+
error('Asked to build for armeabi architecture with API '
217+
'{}, but API 21 or greater does not support armeabi'.format(
218+
self.android_api))
219+
error('You probably want to build with --arch=armeabi-v7a instead')
220+
exit(1)
221+
215222
android = sh.Command(join(sdk_dir, 'tools', 'android'))
216223
targets = android('list').stdout.decode('utf-8').split('\n')
217224
apis = [s for s in targets if re.match(r'^ *API level: ', s)]

pythonforandroid/graph.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ def _add(self, graph, dependent, dependency):
6060

6161
def conflicts(self, conflict):
6262
graphs = self.graphs
63+
initial_num = len(graphs)
6364
for i in range(len(graphs)):
64-
graph = graphs[len(graphs) - 1 - i]
65+
graph = graphs[initial_num - 1 - i]
6566
if conflict in graph:
66-
graphs.pop(len(graphs) - 1 - i)
67+
graphs.pop(initial_num - 1 - i)
6768
return len(graphs) == 0
6869

6970
def remove_remaining_conflicts(self, ctx):
@@ -227,6 +228,8 @@ def get_recipe_order_and_bootstrap(ctx, names, bs=None):
227228
recipe_loaded.append(name)
228229
graph.remove_remaining_conflicts(ctx)
229230
build_order = list(graph.find_order(0))
231+
build_order, python_modules, bs = get_recipe_order_and_bootstrap(
232+
ctx, build_order + python_modules, bs)
230233
return build_order, python_modules, bs
231234

232235
# Do a final check that the new bs doesn't pull in any conflicts

pythonforandroid/logger.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,3 @@ def printtail(out, name, forecolor, tail_n=0,
217217

218218
return output
219219

220-
221-
from pythonforandroid.util import unistr

pythonforandroid/recipe.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,12 @@ def has_libs(self, arch, *libs):
580580

581581
@classmethod
582582
def recipe_dirs(cls, ctx):
583-
return [ctx.local_recipes,
584-
join(ctx.storage_dir, 'recipes'),
585-
join(ctx.root_dir, "recipes")]
583+
recipe_dirs = []
584+
if ctx.local_recipes is not None:
585+
recipe_dirs.append(ctx.local_recipes)
586+
recipe_dirs.extend([join(ctx.storage_dir, 'recipes'),
587+
join(ctx.root_dir, "recipes")])
588+
return recipe_dirs
586589

587590
@classmethod
588591
def list_recipes(cls, ctx):

0 commit comments

Comments
 (0)