Skip to content

Commit

Permalink
Merge pull request #5 from linuxlizard/dpoole/html-output
Browse files Browse the repository at this point in the history
create HTML representation of parsed makefile
  • Loading branch information
linuxlizard committed Jun 23, 2023
2 parents fe77d62 + 4822dc1 commit 7ce1a6c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
41 changes: 41 additions & 0 deletions pymake/html.py
@@ -0,0 +1,41 @@
# https://perfectmotherfuckingwebsite.com/
# copyrighted https://creativecommons.org/publicdomain/zero/1.0/
#
css = """
body{max-width:650px;margin:40px auto;padding:0 10px;font:18px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";color:#444}h1,h2,h3{line-height:1.2}@media (prefers-color-scheme: dark){body{color:#c9d1d9;background:#0d1117}a:link{color:#58a6ff}a:visited{color:#8e96f0}}
"""

top="""
<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Makefile</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="data:image/svg+xml,&lt;svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22&gt;&lt;text y=%22.9em%22 font-size=%2290%22&gt;%F0%9F%96%95&lt;/text&gt;&lt;/svg&gt;">
</head>
<body>
"""

bottom="""
</body></html>
"""

def p(s):
return "<p>%s</p>\n" % s

def _save_rules(outfile, rules):
for target,rule in rules.items():
outfile.write(p(target + " : " + " ".join([pr for pr in rule.prereq_list if not pr.startswith("/usr")])))

def save_rules(outfilename, rules):
with open("style.css","w") as outfile:
outfile.write(css)

with open(outfilename,"w") as outfile:
outfile.write(top)
_save_rules(outfile,rules)
outfile.write(bottom)

15 changes: 14 additions & 1 deletion pymake/pymake.py
Expand Up @@ -465,9 +465,14 @@ def execute(makefile, args):
# write the rules db to graphviz if requested
if args.dotfile:
title = get_basename(makefile.get_pos()[0])
rulesdb.graph(title + "_makefile", args.dotfile)
rulesdb.graphiz_graph(title + "_makefile", args.dotfile)
print("wrote %s for graphviz" % args.dotfile)

if args.htmlfile:
title = get_basename(makefile.get_pos()[0])
rulesdb.html_graph(title + "_makefile", args.htmlfile)
print("wrote %s for html" % args.htmlfile)

try:
if not target_list:
target_list = [ rulesdb.get_default_target() ]
Expand Down Expand Up @@ -565,6 +570,8 @@ def usage():
Options not in GNU Make:
--dotfile FILE
Write the Rules' dependency graph as a GraphViz dot file. (Work in progress.)
--html FILE
Write the Rules' dependency graph as an HTML file. (Work in progress.)
--explain Give a verbose error message for common GNU Make errors.
--output FILE
Rewrite the parsed makefile to FILE.
Expand All @@ -578,6 +585,9 @@ def __init__(self):
# write rules' dependencies to graphviz .dot file
self.dotfile = None

# write rules' dependencies to HTML .html file
self.htmlfile = None

# input filename to parse
self.filename = None

Expand Down Expand Up @@ -612,6 +622,7 @@ def parse_args(argv):
"always-make",
"debug",
"dotfile=",
"html=",
"explain",
"file=",
"makefile=",
Expand Down Expand Up @@ -647,6 +658,8 @@ def parse_args(argv):
args.detailed_error_explain = True
elif opt[0] == "--dotfile":
args.dotfile = opt[1]
elif opt[0] == "--html":
args.htmlfile = opt[1]
elif opt[0] in ("-C", "--directory"):
# multiple -C options are supported for reasons I don't understand
if args.directory is None:
Expand Down
6 changes: 5 additions & 1 deletion pymake/rules.py
Expand Up @@ -7,6 +7,7 @@
#logger.setLevel(level=logging.DEBUG)

from pymake.error import *
from pymake.html import save_rules

_debug = True

Expand Down Expand Up @@ -102,7 +103,10 @@ def walk_tree(self, target):
def __str__(self):
return ",".join(self.rules.keys())

def graph(self, title, dotfilename):
def html_graph(self, title, outfilename):
save_rules(outfilename, self.rules)

def graphviz_graph(self, title, dotfilename):
# Build a graphviz dot file. This is the 2nd biggest reason I made this
# whole silly program.

Expand Down

0 comments on commit 7ce1a6c

Please sign in to comment.