summaryrefslogtreecommitdiff
path: root/apexer/apexer.py
diff options
context:
space:
mode:
authorAlex Light <allight@google.com>2019-03-04 14:27:28 -0800
committerAlex Light <allight@google.com>2019-03-04 14:27:28 -0800
commit18a1b19a7472d12b65c1aa6f749bc0101a43ba63 (patch)
tree2b6b17fd44009256d874cd9db930134cc91d8dc6 /apexer/apexer.py
parent772d63e920502dac417c37e7483bb7575fb482d3 (diff)
Allow APEXER_TOOL_PATH to be set by a flag.
Add a --apexer_tool_path flag that can be used instead of the APEXER_TOOL_PATH environment variable. Test: apexer --help Test: m com.android.support.apexer Test: Build manual apex using --apexer_tool_path Change-Id: I51e689a322574df6d2c4d29823e7bbe778b8e335
Diffstat (limited to 'apexer/apexer.py')
-rw-r--r--apexer/apexer.py27
1 files changed, 11 insertions, 16 deletions
diff --git a/apexer/apexer.py b/apexer/apexer.py
index fc580bc..56b4c9b 100644
--- a/apexer/apexer.py
+++ b/apexer/apexer.py
@@ -35,21 +35,7 @@ import xml.etree.ElementTree as ET
from apex_manifest import ValidateApexManifest
from apex_manifest import ApexManifestError
-if 'APEXER_TOOL_PATH' not in os.environ:
- sys.stderr.write("""
-Error. The APEXER_TOOL_PATH environment variable needs to be set, and point to
-a list of directories containing all the tools used by apexer (e.g. mke2fs,
-avbtool, etc.) separated by ':'. Typically this can be set as:
-
-export APEXER_TOOL_PATH="${ANDROID_BUILD_TOP}/out/soong/host/linux-x86/bin:${ANDROID_BUILD_TOP}/prebuilts/sdk/tools/linux/bin"
-
-Aborting.
-""")
- sys.exit(1)
-
-tool_path = os.environ['APEXER_TOOL_PATH']
-tool_path_list = tool_path.split(":")
-
+tool_path_list = None
BLOCK_SIZE = 4096
def ParseArgs(argv):
@@ -83,6 +69,13 @@ def ParseArgs(argv):
parser.add_argument('--android_jar_path', required=False,
default="prebuilts/sdk/current/public/android.jar",
help='path to use as the source of the android API.')
+ apexer_path_in_environ = "APEXER_TOOL_PATH" in os.environ
+ parser.add_argument('--apexer_tool_path', required=not apexer_path_in_environ,
+ default=os.environ['APEXER_TOOL_PATH'].split(":") if apexer_path_in_environ else None,
+ type=lambda s: s.split(":"),
+ help="""A list of directories containing all the tools used by apexer (e.g.
+ mke2fs, avbtool, etc.) separated by ':'. Can also be set using the
+ APEXER_TOOL_PATH environment variable""")
return parser.parse_args(argv)
def FindBinaryPath(binary):
@@ -90,7 +83,7 @@ def FindBinaryPath(binary):
binary_path = os.path.join(path, binary)
if os.path.exists(binary_path):
return binary_path
- raise Exception("Failed to find binary " + binary + " in path " + tool_path)
+ raise Exception("Failed to find binary " + binary + " in path " + ":".join(tool_path_list))
def RunCommand(cmd, verbose=False, env=None):
env = env or {}
@@ -410,7 +403,9 @@ class TempDirectory(object):
def main(argv):
+ global tool_path_list
args = ParseArgs(argv)
+ tool_path_list = args.apexer_tool_path
with TempDirectory() as work_dir:
success = CreateApex(args, work_dir)