Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor usage of args (excluding *args) to argv #33

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions codebasin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@
}


def extract_defines(args):
def extract_defines(argv):
"""
Extract definitions from command-line arguments.
Recognizes two argument "-D MACRO" and one argument "-DMACRO".
"""
defines = []
prefix = ""
for a in args:
for a in argv:
if a == "-D":
prefix = "-D"
elif prefix:
Expand All @@ -150,7 +150,7 @@ def extract_defines(args):
return defines


def extract_include_paths(args):
def extract_include_paths(argv):
"""
Extract include paths from command-line arguments.
Recognizes two argument "-I path" and one argument "-Ipath".
Expand All @@ -159,7 +159,7 @@ def extract_include_paths(args):

include_paths = []
prefix = ""
for a in args:
for a in argv:
if a in prefixes:
prefix = a
elif prefix in prefixes:
Expand All @@ -170,14 +170,14 @@ def extract_include_paths(args):
return include_paths


def extract_include_files(args):
def extract_include_files(argv):
"""
Extract include files from command-line arguments.
Recognizes two argument "-include file".
"""
includes = []
prefix = ""
for a in args:
for a in argv:
if a == "-include":
prefix = "-include"
elif prefix:
Expand Down Expand Up @@ -474,25 +474,25 @@ def get_defines(self, pass_):
_seen_compiler = collections.defaultdict(lambda: False)


def recognize_compiler(args):
def recognize_compiler(argv):
"""
Attempt to recognize the compiler, given an argument list.
Return a Compiler object.
"""
compiler = None
compiler_name = os.path.basename(args[0])
compiler_name = os.path.basename(argv[0])
if compiler_name in ["clang", "clang++"]:
compiler = ClangCompiler(args)
compiler = ClangCompiler(argv)
elif compiler_name in ["gcc", "g++"]:
compiler = GnuCompiler(args)
compiler = GnuCompiler(argv)
elif compiler_name in ["hipcc"]:
compiler = HipCompiler(args)
compiler = HipCompiler(argv)
elif compiler_name in ["icx", "icpx", "ifx"]:
compiler = IntelCompiler(args)
compiler = IntelCompiler(argv)
elif compiler_name == "nvcc":
compiler = NvccCompiler(args)
compiler = NvccCompiler(argv)
else:
compiler = Compiler(args)
compiler = Compiler(argv)

if not _seen_compiler[compiler_name]:
if compiler:
Expand Down Expand Up @@ -526,19 +526,19 @@ def load_database(dbpath, rootdir):
for e in db:
# Database may not have tokenized arguments
if "command" in e:
args = shlex.split(e["command"])
argv = shlex.split(e["command"])
elif "arguments" in e:
args = e["arguments"]
argv = e["arguments"]

# Extract defines, include paths and include files
# from command-line arguments
defines = extract_defines(args)
include_paths = extract_include_paths(args)
include_files = extract_include_files(args)
defines = extract_defines(argv)
include_paths = extract_include_paths(argv)
include_files = extract_include_files(argv)

# Certain tools may have additional, implicit, behaviors
# (e.g., additional defines, multiple passes for multiple targets)
compiler = recognize_compiler(args)
compiler = recognize_compiler(argv)

# Include paths may be specified relative to root
include_paths = [
Expand Down
Loading