chiark / gitweb /
do not set sdk_path in config.py if using system-provided aapt
authorHans-Christoph Steiner <hans@eds.org>
Tue, 9 Dec 2014 14:20:29 +0000 (15:20 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Sun, 14 Dec 2014 12:26:50 +0000 (13:26 +0100)
By not setting sdk_path when /usr/bin/aapt is found, sdk_path then defaults
to $ANDROID_HOME when its used.  Since in this case, aapt will be used from
the system path, using aapt entirely ignores sdk_path.  If the user runs
`fdroid build` in this setup, sdk_path will be $ANDROID_HOME, so it should
check the env vars for it, but maybe that doesn't actually work like that
yet.

examples/config.py
fdroidserver/common.py
fdroidserver/init.py

index 44d73e01ee95724e6364a634a296aafcd8bb642c..f1c6f7b94dc0b672041a83c890d8c98005b45259 100644 (file)
@@ -9,7 +9,7 @@
 # Override the path to the Android NDK, $ANDROID_NDK by default
 # ndk_path = "/path/to/android-ndk"
 # Build tools version to be used
-build_tools = "21.1.2"
+build_tools = "21.1.2"
 
 # Command for running Ant
 # ant = "/path/to/ant"
index 81233c406c99fca9255a03e5a725c1e03282e281..9e5189ea06d52ecf3de1c8800e1c652a1673877a 100644 (file)
@@ -169,7 +169,7 @@ def find_sdk_tools_cmd(cmd):
     '''find a working path to a tool from the Android SDK'''
 
     tooldirs = []
-    if 'sdk_path' in config and os.path.exists(config['sdk_path']):
+    if config is not None and 'sdk_path' in config and os.path.exists(config['sdk_path']):
         # try to find a working path to this command, in all the recent possible paths
         if 'build_tools' in config:
             build_tools = os.path.join(config['sdk_path'], 'build-tools')
@@ -199,8 +199,11 @@ def find_sdk_tools_cmd(cmd):
 
 def test_sdk_exists(thisconfig):
     if 'sdk_path' not in thisconfig:
-        logging.error("'sdk_path' not set in config.py!")
-        return False
+        if 'aapt' in thisconfig and os.path.isfile(thisconfig['aapt']):
+            return True
+        else:
+            logging.error("'sdk_path' not set in config.py!")
+            return False
     if thisconfig['sdk_path'] == default_config['sdk_path']:
         logging.error('No Android SDK found!')
         logging.error('You can use ANDROID_HOME to set the path to your SDK, i.e.:')
index 98c9081754d8478bc56f1800e6dd4d751d0f4666..a0819129573e29c07a62a2832f67c41ca63bd17e 100644 (file)
@@ -124,6 +124,7 @@ def main():
         prefix = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
         examplesdir = prefix + '/examples'
 
+    aapt = None
     fdroiddir = os.getcwd()
     test_config = dict()
     common.fill_config_defaults(test_config)
@@ -133,21 +134,28 @@ def main():
     if options.android_home is not None:
         test_config['sdk_path'] = options.android_home
     elif not common.test_sdk_exists(test_config):
-        # if neither --android-home nor the default sdk_path exist, prompt the user
-        default_sdk_path = '/opt/android-sdk'
-        while not options.no_prompt:
-            try:
-                s = raw_input('Enter the path to the Android SDK ('
-                              + default_sdk_path + ') here:\n> ')
-            except KeyboardInterrupt:
-                print('')
-                sys.exit(1)
-            if re.match('^\s*$', s) is not None:
-                test_config['sdk_path'] = default_sdk_path
-            else:
-                test_config['sdk_path'] = s
-            if common.test_sdk_exists(test_config):
-                break
+        if os.path.isfile('/usr/bin/aapt'):
+            # remove sdk_path and build_tools, they are not required
+            test_config.pop('sdk_path', None)
+            test_config.pop('build_tools', None)
+            # make sure at least aapt is found, since this can't do anything without it
+            test_config['aapt'] = common.find_sdk_tools_cmd('aapt')
+        else:
+            # if neither --android-home nor the default sdk_path exist, prompt the user
+            default_sdk_path = '/opt/android-sdk'
+            while not options.no_prompt:
+                try:
+                    s = raw_input('Enter the path to the Android SDK ('
+                                  + default_sdk_path + ') here:\n> ')
+                except KeyboardInterrupt:
+                    print('')
+                    sys.exit(1)
+                if re.match('^\s*$', s) is not None:
+                    test_config['sdk_path'] = default_sdk_path
+                else:
+                    test_config['sdk_path'] = s
+                if common.test_sdk_exists(test_config):
+                    break
     if not common.test_sdk_exists(test_config):
         sys.exit(3)
 
@@ -162,16 +170,14 @@ def main():
         # "$ANDROID_HOME" may be used if the env var is set up correctly.
         # If android_home is not None, the path given from the command line
         # will be directly written in the config.
-        write_to_config(test_config, 'sdk_path', options.android_home)
+        if 'sdk_path' in test_config:
+            write_to_config(test_config, 'sdk_path', options.android_home)
     else:
         logging.warn('Looks like this is already an F-Droid repo, cowardly refusing to overwrite it...')
         logging.info('Try running `fdroid init` in an empty directory.')
         sys.exit()
 
-    if os.path.exists('/usr/bin/aapt'):
-        # make sure at least aapt is found, since this can't do anything without it
-        config['aapt'] = common.find_sdk_tools_cmd('aapt')
-    else:
+    if not 'aapt' in test_config or not os.path.isfile(test_config['aapt']):
         # try to find a working aapt, in all the recent possible paths
         build_tools = os.path.join(test_config['sdk_path'], 'build-tools')
         aaptdirs = []
@@ -278,7 +284,8 @@ def main():
     logging.info('Built repo based in "' + fdroiddir + '"')
     logging.info('with this config:')
     logging.info('  Android SDK:\t\t\t' + config['sdk_path'])
-    logging.info('  Android SDK Build Tools:\t' + os.path.dirname(aapt))
+    if aapt:
+        logging.info('  Android SDK Build Tools:\t' + os.path.dirname(aapt))
     logging.info('  Android NDK (optional):\t' + ndk_path)
     logging.info('  Keystore for signing key:\t' + keystore)
     if repo_keyalias is not None: