-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from klauer/makefile_helper
ENH: add Makefile information helper
- Loading branch information
Showing
22 changed files
with
1,293 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
""" | ||
"whatrecord deps" is used to get dependency information from EPICS IOC or | ||
module Makefiles. | ||
Under the hood, this uses GNU make, which is an external dependency required | ||
for correct functionality. | ||
""" | ||
|
||
import argparse | ||
import json | ||
import logging | ||
import sys | ||
from typing import Optional | ||
|
||
import apischema | ||
|
||
from ..common import AnyPath | ||
from ..format import FormatContext | ||
from ..makefile import DependencyGroup, DependencyGroupGraph, Makefile | ||
from .graph import render_graph_to_file | ||
|
||
logger = logging.getLogger(__name__) | ||
DESCRIPTION = __doc__ | ||
|
||
|
||
def build_arg_parser(parser=None): | ||
if parser is None: | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.description = DESCRIPTION | ||
parser.formatter_class = argparse.RawTextHelpFormatter | ||
|
||
parser.add_argument( | ||
"path", type=str, help="Path to IOC or Makefile itself" | ||
) | ||
|
||
parser.add_argument( | ||
"--keep-os-env", | ||
action="store_true", | ||
help=( | ||
"Keep environment variables present outside of ``make`` in the " | ||
".env dictionaries" | ||
) | ||
) | ||
|
||
parser.add_argument( | ||
"--no-recurse", | ||
action="store_true", | ||
help="Do not recurse into dependencies", | ||
) | ||
|
||
parser.add_argument( | ||
"--friendly", | ||
dest="friendly", | ||
action="store_true", | ||
help="Output user-friendly text instead of JSON", | ||
) | ||
|
||
parser.add_argument( | ||
"--graph", | ||
action="store_true", | ||
help="Output a graph of dependencies", | ||
) | ||
|
||
parser.add_argument( | ||
"-o", "--graph-output", | ||
type=str, | ||
required=False, | ||
help="Output file to write to. Defaults to standard output.", | ||
) | ||
|
||
return parser | ||
|
||
|
||
def main( | ||
path: AnyPath, | ||
friendly: bool = False, | ||
no_recurse: bool = False, | ||
keep_os_env: bool = False, | ||
graph: bool = False, | ||
graph_output: Optional[str] = None, | ||
file=sys.stdout, | ||
): | ||
makefile_path = Makefile.find_makefile(path) | ||
makefile = Makefile.from_file(makefile_path, keep_os_env=keep_os_env) | ||
info = DependencyGroup.from_makefile( | ||
makefile, recurse=not no_recurse, keep_os_env=keep_os_env | ||
) | ||
|
||
if graph: | ||
group_graph = DependencyGroupGraph(info) | ||
render_graph_to_file(group_graph.to_digraph(), filename=graph_output) | ||
# An alternative to 'whatrecord graph'; both should have the same | ||
# result in the end. | ||
return | ||
|
||
if not friendly: | ||
json_info = apischema.serialize(info) | ||
print(json.dumps(json_info, indent=4)) | ||
else: | ||
fmt = FormatContext() | ||
print(fmt.render_object(info, "console"), file=file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.