aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2019-01-14 13:02:12 -0600
committerGerrit Code Review2019-01-14 13:02:12 -0600
commit3ab0ca72b5cc8441ea71c6bb7d8e3799148d4370 (patch)
tree71f1380df9232b532176e8f0bae152a8d615375b
parent1df75e3099e706fbe4df1393aa6a08e5c3ff823c (diff)
parent93e7ebe77975a7d48b17306dd625338a88ac4cdb (diff)
downloadplatform-build-3ab0ca72b5cc8441ea71c6bb7d8e3799148d4370.tar.gz
platform-build-3ab0ca72b5cc8441ea71c6bb7d8e3799148d4370.tar.xz
platform-build-3ab0ca72b5cc8441ea71c6bb7d8e3799148d4370.zip
Merge "releasetools: OutputFile stages files under input dir."
-rwxr-xr-xtools/releasetools/add_img_to_target_files.py53
1 files changed, 29 insertions, 24 deletions
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index da5ea4aa1..e75b3b768 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -82,18 +82,23 @@ FIXED_FILE_TIMESTAMP = int((
82 82
83 83
84class OutputFile(object): 84class OutputFile(object):
85 """A helper class to write a generated file to the given dir or zip.
86
87 When generating images, we want the outputs to go into the given zip file, or
88 the given dir.
89
90 Attributes:
91 name: The name of the output file, regardless of the final destination.
92 """
93
85 def __init__(self, output_zip, input_dir, prefix, name): 94 def __init__(self, output_zip, input_dir, prefix, name):
95 # We write the intermediate output file under the given input_dir, even if
96 # the final destination is a zip archive.
97 self.name = os.path.join(input_dir, prefix, name)
86 self._output_zip = output_zip 98 self._output_zip = output_zip
87 self.input_name = os.path.join(input_dir, prefix, name)
88
89 if self._output_zip: 99 if self._output_zip:
90 self._zip_name = os.path.join(prefix, name) 100 self._zip_name = os.path.join(prefix, name)
91 101
92 root, suffix = os.path.splitext(name)
93 self.name = common.MakeTempFile(prefix=root + '-', suffix=suffix)
94 else:
95 self.name = self.input_name
96
97 def Write(self): 102 def Write(self):
98 if self._output_zip: 103 if self._output_zip:
99 common.ZipWrite(self._output_zip, self.name, self._zip_name) 104 common.ZipWrite(self._output_zip, self.name, self._zip_name)
@@ -129,9 +134,9 @@ def AddSystem(output_zip, recovery_img=None, boot_img=None):
129 output_zip. Returns the name of the system image file.""" 134 output_zip. Returns the name of the system image file."""
130 135
131 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "system.img") 136 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "system.img")
132 if os.path.exists(img.input_name): 137 if os.path.exists(img.name):
133 logger.info("system.img already exists; no need to rebuild...") 138 logger.info("system.img already exists; no need to rebuild...")
134 return img.input_name 139 return img.name
135 140
136 def output_sink(fn, data): 141 def output_sink(fn, data):
137 ofile = open(os.path.join(OPTIONS.input_tmp, "SYSTEM", fn), "w") 142 ofile = open(os.path.join(OPTIONS.input_tmp, "SYSTEM", fn), "w")
@@ -161,7 +166,7 @@ def AddSystemOther(output_zip):
161 and store it in output_zip.""" 166 and store it in output_zip."""
162 167
163 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "system_other.img") 168 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "system_other.img")
164 if os.path.exists(img.input_name): 169 if os.path.exists(img.name):
165 logger.info("system_other.img already exists; no need to rebuild...") 170 logger.info("system_other.img already exists; no need to rebuild...")
166 return 171 return
167 172
@@ -173,9 +178,9 @@ def AddVendor(output_zip):
173 output_zip.""" 178 output_zip."""
174 179
175 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "vendor.img") 180 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "vendor.img")
176 if os.path.exists(img.input_name): 181 if os.path.exists(img.name):
177 logger.info("vendor.img already exists; no need to rebuild...") 182 logger.info("vendor.img already exists; no need to rebuild...")
178 return img.input_name 183 return img.name
179 184
180 block_list = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "vendor.map") 185 block_list = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "vendor.map")
181 CreateImage(OPTIONS.input_tmp, OPTIONS.info_dict, "vendor", img, 186 CreateImage(OPTIONS.input_tmp, OPTIONS.info_dict, "vendor", img,
@@ -188,9 +193,9 @@ def AddProduct(output_zip):
188 output_zip.""" 193 output_zip."""
189 194
190 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "product.img") 195 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "product.img")
191 if os.path.exists(img.input_name): 196 if os.path.exists(img.name):
192 logger.info("product.img already exists; no need to rebuild...") 197 logger.info("product.img already exists; no need to rebuild...")
193 return img.input_name 198 return img.name
194 199
195 block_list = OutputFile( 200 block_list = OutputFile(
196 output_zip, OPTIONS.input_tmp, "IMAGES", "product.map") 201 output_zip, OPTIONS.input_tmp, "IMAGES", "product.map")
@@ -206,9 +211,9 @@ def AddProductServices(output_zip):
206 211
207 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", 212 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES",
208 "product_services.img") 213 "product_services.img")
209 if os.path.exists(img.input_name): 214 if os.path.exists(img.name):
210 logger.info("product_services.img already exists; no need to rebuild...") 215 logger.info("product_services.img already exists; no need to rebuild...")
211 return img.input_name 216 return img.name
212 217
213 block_list = OutputFile( 218 block_list = OutputFile(
214 output_zip, OPTIONS.input_tmp, "IMAGES", "product_services.map") 219 output_zip, OPTIONS.input_tmp, "IMAGES", "product_services.map")
@@ -222,9 +227,9 @@ def AddOdm(output_zip):
222 """Turn the contents of ODM into an odm image and store it in output_zip.""" 227 """Turn the contents of ODM into an odm image and store it in output_zip."""
223 228
224 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "odm.img") 229 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "odm.img")
225 if os.path.exists(img.input_name): 230 if os.path.exists(img.name):
226 logger.info("odm.img already exists; no need to rebuild...") 231 logger.info("odm.img already exists; no need to rebuild...")
227 return img.input_name 232 return img.name
228 233
229 block_list = OutputFile( 234 block_list = OutputFile(
230 output_zip, OPTIONS.input_tmp, "IMAGES", "odm.map") 235 output_zip, OPTIONS.input_tmp, "IMAGES", "odm.map")
@@ -241,9 +246,9 @@ def AddDtbo(output_zip):
241 image under PREBUILT_IMAGES/, signs it as needed, and returns the image name. 246 image under PREBUILT_IMAGES/, signs it as needed, and returns the image name.
242 """ 247 """
243 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "dtbo.img") 248 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "dtbo.img")
244 if os.path.exists(img.input_name): 249 if os.path.exists(img.name):
245 logger.info("dtbo.img already exists; no need to rebuild...") 250 logger.info("dtbo.img already exists; no need to rebuild...")
246 return img.input_name 251 return img.name
247 252
248 dtbo_prebuilt_path = os.path.join( 253 dtbo_prebuilt_path = os.path.join(
249 OPTIONS.input_tmp, "PREBUILT_IMAGES", "dtbo.img") 254 OPTIONS.input_tmp, "PREBUILT_IMAGES", "dtbo.img")
@@ -344,7 +349,7 @@ def AddUserdata(output_zip):
344 """ 349 """
345 350
346 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "userdata.img") 351 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "userdata.img")
347 if os.path.exists(img.input_name): 352 if os.path.exists(img.name):
348 logger.info("userdata.img already exists; no need to rebuild...") 353 logger.info("userdata.img already exists; no need to rebuild...")
349 return 354 return
350 355
@@ -418,9 +423,9 @@ def AddVBMeta(output_zip, partitions, name, needed_partitions):
418 423
419 img = OutputFile( 424 img = OutputFile(
420 output_zip, OPTIONS.input_tmp, "IMAGES", "{}.img".format(name)) 425 output_zip, OPTIONS.input_tmp, "IMAGES", "{}.img".format(name))
421 if os.path.exists(img.input_name): 426 if os.path.exists(img.name):
422 logger.info("%s.img already exists; not rebuilding...", name) 427 logger.info("%s.img already exists; not rebuilding...", name)
423 return img.input_name 428 return img.name
424 429
425 avbtool = os.getenv('AVBTOOL') or OPTIONS.info_dict["avb_avbtool"] 430 avbtool = os.getenv('AVBTOOL') or OPTIONS.info_dict["avb_avbtool"]
426 cmd = [avbtool, "make_vbmeta_image", "--output", img.name] 431 cmd = [avbtool, "make_vbmeta_image", "--output", img.name]
@@ -497,7 +502,7 @@ def AddCache(output_zip):
497 """Create an empty cache image and store it in output_zip.""" 502 """Create an empty cache image and store it in output_zip."""
498 503
499 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "cache.img") 504 img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "cache.img")
500 if os.path.exists(img.input_name): 505 if os.path.exists(img.name):
501 logger.info("cache.img already exists; no need to rebuild...") 506 logger.info("cache.img already exists; no need to rebuild...")
502 return 507 return
503 508