Skip to content

Commit

Permalink
[GR-48828] Add --graph-file to mx build to dump the build plan.
Browse files Browse the repository at this point in the history
PullRequest: mx/1680
  • Loading branch information
gilles-duboscq committed Sep 22, 2023
2 parents d6c89c9 + 21f1727 commit da29675
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
],

"mx_version": "6.49.1",
"mx_version": "6.50.2",

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
Expand Down
39 changes: 38 additions & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15005,6 +15005,7 @@ def build(cmd_args, parser=None):
parser.add_argument('--all', action='store_true', help='build all dependencies (not just default targets)')
parser.add_argument('--print-timing', action='store_true', help='print start/end times and duration for each build task', default=is_continuous_integration())
parser.add_argument('--gmake', action='store', help='path to the \'make\' executable that should be used', metavar='<path>', default=None)
parser.add_argument('--graph-file', action='store', help='path where a DOT graph of the build plan should be stored.\nIf the extension is ps, pdf, svg, png, git, or jpg, it will be rendered.', metavar='<path>', default=None)

compilerSelect = parser.add_mutually_exclusive_group()
compilerSelect.add_argument('--error-prone', dest='error_prone', help='path to error-prone.jar', metavar='<path>')
Expand Down Expand Up @@ -15100,6 +15101,7 @@ def build(cmd_args, parser=None):
sortedTasks = []
taskMap = {}
depsMap = {}
edges = []

def _createTask(dep, edge):
if dep.name in deps_w_deprecation_errors:
Expand All @@ -15120,9 +15122,44 @@ def _createTask(dep, edge):
def _registerDep(src, dst, edge):
lst = depsMap.setdefault(src, [])
lst.append(dst)
edges.append((src, dst, edge.kind))

walk_deps(visit=_createTask, visitEdge=_registerDep, roots=roots, ignoredEdges=[DEP_EXCLUDED])

if args.graph_file:
ext = get_file_extension(args.graph_file)
if ext in ('dot', ''):
dot_file = args.graph_file
else:
known_formats = 'ps', 'pdf', 'svg', 'png', 'gif', 'jpg'
if ext not in known_formats:
raise abort("Unknown format for graph file. use one of .dot, " + ', '.join('.' + fmt for fmt in known_formats))
dot_file = args.graph_file + '.dot'
with open(dot_file, 'w') as f:
f.write('digraph build_plan {\n')
f.write('rankdir=BT;\n')
f.write('node [shape=rect];\n')
f.write('splines=true;\n')
f.write('ranksep=1;\n')
for src, dst, kind in edges:
attributes = {}
if kind in (DEP_BUILD, DEP_ANNOTATION_PROCESSOR):
attributes['style'] = 'dashed'
if kind == DEP_STANDARD:
attributes['color'] = 'blue'
if kind == DEP_ANNOTATION_PROCESSOR:
attributes['color'] = 'green'
f.write(f'"{src}" -> "{dst}"')
if attributes:
attr_str = ', '.join((k + '="' + v + '"' for k, v in attributes.items()))
f.write(f'[{attr_str}]')
f.write(';\n')
f.write('}')
if dot_file != args.graph_file:
log(f"Rendering {args.graph_file}...")
with open(args.graph_file, 'wb') as f:
run(['dot', '-T' + ext, dot_file], out=f)

if _opts.very_verbose:
log("++ Serialized build plan ++")
for task in sortedTasks:
Expand Down Expand Up @@ -18793,7 +18830,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.50.2") # GR-48785 - Error messages during compression.
version = VersionSpec("6.50.3") # build graph

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down

0 comments on commit da29675

Please sign in to comment.