13
13
import unittest
14
14
from copy import copy
15
15
from pathlib import PurePath
16
- from collections import defaultdict , OrderedDict
16
+ from collections import defaultdict , OrderedDict , namedtuple
17
17
18
18
from dex .utils .Exceptions import CommandParseError , NonFloatValueInCommand
19
19
@@ -83,7 +83,7 @@ def _merge_subcommands(command_name: str, valid_commands: dict) -> dict:
83
83
84
84
85
85
def _build_command (
86
- command_type , labels , addresses , raw_text : str , path : str , lineno : str
86
+ command_type , labels , addresses , raw_text : str , path , lineno : str
87
87
) -> CommandBase :
88
88
"""Build a command object from raw text.
89
89
@@ -100,11 +100,13 @@ def label_to_line(label_name: str) -> int:
100
100
line = labels .get (label_name , None )
101
101
if line != None :
102
102
return line
103
- raise format_unresolved_label_err (label_name , raw_text , path , lineno )
103
+ raise format_unresolved_label_err (label_name , raw_text , path . base , lineno )
104
104
105
105
def get_address_object (address_name : str , offset : int = 0 ):
106
106
if address_name not in addresses :
107
- raise format_undeclared_address_err (address_name , raw_text , path , lineno )
107
+ raise format_undeclared_address_err (
108
+ address_name , raw_text , path .base , lineno
109
+ )
108
110
return AddressExpression (address_name , offset )
109
111
110
112
valid_commands = _merge_subcommands (
@@ -120,7 +122,7 @@ def get_address_object(address_name: str, offset: int = 0):
120
122
command = eval (raw_text , valid_commands )
121
123
# pylint: enable=eval-used
122
124
command .raw_text = raw_text
123
- command .path = path
125
+ command .path = path . declared
124
126
command .lineno = lineno
125
127
return command
126
128
@@ -267,7 +269,8 @@ def _find_all_commands_in_file(path, file_lines, valid_commands, source_root_dir
267
269
labels = {} # dict of {name: line}.
268
270
addresses = [] # list of addresses.
269
271
address_resolutions = {}
270
- cmd_path = path
272
+ CmdPath = namedtuple ("cmd_path" , "base declared" )
273
+ cmd_path = CmdPath (path , path )
271
274
declared_files = set ()
272
275
commands = defaultdict (dict )
273
276
paren_balance = 0
@@ -346,17 +349,16 @@ def _find_all_commands_in_file(path, file_lines, valid_commands, source_root_dir
346
349
elif type (command ) is DexDeclareAddress :
347
350
add_address (addresses , command , path , cmd_point .get_lineno ())
348
351
elif type (command ) is DexDeclareFile :
349
- cmd_path = command .declared_file
350
- if not os .path .isabs (cmd_path ):
352
+ declared_path = command .declared_file
353
+ if not os .path .isabs (declared_path ):
351
354
source_dir = (
352
355
source_root_dir
353
356
if source_root_dir
354
357
else os .path .dirname (path )
355
358
)
356
- cmd_path = os .path .join (source_dir , cmd_path )
357
- # TODO: keep stored paths as PurePaths for 'longer'.
358
- cmd_path = str (PurePath (cmd_path ))
359
- declared_files .add (cmd_path )
359
+ declared_path = os .path .join (source_dir , declared_path )
360
+ cmd_path = CmdPath (cmd_path .base , str (PurePath (declared_path )))
361
+ declared_files .add (cmd_path .declared )
360
362
elif type (command ) is DexCommandLine and "DexCommandLine" in commands :
361
363
msg = "More than one DexCommandLine in file"
362
364
raise format_parse_err (msg , path , file_lines , err_point )
0 commit comments