1 # -*- coding: utf-8 -*-
3 # common.py - part of the FDroid server tools
4 # Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
5 # Copyright (C) 2013-2014 Daniel Martà <mvdan@mvdan.cc>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
33 from distutils.version import LooseVersion
41 def get_default_config():
43 'sdk_path': os.getenv("ANDROID_HOME"),
44 'ndk_path': "$ANDROID_NDK",
45 'build_tools': "19.0.3",
50 'update_stats': False,
51 'stats_to_carbon': False,
53 'build_server_always': False,
54 'keystore': '$HOME/.local/share/fdroidserver/keystore.jks',
55 'smartcardoptions': [],
64 def read_config(opts, config_file='config.py'):
65 """Read the repository config
67 The config is read from config_file, which is in the current directory when
68 any of the repo management commands are used.
70 global config, options
72 if config is not None:
74 if not os.path.isfile(config_file):
75 logging.critical("Missing config file - is this a repo directory?")
82 logging.debug("Reading %s" % config_file)
83 execfile(config_file, config)
85 # smartcardoptions must be a list since its command line args for Popen
86 if 'smartcardoptions' in config:
87 config['smartcardoptions'] = config['smartcardoptions'].split(' ')
88 elif 'keystore' in config and config['keystore'] == 'NONE':
89 # keystore='NONE' means use smartcard, these are required defaults
90 config['smartcardoptions'] = ['-storetype', 'PKCS11', '-providerName',
91 'SunPKCS11-OpenSC', '-providerClass',
92 'sun.security.pkcs11.SunPKCS11',
93 '-providerArg', 'opensc-fdroid.cfg']
95 defconfig = get_default_config()
96 for k, v in defconfig.items():
100 # Expand environment variables
101 for k, v in config.items():
104 v = os.path.expanduser(v)
105 config[k] = os.path.expandvars(v)
107 if not test_sdk_exists(config):
110 if any(k in config for k in ["keystore", "keystorepass", "keypass"]):
111 st = os.stat(config_file)
112 if st.st_mode & stat.S_IRWXG or st.st_mode & stat.S_IRWXO:
113 logging.warn("unsafe permissions on {0} (should be 0600)!".format(config_file))
115 for k in ["keystorepass", "keypass"]:
117 write_password_file(k)
119 # since this is used with rsync, where trailing slashes have meaning,
120 # ensure there is always a trailing slash
121 if 'serverwebroot' in config:
122 if config['serverwebroot'][-1] != '/':
123 config['serverwebroot'] += '/'
124 config['serverwebroot'] = config['serverwebroot'].replace('//', '/')
129 def test_sdk_exists(c):
130 if c['sdk_path'] is None:
131 # c['sdk_path'] is set to the value of ANDROID_HOME by default
132 logging.critical('No Android SDK found! ANDROID_HOME is not set and sdk_path is not in config.py!')
133 logging.info('You can use ANDROID_HOME to set the path to your SDK, i.e.:')
134 logging.info('\texport ANDROID_HOME=/opt/android-sdk')
136 if not os.path.exists(c['sdk_path']):
137 logging.critical('Android SDK path "' + c['sdk_path'] + '" does not exist!')
139 if not os.path.isdir(c['sdk_path']):
140 logging.critical('Android SDK path "' + c['sdk_path'] + '" is not a directory!')
142 if not os.path.isdir(os.path.join(c['sdk_path'], 'build-tools')):
143 logging.critical('Android SDK path "' + c['sdk_path'] + '" does not contain "build-tools/"!')
148 def test_build_tools_exists(c):
149 if not test_sdk_exists(c):
151 build_tools = os.path.join(c['sdk_path'], 'build-tools')
152 versioned_build_tools = os.path.join(build_tools, c['build_tools'])
153 if not os.path.isdir(versioned_build_tools):
154 logging.critical('Android Build Tools path "'
155 + versioned_build_tools + '" does not exist!')
157 if not os.path.exists(os.path.join(c['sdk_path'], 'build-tools', c['build_tools'], 'aapt')):
158 logging.critical('Android Build Tools "'
159 + versioned_build_tools
160 + '" does not contain "aapt"!')
165 def write_password_file(pwtype, password=None):
167 writes out passwords to a protected file instead of passing passwords as
168 command line argments
170 filename = '.fdroid.' + pwtype + '.txt'
171 fd = os.open(filename, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0600)
173 os.write(fd, config[pwtype])
175 os.write(fd, password)
177 config[pwtype + 'file'] = filename
180 # Given the arguments in the form of multiple appid:[vc] strings, this returns
181 # a dictionary with the set of vercodes specified for each package.
182 def read_pkg_args(args, allow_vercodes=False):
189 if allow_vercodes and ':' in p:
190 package, vercode = p.split(':')
192 package, vercode = p, None
193 if package not in vercodes:
194 vercodes[package] = [vercode] if vercode else []
196 elif vercode and vercode not in vercodes[package]:
197 vercodes[package] += [vercode] if vercode else []
202 # On top of what read_pkg_args does, this returns the whole app metadata, but
203 # limiting the builds list to the builds matching the vercodes specified.
204 def read_app_args(args, allapps, allow_vercodes=False):
206 vercodes = read_pkg_args(args, allow_vercodes)
211 apps = [app for app in allapps if app['id'] in vercodes]
213 if len(apps) != len(vercodes):
214 allids = [app["id"] for app in allapps]
217 logging.critical("No such package: %s" % p)
218 raise Exception("Found invalid app ids in arguments")
220 raise Exception("No packages specified")
224 vc = vercodes[app['id']]
227 app['builds'] = [b for b in app['builds'] if b['vercode'] in vc]
228 if len(app['builds']) != len(vercodes[app['id']]):
230 allvcs = [b['vercode'] for b in app['builds']]
231 for v in vercodes[app['id']]:
233 logging.critical("No such vercode %s for app %s" % (v, app['id']))
236 raise Exception("Found invalid vercodes for some apps")
241 def has_extension(filename, extension):
242 name, ext = os.path.splitext(filename)
243 ext = ext.lower()[1:]
244 return ext == extension
249 def apknameinfo(filename):
251 filename = os.path.basename(filename)
252 if apk_regex is None:
253 apk_regex = re.compile(r"^(.+)_([0-9]+)\.apk$")
254 m = apk_regex.match(filename)
256 result = (m.group(1), m.group(2))
257 except AttributeError:
258 raise Exception("Invalid apk name: %s" % filename)
262 def getapkname(app, build):
263 return "%s_%s.apk" % (app['id'], build['vercode'])
266 def getsrcname(app, build):
267 return "%s_%s_src.tar.gz" % (app['id'], build['vercode'])
274 return app['Auto Name']
279 return '%s (%s)' % (app['Current Version'], app['Current Version Code'])
282 def getvcs(vcstype, remote, local):
284 return vcs_git(remote, local)
286 return vcs_svn(remote, local)
287 if vcstype == 'git-svn':
288 return vcs_gitsvn(remote, local)
290 return vcs_hg(remote, local)
292 return vcs_bzr(remote, local)
293 if vcstype == 'srclib':
294 if local != 'build/srclib/' + remote:
295 raise VCSException("Error: srclib paths are hard-coded!")
296 return getsrclib(remote, 'build/srclib', raw=True)
297 raise VCSException("Invalid vcs type " + vcstype)
300 def getsrclibvcs(name):
301 if name not in metadata.srclibs:
302 raise VCSException("Missing srclib " + name)
303 return metadata.srclibs[name]['Repo Type']
307 def __init__(self, remote, local):
309 # svn, git-svn and bzr may require auth
311 if self.repotype() in ('svn', 'git-svn', 'bzr'):
313 self.username, remote = remote.split('@')
314 if ':' not in self.username:
315 raise VCSException("Password required with username")
316 self.username, self.password = self.username.split(':')
320 self.refreshed = False
326 # Take the local repository to a clean version of the given revision, which
327 # is specificed in the VCS's native format. Beforehand, the repository can
328 # be dirty, or even non-existent. If the repository does already exist
329 # locally, it will be updated from the origin, but only once in the
330 # lifetime of the vcs object.
331 # None is acceptable for 'rev' if you know you are cloning a clean copy of
332 # the repo - otherwise it must specify a valid revision.
333 def gotorevision(self, rev):
335 # The .fdroidvcs-id file for a repo tells us what VCS type
336 # and remote that directory was created from, allowing us to drop it
337 # automatically if either of those things changes.
338 fdpath = os.path.join(self.local, '..',
339 '.fdroidvcs-' + os.path.basename(self.local))
340 cdata = self.repotype() + ' ' + self.remote
343 if os.path.exists(self.local):
344 if os.path.exists(fdpath):
345 with open(fdpath, 'r') as f:
346 fsdata = f.read().strip()
351 logging.info("Repository details changed - deleting")
354 logging.info("Repository details missing - deleting")
356 shutil.rmtree(self.local)
358 self.gotorevisionx(rev)
360 # If necessary, write the .fdroidvcs file.
362 with open(fdpath, 'w') as f:
365 # Derived classes need to implement this. It's called once basic checking
366 # has been performend.
367 def gotorevisionx(self, rev):
368 raise VCSException("This VCS type doesn't define gotorevisionx")
370 # Initialise and update submodules
371 def initsubmodules(self):
372 raise VCSException('Submodules not supported for this vcs type')
374 # Get a list of all known tags
376 raise VCSException('gettags not supported for this vcs type')
378 # Get a list of latest number tags
379 def latesttags(self, number):
380 raise VCSException('latesttags not supported for this vcs type')
382 # Get current commit reference (hash, revision, etc)
384 raise VCSException('getref not supported for this vcs type')
386 # Returns the srclib (name, path) used in setting up the current
397 # If the local directory exists, but is somehow not a git repository, git
398 # will traverse up the directory tree until it finds one that is (i.e.
399 # fdroidserver) and then we'll proceed to destroy it! This is called as
402 p = SilentPopen(['git', 'rev-parse', '--show-toplevel'], cwd=self.local)
403 result = p.stdout.rstrip()
404 if not result.endswith(self.local):
405 raise VCSException('Repository mismatch')
407 def gotorevisionx(self, rev):
408 if not os.path.exists(self.local):
410 p = FDroidPopen(['git', 'clone', self.remote, self.local])
411 if p.returncode != 0:
412 raise VCSException("Git clone failed")
416 # Discard any working tree changes
417 p = SilentPopen(['git', 'reset', '--hard'], cwd=self.local)
418 if p.returncode != 0:
419 raise VCSException("Git reset failed")
420 # Remove untracked files now, in case they're tracked in the target
421 # revision (it happens!)
422 p = SilentPopen(['git', 'clean', '-dffx'], cwd=self.local)
423 if p.returncode != 0:
424 raise VCSException("Git clean failed")
425 if not self.refreshed:
426 # Get latest commits and tags from remote
427 p = FDroidPopen(['git', 'fetch', 'origin'], cwd=self.local)
428 if p.returncode != 0:
429 raise VCSException("Git fetch failed")
430 p = SilentPopen(['git', 'fetch', '--prune', '--tags', 'origin'], cwd=self.local)
431 if p.returncode != 0:
432 raise VCSException("Git fetch failed")
433 self.refreshed = True
434 # Check out the appropriate revision
435 rev = str(rev if rev else 'origin/master')
436 p = SilentPopen(['git', 'checkout', '-f', rev], cwd=self.local)
437 if p.returncode != 0:
438 raise VCSException("Git checkout failed")
439 # Get rid of any uncontrolled files left behind
440 p = SilentPopen(['git', 'clean', '-dffx'], cwd=self.local)
441 if p.returncode != 0:
442 raise VCSException("Git clean failed")
444 def initsubmodules(self):
446 submfile = os.path.join(self.local, '.gitmodules')
447 if not os.path.isfile(submfile):
448 raise VCSException("No git submodules available")
450 # fix submodules not accessible without an account and public key auth
451 with open(submfile, 'r') as f:
452 lines = f.readlines()
453 with open(submfile, 'w') as f:
455 if 'git@github.com' in line:
456 line = line.replace('git@github.com:', 'https://github.com/')
460 ['git', 'reset', '--hard'],
461 ['git', 'clean', '-dffx'],
463 p = SilentPopen(['git', 'submodule', 'foreach', '--recursive'] + cmd, cwd=self.local)
464 if p.returncode != 0:
465 raise VCSException("Git submodule reset failed")
466 p = FDroidPopen(['git', 'submodule', 'sync'], cwd=self.local)
467 if p.returncode != 0:
468 raise VCSException("Git submodule sync failed")
469 p = FDroidPopen(['git', 'submodule', 'update', '--init', '--force', '--recursive'], cwd=self.local)
470 if p.returncode != 0:
471 raise VCSException("Git submodule update failed")
475 p = SilentPopen(['git', 'tag'], cwd=self.local)
476 return p.stdout.splitlines()
478 def latesttags(self, alltags, number):
480 p = SilentPopen(['echo "' + '\n'.join(alltags) + '" | \
481 xargs -I@ git log --format=format:"%at @%n" -1 @ | \
482 sort -n | awk \'{print $2}\''],
483 cwd=self.local, shell=True)
484 return p.stdout.splitlines()[-number:]
487 class vcs_gitsvn(vcs):
492 # Damn git-svn tries to use a graphical password prompt, so we have to
493 # trick it into taking the password from stdin
495 if self.username is None:
497 return ('echo "%s" | DISPLAY="" ' % self.password, ' --username "%s"' % self.username)
499 # If the local directory exists, but is somehow not a git repository, git
500 # will traverse up the directory tree until it finds one that is (i.e.
501 # fdroidserver) and then we'll proceed to destory it! This is called as
504 p = SilentPopen(['git', 'rev-parse', '--show-toplevel'], cwd=self.local)
505 result = p.stdout.rstrip()
506 if not result.endswith(self.local):
507 raise VCSException('Repository mismatch')
509 def gotorevisionx(self, rev):
510 if not os.path.exists(self.local):
512 gitsvn_cmd = '%sgit svn clone%s' % self.userargs()
513 if ';' in self.remote:
514 remote_split = self.remote.split(';')
515 for i in remote_split[1:]:
516 if i.startswith('trunk='):
517 gitsvn_cmd += ' -T %s' % i[6:]
518 elif i.startswith('tags='):
519 gitsvn_cmd += ' -t %s' % i[5:]
520 elif i.startswith('branches='):
521 gitsvn_cmd += ' -b %s' % i[9:]
522 p = SilentPopen([gitsvn_cmd + " %s %s" % (remote_split[0], self.local)], shell=True)
523 if p.returncode != 0:
524 raise VCSException("Git clone failed")
526 p = SilentPopen([gitsvn_cmd + " %s %s" % (self.remote, self.local)], shell=True)
527 if p.returncode != 0:
528 raise VCSException("Git clone failed")
532 # Discard any working tree changes
533 p = SilentPopen(['git', 'reset', '--hard'], cwd=self.local)
534 if p.returncode != 0:
535 raise VCSException("Git reset failed")
536 # Remove untracked files now, in case they're tracked in the target
537 # revision (it happens!)
538 p = SilentPopen(['git', 'clean', '-dffx'], cwd=self.local)
539 if p.returncode != 0:
540 raise VCSException("Git clean failed")
541 if not self.refreshed:
542 # Get new commits, branches and tags from repo
543 p = SilentPopen(['%sgit svn fetch %s' % self.userargs()], cwd=self.local, shell=True)
544 if p.returncode != 0:
545 raise VCSException("Git svn fetch failed")
546 p = SilentPopen(['%sgit svn rebase %s' % self.userargs()], cwd=self.local, shell=True)
547 if p.returncode != 0:
548 raise VCSException("Git svn rebase failed")
549 self.refreshed = True
551 rev = str(rev if rev else 'master')
553 nospaces_rev = rev.replace(' ', '%20')
554 # Try finding a svn tag
555 p = SilentPopen(['git', 'checkout', 'tags/' + nospaces_rev], cwd=self.local)
556 if p.returncode != 0:
557 # No tag found, normal svn rev translation
558 # Translate svn rev into git format
559 rev_split = rev.split('/')
560 if len(rev_split) > 1:
561 treeish = rev_split[0]
562 svn_rev = rev_split[1]
565 # if no branch is specified, then assume trunk (ie. 'master'
570 p = SilentPopen(['git', 'svn', 'find-rev', 'r' + svn_rev, treeish], cwd=self.local)
571 git_rev = p.stdout.rstrip()
573 if p.returncode != 0 or not git_rev:
574 # Try a plain git checkout as a last resort
575 p = SilentPopen(['git', 'checkout', rev], cwd=self.local)
576 if p.returncode != 0:
577 raise VCSException("No git treeish found and direct git checkout failed")
579 # Check out the git rev equivalent to the svn rev
580 p = SilentPopen(['git', 'checkout', git_rev], cwd=self.local)
581 if p.returncode != 0:
582 raise VCSException("Git svn checkout failed")
584 # Get rid of any uncontrolled files left behind
585 p = SilentPopen(['git', 'clean', '-dffx'], cwd=self.local)
586 if p.returncode != 0:
587 raise VCSException("Git clean failed")
591 return os.listdir(os.path.join(self.local, '.git/svn/refs/remotes/tags'))
595 p = SilentPopen(['git', 'svn', 'find-rev', 'HEAD'], cwd=self.local)
596 if p.returncode != 0:
598 return p.stdout.strip()
607 if self.username is None:
608 return ['--non-interactive']
609 return ['--username', self.username,
610 '--password', self.password,
613 def gotorevisionx(self, rev):
614 if not os.path.exists(self.local):
615 p = SilentPopen(['svn', 'checkout', self.remote, self.local] + self.userargs())
616 if p.returncode != 0:
617 raise VCSException("Svn checkout failed")
621 r"svn status | awk '/\?/ {print $2}' | xargs rm -rf"):
622 p = SilentPopen([svncommand], cwd=self.local, shell=True)
623 if p.returncode != 0:
624 raise VCSException("Svn reset ({0}) failed in {1}".format(svncommand, self.local))
625 if not self.refreshed:
626 p = SilentPopen(['svn', 'update'] + self.userargs(), cwd=self.local)
627 if p.returncode != 0:
628 raise VCSException("Svn update failed")
629 self.refreshed = True
631 revargs = list(['-r', rev] if rev else [])
632 p = SilentPopen(['svn', 'update', '--force'] + revargs + self.userargs(), cwd=self.local)
633 if p.returncode != 0:
634 raise VCSException("Svn update failed")
637 p = SilentPopen(['svn', 'info'], cwd=self.local)
638 for line in p.stdout.splitlines():
639 if line and line.startswith('Last Changed Rev: '):
649 def gotorevisionx(self, rev):
650 if not os.path.exists(self.local):
651 p = SilentPopen(['hg', 'clone', self.remote, self.local])
652 if p.returncode != 0:
653 raise VCSException("Hg clone failed")
655 p = SilentPopen(['hg status -uS | xargs rm -rf'], cwd=self.local, shell=True)
656 if p.returncode != 0:
657 raise VCSException("Hg clean failed")
658 if not self.refreshed:
659 p = SilentPopen(['hg', 'pull'], cwd=self.local)
660 if p.returncode != 0:
661 raise VCSException("Hg pull failed")
662 self.refreshed = True
664 rev = str(rev if rev else 'default')
667 p = SilentPopen(['hg', 'update', '-C', rev], cwd=self.local)
668 if p.returncode != 0:
669 raise VCSException("Hg checkout failed")
670 p = SilentPopen(['hg', 'purge', '--all'], cwd=self.local)
671 # Also delete untracked files, we have to enable purge extension for that:
672 if "'purge' is provided by the following extension" in p.stdout:
673 with open(self.local + "/.hg/hgrc", "a") as myfile:
674 myfile.write("\n[extensions]\nhgext.purge=\n")
675 p = SilentPopen(['hg', 'purge', '--all'], cwd=self.local)
676 if p.returncode != 0:
677 raise VCSException("HG purge failed")
678 elif p.returncode != 0:
679 raise VCSException("HG purge failed")
682 p = SilentPopen(['hg', 'tags', '-q'], cwd=self.local)
683 return p.stdout.splitlines()[1:]
691 def gotorevisionx(self, rev):
692 if not os.path.exists(self.local):
693 p = SilentPopen(['bzr', 'branch', self.remote, self.local])
694 if p.returncode != 0:
695 raise VCSException("Bzr branch failed")
697 p = SilentPopen(['bzr', 'clean-tree', '--force', '--unknown', '--ignored'], cwd=self.local)
698 if p.returncode != 0:
699 raise VCSException("Bzr revert failed")
700 if not self.refreshed:
701 p = SilentPopen(['bzr', 'pull'], cwd=self.local)
702 if p.returncode != 0:
703 raise VCSException("Bzr update failed")
704 self.refreshed = True
706 revargs = list(['-r', rev] if rev else [])
707 p = SilentPopen(['bzr', 'revert'] + revargs, cwd=self.local)
708 if p.returncode != 0:
709 raise VCSException("Bzr revert failed")
712 p = SilentPopen(['bzr', 'tags'], cwd=self.local)
713 return [tag.split(' ')[0].strip() for tag in
714 p.stdout.splitlines()]
717 def retrieve_string(app_dir, string, xmlfiles=None):
720 os.path.join(app_dir, 'res'),
721 os.path.join(app_dir, 'src/main'),
726 for res_dir in res_dirs:
727 for r, d, f in os.walk(res_dir):
728 if r.endswith('/values'):
729 xmlfiles += [os.path.join(r, x) for x in f if x.endswith('.xml')]
732 if string.startswith('@string/'):
733 string_search = re.compile(r'.*name="' + string[8:] + '".*?>([^<]+?)<.*').search
734 elif string.startswith('&') and string.endswith(';'):
735 string_search = re.compile(r'.*<!ENTITY.*' + string[1:-1] + '.*?"([^"]+?)".*>').search
737 if string_search is not None:
738 for xmlfile in xmlfiles:
739 for line in file(xmlfile):
740 matches = string_search(line)
742 return retrieve_string(app_dir, matches.group(1), xmlfiles)
745 return string.replace("\\'", "'")
748 # Return list of existing files that will be used to find the highest vercode
749 def manifest_paths(app_dir, flavour):
751 possible_manifests = \
752 [os.path.join(app_dir, 'AndroidManifest.xml'),
753 os.path.join(app_dir, 'src', 'main', 'AndroidManifest.xml'),
754 os.path.join(app_dir, 'src', 'AndroidManifest.xml'),
755 os.path.join(app_dir, 'build.gradle')]
758 possible_manifests.append(
759 os.path.join(app_dir, 'src', flavour, 'AndroidManifest.xml'))
761 return [path for path in possible_manifests if os.path.isfile(path)]
764 # Retrieve the package name. Returns the name, or None if not found.
765 def fetch_real_name(app_dir, flavour):
766 app_search = re.compile(r'.*<application.*').search
767 name_search = re.compile(r'.*android:label="([^"]+)".*').search
769 for f in manifest_paths(app_dir, flavour):
770 if not has_extension(f, 'xml'):
772 logging.debug("fetch_real_name: Checking manifest at " + f)
778 matches = name_search(line)
780 stringname = matches.group(1)
781 logging.debug("fetch_real_name: using string " + stringname)
782 result = retrieve_string(app_dir, stringname)
784 result = result.strip()
789 # Retrieve the version name
790 def version_name(original, app_dir, flavour):
791 for f in manifest_paths(app_dir, flavour):
792 if not has_extension(f, 'xml'):
794 string = retrieve_string(app_dir, original)
800 def get_library_references(root_dir):
802 proppath = os.path.join(root_dir, 'project.properties')
803 if not os.path.isfile(proppath):
805 with open(proppath) as f:
806 for line in f.readlines():
807 if not line.startswith('android.library.reference.'):
809 path = line.split('=')[1].strip()
810 relpath = os.path.join(root_dir, path)
811 if not os.path.isdir(relpath):
813 logging.info("Found subproject at %s" % path)
814 libraries.append(path)
818 def ant_subprojects(root_dir):
819 subprojects = get_library_references(root_dir)
820 for subpath in subprojects:
821 subrelpath = os.path.join(root_dir, subpath)
822 for p in get_library_references(subrelpath):
823 relp = os.path.normpath(os.path.join(subpath, p))
824 if relp not in subprojects:
825 subprojects.insert(0, relp)
829 def remove_debuggable_flags(root_dir):
830 # Remove forced debuggable flags
831 logging.info("Removing debuggable flags")
832 for root, dirs, files in os.walk(root_dir):
833 if 'AndroidManifest.xml' in files:
834 path = os.path.join(root, 'AndroidManifest.xml')
835 p = FDroidPopen(['sed', '-i', 's/android:debuggable="[^"]*"//g', path])
836 if p.returncode != 0:
837 raise BuildException("Failed to remove debuggable flags of %s" % path)
840 # Extract some information from the AndroidManifest.xml at the given path.
841 # Returns (version, vercode, package), any or all of which might be None.
842 # All values returned are strings.
843 def parse_androidmanifests(paths, ignoreversions=None):
846 return (None, None, None)
848 vcsearch = re.compile(r'.*:versionCode="([0-9]+?)".*').search
849 vnsearch = re.compile(r'.*:versionName="([^"]+?)".*').search
850 psearch = re.compile(r'.*package="([^"]+)".*').search
852 vcsearch_g = re.compile(r'.*versionCode *=* *["\']*([0-9]+)["\']*').search
853 vnsearch_g = re.compile(r'.*versionName *=* *(["\'])((?:(?=(\\?))\3.)*?)\1.*').search
854 psearch_g = re.compile(r'.*packageName *=* *["\']([^"]+)["\'].*').search
856 ignoresearch = re.compile(ignoreversions).search if ignoreversions else None
866 gradle = has_extension(path, 'gradle')
867 # Remember package name, may be defined separately from version+vercode
868 package = max_package
870 for line in file(path):
873 matches = psearch_g(line)
875 matches = psearch(line)
877 package = matches.group(1)
880 matches = vnsearch_g(line)
882 matches = vnsearch(line)
884 version = matches.group(2 if gradle else 1)
887 matches = vcsearch_g(line)
889 matches = vcsearch(line)
891 vercode = matches.group(1)
893 # Better some package name than nothing
894 if max_package is None:
895 max_package = package
897 if max_vercode is None or (vercode is not None and vercode > max_vercode):
898 if not ignoresearch or not ignoresearch(version):
899 max_version = version
900 max_vercode = vercode
901 max_package = package
903 max_version = "Ignore"
905 if max_version is None:
906 max_version = version if version else "Unknown"
908 return (max_version, max_vercode, max_package)
911 class BuildException(Exception):
912 def __init__(self, value, detail=None):
916 def get_wikitext(self):
917 ret = repr(self.value) + "\n"
921 txt = self.detail[-8192:] if len(self.detail) > 8192 else self.detail
929 ret += "\n==== detail begin ====\n%s\n==== detail end ====" % self.detail.strip()
933 class VCSException(Exception):
934 def __init__(self, value):
941 # Get the specified source library.
942 # Returns the path to it. Normally this is the path to be used when referencing
943 # it, which may be a subdirectory of the actual project. If you want the base
944 # directory of the project, pass 'basepath=True'.
945 def getsrclib(spec, srclib_dir, srclibpaths=[], subdir=None,
946 basepath=False, raw=False, prepare=True, preponly=False):
954 name, ref = spec.split('@')
956 number, name = name.split(':', 1)
958 name, subdir = name.split('/', 1)
960 if name not in metadata.srclibs:
961 raise BuildException('srclib ' + name + ' not found.')
963 srclib = metadata.srclibs[name]
965 sdir = os.path.join(srclib_dir, name)
968 vcs = getvcs(srclib["Repo Type"], srclib["Repo"], sdir)
969 vcs.srclib = (name, number, sdir)
971 vcs.gotorevision(ref)
978 libdir = os.path.join(sdir, subdir)
979 elif srclib["Subdir"]:
980 for subdir in srclib["Subdir"]:
981 libdir_candidate = os.path.join(sdir, subdir)
982 if os.path.exists(libdir_candidate):
983 libdir = libdir_candidate
989 if srclib["Srclibs"]:
991 for lib in srclib["Srclibs"].replace(';', ',').split(','):
993 for t in srclibpaths:
998 raise BuildException('Missing recursive srclib %s for %s' % (
1000 place_srclib(libdir, n, s_tuple[2])
1003 remove_signing_keys(sdir)
1004 remove_debuggable_flags(sdir)
1008 if srclib["Prepare"]:
1009 cmd = replace_config_vars(srclib["Prepare"])
1011 p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=libdir)
1012 if p.returncode != 0:
1013 raise BuildException("Error running prepare command for srclib %s"
1019 return (name, number, libdir)
1022 # Prepare the source code for a particular build
1023 # 'vcs' - the appropriate vcs object for the application
1024 # 'app' - the application details from the metadata
1025 # 'build' - the build details from the metadata
1026 # 'build_dir' - the path to the build directory, usually
1028 # 'srclib_dir' - the path to the source libraries directory, usually
1030 # 'extlib_dir' - the path to the external libraries directory, usually
1032 # Returns the (root, srclibpaths) where:
1033 # 'root' is the root directory, which may be the same as 'build_dir' or may
1034 # be a subdirectory of it.
1035 # 'srclibpaths' is information on the srclibs being used
1036 def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=False):
1038 # Optionally, the actual app source can be in a subdirectory
1040 root_dir = os.path.join(build_dir, build['subdir'])
1042 root_dir = build_dir
1044 # Get a working copy of the right revision
1045 logging.info("Getting source for revision " + build['commit'])
1046 vcs.gotorevision(build['commit'])
1048 # Initialise submodules if requred
1049 if build['submodules']:
1050 logging.info("Initialising submodules")
1051 vcs.initsubmodules()
1053 # Check that a subdir (if we're using one) exists. This has to happen
1054 # after the checkout, since it might not exist elsewhere
1055 if not os.path.exists(root_dir):
1056 raise BuildException('Missing subdir ' + root_dir)
1058 # Run an init command if one is required
1060 cmd = replace_config_vars(build['init'])
1061 logging.info("Running 'init' commands in %s" % root_dir)
1063 p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir)
1064 if p.returncode != 0:
1065 raise BuildException("Error running init command for %s:%s" %
1066 (app['id'], build['version']), p.stdout)
1068 # Apply patches if any
1070 logging.info("Applying patches")
1071 for patch in build['patch']:
1072 patch = patch.strip()
1073 logging.info("Applying " + patch)
1074 patch_path = os.path.join('metadata', app['id'], patch)
1075 p = FDroidPopen(['patch', '-p1', '-i', os.path.abspath(patch_path)], cwd=build_dir)
1076 if p.returncode != 0:
1077 raise BuildException("Failed to apply patch %s" % patch_path)
1079 # Get required source libraries
1081 if build['srclibs']:
1082 logging.info("Collecting source libraries")
1083 for lib in build['srclibs']:
1084 srclibpaths.append(getsrclib(lib, srclib_dir, srclibpaths,
1087 for name, number, libpath in srclibpaths:
1088 place_srclib(root_dir, int(number) if number else None, libpath)
1090 basesrclib = vcs.getsrclib()
1091 # If one was used for the main source, add that too.
1093 srclibpaths.append(basesrclib)
1095 # Update the local.properties file
1096 localprops = [os.path.join(build_dir, 'local.properties')]
1098 localprops += [os.path.join(root_dir, 'local.properties')]
1099 for path in localprops:
1100 if not os.path.isfile(path):
1102 logging.info("Updating properties file at %s" % path)
1107 # Fix old-fashioned 'sdk-location' by copying
1108 # from sdk.dir, if necessary
1109 if build['oldsdkloc']:
1110 sdkloc = re.match(r".*^sdk.dir=(\S+)$.*", props,
1111 re.S | re.M).group(1)
1112 props += "sdk-location=%s\n" % sdkloc
1114 props += "sdk.dir=%s\n" % config['sdk_path']
1115 props += "sdk-location=%s\n" % config['sdk_path']
1116 if 'ndk_path' in config:
1118 props += "ndk.dir=%s\n" % config['ndk_path']
1119 props += "ndk-location=%s\n" % config['ndk_path']
1120 # Add java.encoding if necessary
1121 if build['encoding']:
1122 props += "java.encoding=%s\n" % build['encoding']
1128 if build['type'] == 'gradle':
1129 flavour = build['gradle'].split('@')[0]
1130 if flavour in ['main', 'yes', '']:
1133 version_regex = re.compile(r".*'com\.android\.tools\.build:gradle:([^\.]+\.[^\.]+).*'.*")
1134 gradlepluginver = None
1136 with open(os.path.join(root_dir, 'build.gradle')) as f:
1138 match = version_regex.match(line)
1140 gradlepluginver = match.group(1)
1142 if '@' in build['gradle'] and not gradlepluginver:
1143 gradle_dir = os.path.join(root_dir, build['gradle'].split('@', 1)[1])
1144 gradle_dir = os.path.normpath(gradle_dir)
1145 with open(os.path.join(root_dir, 'build.gradle')) as f:
1147 match = version_regex.match(line)
1149 gradlepluginver = match.group(1)
1152 build['gradlepluginver'] = LooseVersion(gradlepluginver)
1155 n = build["target"].split('-')[1]
1156 FDroidPopen(['sed', '-i',
1157 's@compileSdkVersion *[0-9]*@compileSdkVersion ' + n + '@g',
1160 if '@' in build['gradle']:
1161 gradle_dir = os.path.join(root_dir, build['gradle'].split('@', 1)[1])
1162 gradle_dir = os.path.normpath(gradle_dir)
1163 FDroidPopen(['sed', '-i',
1164 's@compileSdkVersion *[0-9]*@compileSdkVersion ' + n + '@g',
1168 # Remove forced debuggable flags
1169 remove_debuggable_flags(root_dir)
1171 # Insert version code and number into the manifest if necessary
1172 if build['forceversion']:
1173 logging.info("Changing the version name")
1174 for path in manifest_paths(root_dir, flavour):
1175 if not os.path.isfile(path):
1177 if has_extension(path, 'xml'):
1178 p = SilentPopen(['sed', '-i',
1179 's/android:versionName="[^"]*"/android:versionName="'
1180 + build['version'] + '"/g',
1182 if p.returncode != 0:
1183 raise BuildException("Failed to amend manifest")
1184 elif has_extension(path, 'gradle'):
1185 p = SilentPopen(['sed', '-i',
1186 's/versionName *=* *"[^"]*"/versionName = "'
1187 + build['version'] + '"/g',
1189 if p.returncode != 0:
1190 raise BuildException("Failed to amend build.gradle")
1191 if build['forcevercode']:
1192 logging.info("Changing the version code")
1193 for path in manifest_paths(root_dir, flavour):
1194 if not os.path.isfile(path):
1196 if has_extension(path, 'xml'):
1197 p = SilentPopen(['sed', '-i',
1198 's/android:versionCode="[^"]*"/android:versionCode="'
1199 + build['vercode'] + '"/g',
1201 if p.returncode != 0:
1202 raise BuildException("Failed to amend manifest")
1203 elif has_extension(path, 'gradle'):
1204 p = SilentPopen(['sed', '-i',
1205 's/versionCode *=* *[0-9]*/versionCode = '
1206 + build['vercode'] + '/g',
1208 if p.returncode != 0:
1209 raise BuildException("Failed to amend build.gradle")
1211 # Delete unwanted files
1213 logging.info("Removing specified files")
1214 for part in getpaths(build_dir, build, 'rm'):
1215 dest = os.path.join(build_dir, part)
1216 logging.info("Removing {0}".format(part))
1217 if os.path.lexists(dest):
1218 if os.path.islink(dest):
1219 SilentPopen(['unlink ' + dest], shell=True)
1221 SilentPopen(['rm -rf ' + dest], shell=True)
1223 logging.info("...but it didn't exist")
1225 remove_signing_keys(build_dir)
1227 # Add required external libraries
1228 if build['extlibs']:
1229 logging.info("Collecting prebuilt libraries")
1230 libsdir = os.path.join(root_dir, 'libs')
1231 if not os.path.exists(libsdir):
1233 for lib in build['extlibs']:
1235 logging.info("...installing extlib {0}".format(lib))
1236 libf = os.path.basename(lib)
1237 libsrc = os.path.join(extlib_dir, lib)
1238 if not os.path.exists(libsrc):
1239 raise BuildException("Missing extlib file {0}".format(libsrc))
1240 shutil.copyfile(libsrc, os.path.join(libsdir, libf))
1242 # Run a pre-build command if one is required
1243 if build['prebuild']:
1244 logging.info("Running 'prebuild' commands in %s" % root_dir)
1246 cmd = replace_config_vars(build['prebuild'])
1248 # Substitute source library paths into prebuild commands
1249 for name, number, libpath in srclibpaths:
1250 libpath = os.path.relpath(libpath, root_dir)
1251 cmd = cmd.replace('$$' + name + '$$', libpath)
1253 p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir)
1254 if p.returncode != 0:
1255 raise BuildException("Error running prebuild command for %s:%s" %
1256 (app['id'], build['version']), p.stdout)
1258 # Generate (or update) the ant build file, build.xml...
1259 if build['update'] and build['update'] != ['no'] and build['type'] == 'ant':
1260 parms = [os.path.join(config['sdk_path'], 'tools', 'android'), 'update']
1261 lparms = parms + ['lib-project']
1262 parms = parms + ['project']
1265 parms += ['-t', build['target']]
1266 lparms += ['-t', build['target']]
1267 if build['update'] == ['auto']:
1268 update_dirs = ant_subprojects(root_dir) + ['.']
1270 update_dirs = build['update']
1272 for d in update_dirs:
1273 subdir = os.path.join(root_dir, d)
1275 print("Updating main project")
1276 cmd = parms + ['-p', d]
1278 print("Updating subproject %s" % d)
1279 cmd = lparms + ['-p', d]
1280 p = FDroidPopen(cmd, cwd=root_dir)
1281 # Check to see whether an error was returned without a proper exit
1282 # code (this is the case for the 'no target set or target invalid'
1284 if p.returncode != 0 or p.stdout.startswith("Error: "):
1285 raise BuildException("Failed to update project at %s" % d, p.stdout)
1286 # Clean update dirs via ant
1288 logging.info("Cleaning subproject %s" % d)
1289 p = FDroidPopen(['ant', 'clean'], cwd=subdir)
1291 return (root_dir, srclibpaths)
1294 # Split and extend via globbing the paths from a field
1295 def getpaths(build_dir, build, field):
1297 for p in build[field]:
1299 full_path = os.path.join(build_dir, p)
1300 full_path = os.path.normpath(full_path)
1301 paths += [r[len(build_dir) + 1:] for r in glob.glob(full_path)]
1305 # Scan the source code in the given directory (and all subdirectories)
1306 # and return the number of fatal problems encountered
1307 def scan_source(build_dir, root_dir, thisbuild):
1311 # Common known non-free blobs (always lower case):
1313 re.compile(r'flurryagent', re.IGNORECASE),
1314 re.compile(r'paypal.*mpl', re.IGNORECASE),
1315 re.compile(r'libgoogleanalytics', re.IGNORECASE),
1316 re.compile(r'admob.*sdk.*android', re.IGNORECASE),
1317 re.compile(r'googleadview', re.IGNORECASE),
1318 re.compile(r'googleadmobadssdk', re.IGNORECASE),
1319 re.compile(r'google.*play.*services', re.IGNORECASE),
1320 re.compile(r'crittercism', re.IGNORECASE),
1321 re.compile(r'heyzap', re.IGNORECASE),
1322 re.compile(r'jpct.*ae', re.IGNORECASE),
1323 re.compile(r'youtubeandroidplayerapi', re.IGNORECASE),
1324 re.compile(r'bugsense', re.IGNORECASE),
1325 re.compile(r'crashlytics', re.IGNORECASE),
1326 re.compile(r'ouya.*sdk', re.IGNORECASE),
1327 re.compile(r'libspen23', re.IGNORECASE),
1330 scanignore = getpaths(build_dir, thisbuild, 'scanignore')
1331 scandelete = getpaths(build_dir, thisbuild, 'scandelete')
1334 ms = magic.open(magic.MIME_TYPE)
1336 except AttributeError:
1340 for i in scanignore:
1341 if fd.startswith(i):
1346 for i in scandelete:
1347 if fd.startswith(i):
1351 def removeproblem(what, fd, fp):
1352 logging.info('Removing %s at %s' % (what, fd))
1355 def warnproblem(what, fd):
1356 logging.warn('Found %s at %s' % (what, fd))
1358 def handleproblem(what, fd, fp):
1360 removeproblem(what, fd, fp)
1362 logging.error('Found %s at %s' % (what, fd))
1366 def insidedir(path, dirname):
1367 return path.endswith('/%s' % dirname) or '/%s/' % dirname in path
1369 # Iterate through all files in the source code
1370 for r, d, f in os.walk(build_dir):
1372 if any(insidedir(r, d) for d in ('.hg', '.git', '.svn', '.bzr')):
1377 # Path (relative) to the file
1378 fp = os.path.join(r, curfile)
1379 fd = fp[len(build_dir) + 1:]
1381 # Check if this file has been explicitly excluded from scanning
1385 mime = magic.from_file(fp, mime=True) if ms is None else ms.file(fp)
1387 if mime == 'application/x-sharedlib':
1388 count += handleproblem('shared library', fd, fp)
1390 elif mime == 'application/x-archive':
1391 count += handleproblem('static library', fd, fp)
1393 elif mime == 'application/x-executable':
1394 count += handleproblem('binary executable', fd, fp)
1396 elif mime == 'application/x-java-applet':
1397 count += handleproblem('Java compiled class', fd, fp)
1402 'application/java-archive',
1403 'application/octet-stream',
1407 if has_extension(fp, 'apk'):
1408 removeproblem('APK file', fd, fp)
1410 elif has_extension(fp, 'jar'):
1412 if any(suspect.match(curfile) for suspect in usual_suspects):
1413 count += handleproblem('usual supect', fd, fp)
1415 warnproblem('JAR file', fd)
1417 elif has_extension(fp, 'zip'):
1418 warnproblem('ZIP file', fd)
1421 warnproblem('unknown compressed or binary file', fd)
1423 elif has_extension(fp, 'java'):
1424 for line in file(fp):
1425 if 'DexClassLoader' in line:
1426 count += handleproblem('DexClassLoader', fd, fp)
1431 # Presence of a jni directory without buildjni=yes might
1432 # indicate a problem (if it's not a problem, explicitly use
1433 # buildjni=no to bypass this check)
1434 if (os.path.exists(os.path.join(root_dir, 'jni')) and
1435 not thisbuild['buildjni']):
1436 logging.error('Found jni directory, but buildjni is not enabled')
1445 self.path = os.path.join('stats', 'known_apks.txt')
1447 if os.path.exists(self.path):
1448 for line in file(self.path):
1449 t = line.rstrip().split(' ')
1451 self.apks[t[0]] = (t[1], None)
1453 self.apks[t[0]] = (t[1], time.strptime(t[2], '%Y-%m-%d'))
1454 self.changed = False
1456 def writeifchanged(self):
1458 if not os.path.exists('stats'):
1460 f = open(self.path, 'w')
1462 for apk, app in self.apks.iteritems():
1464 line = apk + ' ' + appid
1466 line += ' ' + time.strftime('%Y-%m-%d', added)
1468 for line in sorted(lst):
1469 f.write(line + '\n')
1472 # Record an apk (if it's new, otherwise does nothing)
1473 # Returns the date it was added.
1474 def recordapk(self, apk, app):
1475 if apk not in self.apks:
1476 self.apks[apk] = (app, time.gmtime(time.time()))
1478 _, added = self.apks[apk]
1481 # Look up information - given the 'apkname', returns (app id, date added/None).
1482 # Or returns None for an unknown apk.
1483 def getapp(self, apkname):
1484 if apkname in self.apks:
1485 return self.apks[apkname]
1488 # Get the most recent 'num' apps added to the repo, as a list of package ids
1489 # with the most recent first.
1490 def getlatest(self, num):
1492 for apk, app in self.apks.iteritems():
1496 if apps[appid] > added:
1500 sortedapps = sorted(apps.iteritems(), key=operator.itemgetter(1))[-num:]
1501 lst = [app for app, _ in sortedapps]
1506 def isApkDebuggable(apkfile, config):
1507 """Returns True if the given apk file is debuggable
1509 :param apkfile: full path to the apk to check"""
1511 p = SilentPopen([os.path.join(config['sdk_path'], 'build-tools',
1512 config['build_tools'], 'aapt'),
1513 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'])
1514 if p.returncode != 0:
1515 logging.critical("Failed to get apk manifest information")
1517 for line in p.stdout.splitlines():
1518 if 'android:debuggable' in line and not line.endswith('0x0'):
1523 class AsynchronousFileReader(threading.Thread):
1525 Helper class to implement asynchronous reading of a file
1526 in a separate thread. Pushes read lines on a queue to
1527 be consumed in another thread.
1530 def __init__(self, fd, queue):
1531 assert isinstance(queue, Queue.Queue)
1532 assert callable(fd.readline)
1533 threading.Thread.__init__(self)
1538 '''The body of the tread: read lines and put them on the queue.'''
1539 for line in iter(self._fd.readline, ''):
1540 self._queue.put(line)
1543 '''Check whether there is no more content to expect.'''
1544 return not self.is_alive() and self._queue.empty()
1552 def SilentPopen(commands, cwd=None, shell=False):
1553 return FDroidPopen(commands, cwd=cwd, shell=shell, output=False)
1556 def FDroidPopen(commands, cwd=None, shell=False, output=False):
1558 Run a command and capture the possibly huge output.
1560 :param commands: command and argument list like in subprocess.Popen
1561 :param cwd: optionally specifies a working directory
1562 :returns: A PopenResult.
1567 cwd = os.path.normpath(cwd)
1568 logging.info("Directory: %s" % cwd)
1569 logging.info("> %s" % ' '.join(commands))
1571 result = PopenResult()
1572 p = subprocess.Popen(commands, cwd=cwd, shell=shell,
1573 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
1575 stdout_queue = Queue.Queue()
1576 stdout_reader = AsynchronousFileReader(p.stdout, stdout_queue)
1577 stdout_reader.start()
1579 # Check the queue for output (until there is no more to get)
1580 while not stdout_reader.eof():
1581 while not stdout_queue.empty():
1582 line = stdout_queue.get()
1583 if output or options.verbose:
1584 # Output directly to console
1585 sys.stdout.write(line)
1587 result.stdout += line
1592 result.returncode = p.returncode
1596 def remove_signing_keys(build_dir):
1597 comment = re.compile(r'[ ]*//')
1598 signing_configs = re.compile(r'^[\t ]*signingConfigs[ \t]*{[ \t]*$')
1600 re.compile(r'^[\t ]*signingConfig [^ ]*$'),
1601 re.compile(r'.*android\.signingConfigs\.[^{]*$'),
1602 re.compile(r'.*variant\.outputFile = .*'),
1603 re.compile(r'.*\.readLine\(.*'),
1605 for root, dirs, files in os.walk(build_dir):
1606 if 'build.gradle' in files:
1607 path = os.path.join(root, 'build.gradle')
1609 with open(path, "r") as o:
1610 lines = o.readlines()
1613 with open(path, "w") as o:
1615 if comment.match(line):
1619 opened += line.count('{')
1620 opened -= line.count('}')
1623 if signing_configs.match(line):
1627 if any(s.match(line) for s in line_matches):
1633 logging.info("Cleaned build.gradle of keysigning configs at %s" % path)
1636 'project.properties',
1638 'default.properties',
1641 if propfile in files:
1642 path = os.path.join(root, propfile)
1644 with open(path, "r") as o:
1645 lines = o.readlines()
1647 with open(path, "w") as o:
1649 if line.startswith('key.store'):
1651 if line.startswith('key.alias'):
1655 logging.info("Cleaned %s of keysigning configs at %s" % (propfile, path))
1658 def replace_config_vars(cmd):
1659 cmd = cmd.replace('$$SDK$$', config['sdk_path'])
1660 cmd = cmd.replace('$$NDK$$', config['ndk_path'])
1661 cmd = cmd.replace('$$MVN3$$', config['mvn3'])
1665 def place_srclib(root_dir, number, libpath):
1668 relpath = os.path.relpath(libpath, root_dir)
1669 proppath = os.path.join(root_dir, 'project.properties')
1672 if os.path.isfile(proppath):
1673 with open(proppath, "r") as o:
1674 lines = o.readlines()
1676 with open(proppath, "w") as o:
1679 if line.startswith('android.library.reference.%d=' % number):
1680 o.write('android.library.reference.%d=%s\n' % (number, relpath))
1685 o.write('android.library.reference.%d=%s\n' % (number, relpath))