diff options
author | Doug Zongker <dougz@android.com> | 2009-06-23 17:40:35 -0700 |
---|---|---|
committer | Doug Zongker <dougz@android.com> | 2009-06-23 17:40:35 -0700 |
commit | e1c31bacae7be6da140066966e6d2bbadd9331e9 (patch) | |
tree | 9fe9e78e02a7276d972942eba70c073ae78722d0 /tools/releasetools/common.py | |
parent | 55766e47aaf4fe72a2b5cdd8aa60d14781c01e94 (diff) | |
download | build-e1c31bacae7be6da140066966e6d2bbadd9331e9.zip build-e1c31bacae7be6da140066966e6d2bbadd9331e9.tar.gz build-e1c31bacae7be6da140066966e6d2bbadd9331e9.tar.bz2 |
make building recovery and boot images optional
If the source target-files zip omits files needed to build the
recovery and/or boot images, leave them out instead of dying with an
error. This lets build like "generic-userdebug" work.
Diffstat (limited to 'tools/releasetools/common.py')
-rw-r--r-- | tools/releasetools/common.py | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index afb61a3..a07ff7c 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -63,18 +63,29 @@ def LoadBoardConfig(fn): def BuildAndAddBootableImage(sourcedir, targetname, output_zip): """Take a kernel, cmdline, and ramdisk directory from the input (in 'sourcedir'), and turn them into a boot image. Put the boot image - into the output zip file under the name 'targetname'.""" + into the output zip file under the name 'targetname'. Returns + targetname on success or None on failure (if sourcedir does not + appear to contain files for the requested image).""" print "creating %s..." % (targetname,) img = BuildBootableImage(sourcedir) + if img is None: + return None CheckSize(img, targetname) ZipWriteStr(output_zip, targetname, img) + return targetname def BuildBootableImage(sourcedir): """Take a kernel, cmdline, and ramdisk directory from the input (in - 'sourcedir'), and turn them into a boot image. Return the image data.""" + 'sourcedir'), and turn them into a boot image. Return the image + data, or None if sourcedir does not appear to contains files for + building the requested image.""" + + if (not os.access(os.path.join(sourcedir, "RAMDISK"), os.F_OK) or + not os.access(os.path.join(sourcedir, "kernel"), os.F_OK)): + return None ramdisk_img = tempfile.NamedTemporaryFile() img = tempfile.NamedTemporaryFile() @@ -89,15 +100,25 @@ def BuildBootableImage(sourcedir): assert p1.returncode == 0, "mkbootfs of %s ramdisk failed" % (targetname,) assert p2.returncode == 0, "minigzip of %s ramdisk failed" % (targetname,) - cmdline = open(os.path.join(sourcedir, "cmdline")).read().rstrip("\n") - p = Run(["mkbootimg", - "--kernel", os.path.join(sourcedir, "kernel"), - "--cmdline", cmdline, - "--ramdisk", ramdisk_img.name, - "--output", img.name], - stdout=subprocess.PIPE) + cmd = ["mkbootimg", "--kernel", os.path.join(sourcedir, "kernel")] + + fn = os.path.join(sourcedir, "cmdline") + if os.access(fn, os.F_OK): + cmd.append("--cmdline") + cmd.append(open(fn).read().rstrip("\n")) + + fn = os.path.join(sourcedir, "base") + if os.access(fn, os.F_OK): + cmd.append("--base") + cmd.append(open(fn).read().rstrip("\n")) + + cmd.extend(["--ramdisk", ramdisk_img.name, + "--output", img.name]) + + p = Run(cmd, stdout=subprocess.PIPE) p.communicate() - assert p.returncode == 0, "mkbootimg of %s image failed" % (targetname,) + assert p.returncode == 0, "mkbootimg of %s image failed" % ( + os.path.basename(sourcedir),) img.seek(os.SEEK_SET, 0) data = img.read() |