Skip to content

Commit

Permalink
Fix build the fuck up!
Browse files Browse the repository at this point in the history
Change-Id: Ib433b258f95b00a423affb7e892d387b7254b371
  • Loading branch information
LorDClockaN committed Apr 15, 2017
1 parent 83e8e73 commit f3d5525
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 114 deletions.
4 changes: 1 addition & 3 deletions tools/fileslist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
# limitations under the License.
#

from __future__ import print_function

import json, hashlib, operator, os, sys

def get_file_size(path):
st = os.lstat(path)
return st.st_size
return st.st_size;

def get_file_digest(path):
if os.path.isfile(path) == False:
Expand Down
73 changes: 34 additions & 39 deletions tools/releasetools/build_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,17 @@
Usage: build_image input_directory properties_file output_image_file
"""

from __future__ import print_function

import os
import os.path
import re
import subprocess
import sys
import commands
import common
import shutil
import sparse_img
import tempfile

try:
from commands import getstatusoutput
except ImportError:
from subprocess import getstatusoutput

OPTIONS = common.OPTIONS

FIXED_SALT = "aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7"
Expand All @@ -51,36 +44,36 @@ def RunCommand(cmd):
Returns:
A tuple of the output and the exit code.
"""
print("Running: %s" % " ".join(cmd))
print "Running: ", " ".join(cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = p.communicate()
print("%s" % output.rstrip())
print "%s" % (output.rstrip(),)
return (output, p.returncode)

def GetVerityFECSize(partition_size):
cmd = "fec -s %d" % partition_size
status, output = getstatusoutput(cmd)
status, output = commands.getstatusoutput(cmd)
if status:
print(output)
print output
return False, 0
return True, int(output)

def GetVerityTreeSize(partition_size):
cmd = "build_verity_tree -s %d"
cmd %= partition_size
status, output = getstatusoutput(cmd)
status, output = commands.getstatusoutput(cmd)
if status:
print(output)
print output
return False, 0
return True, int(output)

def GetVerityMetadataSize(partition_size):
cmd = "system/extras/verity/build_verity_metadata.py size %d"
cmd %= partition_size

status, output = getstatusoutput(cmd)
status, output = commands.getstatusoutput(cmd)
if status:
print(output)
print output
return False, 0
return True, int(output)

Expand Down Expand Up @@ -157,17 +150,17 @@ def BuildVerityFEC(sparse_image_path, verity_path, verity_fec_path,
print cmd
status, output = commands.getstatusoutput(cmd)
if status:
print("Could not build FEC data! Error: %s" % output)
print "Could not build FEC data! Error: %s" % output
return False
return True

def BuildVerityTree(sparse_image_path, verity_image_path, prop_dict):
cmd = "build_verity_tree -A %s %s %s" % (
FIXED_SALT, sparse_image_path, verity_image_path)
print(cmd)
status, output = getstatusoutput(cmd)
print cmd
status, output = commands.getstatusoutput(cmd)
if status:
print("Could not build verity tree! Error: %s" % output)
print "Could not build verity tree! Error: %s" % output
return False
root, salt = output.split()
prop_dict["verity_root_hash"] = root
Expand Down Expand Up @@ -218,19 +211,19 @@ def Append2Simg(sparse_image_path, unsparse_image_path, error_message):
"""
cmd = "append2simg %s %s"
cmd %= (sparse_image_path, unsparse_image_path)
print(cmd)
status, output = getstatusoutput(cmd)
print cmd
status, output = commands.getstatusoutput(cmd)
if status:
print("%s: %s" % (error_message, output))
print "%s: %s" % (error_message, output)
return False
return True

def Append(target, file_to_append, error_message):
cmd = 'cat %s >> %s' % (file_to_append, target)
print(cmd)
status, output = getstatusoutput(cmd)
print cmd
status, output = commands.getstatusoutput(cmd)
if status:
print("%s: %s" % (error_message, output))
print "%s: %s" % (error_message, output)
return False
return True

Expand Down Expand Up @@ -355,6 +348,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
Returns:
True iff the image is built successfully.
"""
print("BuildImage: in_dir = %s, out_file = %s" % (in_dir, out_file))
# system_root_image=true: build a system.img that combines the contents of
# /system and the ramdisk, and can be mounted at the root of the file system.
origin_in = in_dir
Expand Down Expand Up @@ -397,7 +391,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
(adjusted_size, verity_size) = AdjustPartitionSizeForVerity(partition_size,
verity_fec_supported)
if not adjusted_size:
print("Error: adjusting partition size for verity failed, partition_size = %d" % partition_size)
print "Error: adjusting partition size for verity failed, partition_size = %d" % partition_size
return False
prop_dict["partition_size"] = str(adjusted_size)
prop_dict["original_partition_size"] = str(partition_size)
Expand Down Expand Up @@ -428,7 +422,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
if "base_fs_file" in prop_dict:
base_fs_file = ConvertBlockMapToBaseFs(prop_dict["base_fs_file"])
if base_fs_file is None:
print("Error: no base fs file found")
print "Error: no base fs file found"
return False
build_command.extend(["-d", base_fs_file])
build_command.extend(["-L", prop_dict["mount_point"]])
Expand Down Expand Up @@ -486,11 +480,12 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):

try:
if reserved_blocks and fs_type.startswith("ext4"):
print("fs type is ext4")
print "fs type is ext4"
(ext4fs_output, exit_code) = RunCommand(build_command)
else:
print("fs type is not ext4")
print "fs type is not ext4"
(_, exit_code) = RunCommand(build_command)
print("Running %s command, exit code = %d" % (build_command, exit_code))
finally:
if in_dir != origin_in:
# Clean up temporary directories and files.
Expand All @@ -500,7 +495,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
if base_fs_file is not None:
os.remove(base_fs_file)
if exit_code != 0:
print("Error: %s command unsuccessful" % build_command)
print "Error: %s command unsuccessful" % build_command
return False

# Bug: 21522719, 22023465
Expand All @@ -514,7 +509,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
ext4fs_stats = re.compile(
r'Created filesystem with .* (?P<used_blocks>[0-9]+)/'
r'(?P<total_blocks>[0-9]+) blocks')
m = ext4fs_stats.match(ext4fs_output.strip().split(b'\n')[-1])
m = ext4fs_stats.match(ext4fs_output.strip().split('\n')[-1])
used_blocks = int(m.groupdict().get('used_blocks'))
total_blocks = int(m.groupdict().get('total_blocks'))
reserved_blocks = min(4096, int(total_blocks * 0.02))
Expand All @@ -541,19 +536,19 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
# create the verified image if this is to be verified
if verity_supported and is_verity_partition:
if not MakeVerityEnabledImage(out_file, verity_fec_supported, prop_dict):
print("Error: making verity enabled image failed")
print "Error: making verity enabled image failed"
return False

if run_fsck and prop_dict.get("skip_fsck") != "true":
success, unsparse_image = UnsparseImage(out_file, replace=False)
if not success:
print("Error: unparsing of image failed")
print "Error: unparsing of image failed"
return False

# Run e2fsck on the inflated image file
e2fsck_command = ["e2fsck", "-f", "-n", unsparse_image]
(_, exit_code) = RunCommand(e2fsck_command)

print("Running %s command, exit code = %d" % (e2fsck_command, exit_code))
os.remove(unsparse_image)

return exit_code == 0
Expand Down Expand Up @@ -675,7 +670,7 @@ def LoadGlobalDict(filename):

def main(argv):
if len(argv) != 4:
print(__doc__)
print __doc__
sys.exit(1)

in_dir = argv[0]
Expand Down Expand Up @@ -704,14 +699,14 @@ def main(argv):
elif image_filename == "oem.img":
mount_point = "oem"
else:
print("error: unknown image file name ", image_filename, file=sys.stderr)
print >> sys.stderr, "error: unknown image file name ", image_filename
exit(1)

image_properties = ImagePropFromGlobalDict(glob_dict, mount_point)

if not BuildImage(in_dir, image_properties, out_file, target_out):
print("error: failed to build %s from %s" % (out_file, in_dir),
file=sys.stderr)
print >> sys.stderr, "error: failed to build %s from %s" % (out_file,
in_dir)
exit(1)


Expand Down
Loading

0 comments on commit f3d5525

Please sign in to comment.