From 62556d41c784ae86e5ef415f4b9760ab97d90097 Mon Sep 17 00:00:00 2001 From: Daniel Mentz Date: Tue, 10 Sep 2019 16:31:53 -0700 Subject: [PATCH] mkuserimg_mke2fs.py: Package mke2fs.conf Depending on the environment where mkuserimg_mke2fs.py is used, it's difficult to locate the configuration file mke2fs.conf. To avoid potential issues, let's just package mke2fs.conf with mkuserimg_mke2fs.py. Bug: 112937752 Change-Id: I9eb911fc9357e65a666bafd3089461cac8289008 --- ext4_utils/Android.bp | 4 ++++ ext4_utils/mkuserimg_mke2fs.py | 25 ++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ext4_utils/Android.bp b/ext4_utils/Android.bp index 967af010..4efecf7d 100644 --- a/ext4_utils/Android.bp +++ b/ext4_utils/Android.bp @@ -48,6 +48,10 @@ python_binary_host { "mkuserimg_mke2fs.py", ], + data: [ + "mke2fs.conf", + ], + version: { py2: { enabled: true, diff --git a/ext4_utils/mkuserimg_mke2fs.py b/ext4_utils/mkuserimg_mke2fs.py index 538ffaac..4633426b 100644 --- a/ext4_utils/mkuserimg_mke2fs.py +++ b/ext4_utils/mkuserimg_mke2fs.py @@ -17,8 +17,10 @@ import argparse import logging import os +import pkgutil import subprocess import sys +import tempfile def RunCommand(cmd, env): @@ -212,15 +214,20 @@ def main(argv): output.truncate() # run mke2fs - mke2fs_env = {"MKE2FS_CONFIG" : "./system/extras/ext4_utils/mke2fs.conf"} - if args.timestamp: - mke2fs_env["E2FSPROGS_FAKE_TIME"] = args.timestamp - - output, ret = RunCommand(mke2fs_cmd, mke2fs_env) - print(output) - if ret != 0: - logging.error("Failed to run mke2fs: " + output) - sys.exit(4) + with tempfile.NamedTemporaryFile() as conf_file: + conf_data = pkgutil.get_data('mkuserimg_mke2fs', 'mke2fs.conf') + conf_file.write(conf_data) + conf_file.flush() + mke2fs_env = {"MKE2FS_CONFIG" : conf_file.name} + + if args.timestamp: + mke2fs_env["E2FSPROGS_FAKE_TIME"] = args.timestamp + + output, ret = RunCommand(mke2fs_cmd, mke2fs_env) + print(output) + if ret != 0: + logging.error("Failed to run mke2fs: " + output) + sys.exit(4) # run e2fsdroid e2fsdroid_env = {} -- 2.11.0