Merge 1eedb609159bdcc5af125281020db393e7da7151 on remote branch
Change-Id: If27d2c059bb056e1100777a10fd4bac4b85b3c53
diff --git a/aidegen/lib/common_util.py b/aidegen/lib/common_util.py
index 75f2a3c..a5f7c9b 100644
--- a/aidegen/lib/common_util.py
+++ b/aidegen/lib/common_util.py
@@ -98,7 +98,7 @@
1. Module name, e.g. Settings
2. Module path, e.g. packages/apps/Settings
3. Relative path, e.g. ../../packages/apps/Settings
- 4. Current directory, e.g. . or no argument
+ 4. Current directory, e.g. '.' or no argument
5. An empty string, which added by AIDEGen, used for generating
the iml files for the whole Android repo tree.
e.g.
@@ -113,6 +113,9 @@
"""
rel_path = None
abs_path = None
+ # take the command 'aidegen .' as 'aidegen'.
+ if target == '.':
+ target = None
if target:
# For the case of whole Android repo tree.
if target == constant.WHOLE_ANDROID_TREE_TARGET:
@@ -335,33 +338,6 @@
return amodule_info
-def read_file_content(path, encode_type='utf8'):
- """Read file's content.
-
- Args:
- path: Path of input file.
- encode_type: A string of encoding name, default to UTF-8.
-
- Returns:
- String: Content of the file.
- """
- with open(path, encoding=encode_type) as template:
- return template.read()
-
-
-def file_generate(path, content):
- """Generate file from content.
-
- Args:
- path: Path of target file.
- content: String content of file.
- """
- if not os.path.exists(os.path.dirname(path)):
- os.makedirs(os.path.dirname(path))
- with open(path, 'w') as target:
- target.write(content)
-
-
def get_blueprint_json_path(file_name):
"""Assemble the path of blueprint json file.
@@ -465,22 +441,6 @@
logging.basicConfig(level=level, format=log_format, datefmt=datefmt)
-def read_file_line_to_list(file_path):
- """Read a file line by line and write them into a list.
-
- Args:
- file_path: A string of a file's path.
-
- Returns:
- A list of the file's content by line.
- """
- files = []
- with open(file_path, encoding='utf8') as infile:
- for line in infile:
- files.append(line.strip())
- return files
-
-
def exist_android_bp(abs_path):
"""Check if the Android.bp exists under specific folder.
@@ -624,3 +584,49 @@
"""
with open(json_path) as jfile:
return json.load(jfile)
+
+
+@io_error_handle
+def read_file_line_to_list(file_path):
+ """Read a file line by line and write them into a list.
+
+ Args:
+ file_path: A string of a file's path.
+
+ Returns:
+ A list of the file's content by line.
+ """
+ files = []
+ with open(file_path, encoding='utf8') as infile:
+ for line in infile:
+ files.append(line.strip())
+ return files
+
+
+@io_error_handle
+def read_file_content(path, encode_type='utf8'):
+ """Read file's content.
+
+ Args:
+ path: Path of input file.
+ encode_type: A string of encoding name, default to UTF-8.
+
+ Returns:
+ String: Content of the file.
+ """
+ with open(path, encoding=encode_type) as template:
+ return template.read()
+
+
+@io_error_handle
+def file_generate(path, content):
+ """Generate file from content.
+
+ Args:
+ path: Path of target file.
+ content: String content of file.
+ """
+ if not os.path.exists(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
+ with open(path, 'w') as target:
+ target.write(content)
diff --git a/aidegen/lib/common_util_unittest.py b/aidegen/lib/common_util_unittest.py
index 516ff29..69ef8b7 100644
--- a/aidegen/lib/common_util_unittest.py
+++ b/aidegen/lib/common_util_unittest.py
@@ -97,6 +97,8 @@
expected = ('b', '/a/b')
result = common_util.get_related_paths(mod_info, target=None)
self.assertEqual(expected, result)
+ result = common_util.get_related_paths(mod_info, target='.')
+ self.assertEqual(expected, result)
@mock.patch.object(common_util, 'is_android_root')
@mock.patch.object(common_util, 'get_related_paths')
diff --git a/atest/atest.py b/atest/atest.py
index 7202be8..6cf1aca 100755
--- a/atest/atest.py
+++ b/atest/atest.py
@@ -159,8 +159,13 @@
if not os.path.exists(constants.ATEST_RESULT_ROOT):
os.makedirs(constants.ATEST_RESULT_ROOT)
ctime = time.strftime(TEST_RUN_DIR_PREFIX, time.localtime())
- return tempfile.mkdtemp(prefix='%s_' % ctime,
- dir=constants.ATEST_RESULT_ROOT)
+ test_result_dir = tempfile.mkdtemp(prefix='%s_' % ctime,
+ dir=constants.ATEST_RESULT_ROOT)
+ symlink = os.path.join(constants.ATEST_RESULT_ROOT, 'LATEST')
+ if os.path.exists(symlink):
+ os.remove(symlink)
+ os.symlink(test_result_dir, symlink)
+ return test_result_dir
def get_extra_args(args):