OSDN Git Service

Create userdata.img with real data when SANITIZE_TARGET=address.
authorYing Wang <wangying@google.com>
Thu, 25 Jun 2015 20:56:53 +0000 (13:56 -0700)
committerYing Wang <wangying@google.com>
Thu, 25 Jun 2015 21:29:04 +0000 (14:29 -0700)
Bug: 21785137
Change-Id: Ie0c36988759fe07419ad29bab5a71cdd0d992d2a

core/Makefile
tools/releasetools/add_img_to_target_files.py
tools/releasetools/build_image.py

index 65b4f18..a6b6cd4 100644 (file)
@@ -1475,6 +1475,10 @@ ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
        # OTA scripts are only interested in fingerprint related properties
        $(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $(zip_root)/META/misc_info.txt
 endif
+ifeq ($(SANITIZE_TARGET),address)
+       # We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
+       $(hide) echo "userdata_img_with_data=true" >> $(zip_root)/META/misc_info.txt
+endif
        $(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
        $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
            ./build/tools/releasetools/make_recovery_patch $(zip_root) $(zip_root)
index eab8113..dee5a69 100755 (executable)
@@ -30,6 +30,7 @@ if sys.hexversion < 0x02070000:
 
 import errno
 import os
+import shutil
 import tempfile
 import zipfile
 
@@ -153,7 +154,13 @@ def CreateImage(input_dir, info_dict, what, block_list=None):
 
 
 def AddUserdata(output_zip, prefix="IMAGES/"):
-  """Create an empty userdata image and store it in output_zip."""
+  """Create a userdata image and store it in output_zip.
+
+  In most case we just create and store an empty userdata.img;
+  But the invoker can also request to create userdata.img with real
+  data from the target files, by setting "userdata_img_with_data=true"
+  in OPTIONS.info_dict.
+  """
 
   prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "userdata.img")
   if os.path.exists(prebuilt_path):
@@ -172,10 +179,19 @@ def AddUserdata(output_zip, prefix="IMAGES/"):
 
   # The name of the directory it is making an image out of matters to
   # mkyaffs2image.  So we create a temp dir, and within it we create an
-  # empty dir named "data", and build the image from that.
+  # empty dir named "data", or a symlink to the DATA dir,
+  # and build the image from that.
   temp_dir = tempfile.mkdtemp()
   user_dir = os.path.join(temp_dir, "data")
-  os.mkdir(user_dir)
+  empty = (OPTIONS.info_dict.get("userdata_img_with_data") != "true")
+  if empty:
+    # Create an empty dir.
+    os.mkdir(user_dir)
+  else:
+    # Symlink to the DATA dir.
+    os.symlink(os.path.join(OPTIONS.input_tmp, "DATA"),
+               user_dir)
+
   img = tempfile.NamedTemporaryFile()
 
   fstab = OPTIONS.info_dict["fstab"]
@@ -187,8 +203,7 @@ def AddUserdata(output_zip, prefix="IMAGES/"):
   common.CheckSize(img.name, "userdata.img", OPTIONS.info_dict)
   common.ZipWrite(output_zip, img.name, prefix + "userdata.img")
   img.close()
-  os.rmdir(user_dir)
-  os.rmdir(temp_dir)
+  shutil.rmtree(temp_dir)
 
 
 def AddCache(output_zip, prefix="IMAGES/"):
index cbcad6d..b12969e 100755 (executable)
@@ -31,7 +31,7 @@ import tempfile
 FIXED_SALT = "aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7"
 
 def RunCommand(cmd):
-  """ Echo and run the given command
+  """ Echo and run the given command.
 
   Args:
     cmd: the command represented as a list of strings.