Skip to content

Commit 8383e56

Browse files
authored
Merge pull request rust-lang#1107 from Manishearth/setup-gh-pages
Setup gh-pages
2 parents a371558 + 01c61a7 commit 8383e56

File tree

7 files changed

+416
-0
lines changed

7 files changed

+416
-0
lines changed

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 4
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.github/deploy.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Automatically deploy on gh-pages
3+
4+
set -e
5+
6+
SOURCE_BRANCH="master"
7+
TARGET_BRANCH="gh-pages"
8+
9+
# Save some useful information
10+
REPO=$(git config remote.origin.url)
11+
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
12+
SHA=$(git rev-parse --verify HEAD)
13+
14+
# Clone the existing gh-pages for this repo into out/
15+
(
16+
git clone "$REPO" out
17+
cd out
18+
git checkout $TARGET_BRANCH
19+
)
20+
21+
# Remove the current doc for master
22+
rm -rf out/master/ || exit 0
23+
24+
# Make the doc for master
25+
mkdir out/master/
26+
cp util/gh-pages/index.html out/master
27+
./util/export.py out/master/lints.json
28+
29+
# Save the doc for the current tag and point current/ to it
30+
if [ -n "$TRAVIS_TAG" ]; then
31+
cp -r out/master "out/$TRAVIS_TAG"
32+
rm -f out/current
33+
ln -s "$TRAVIS_TAG" out/current
34+
fi
35+
36+
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
37+
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
38+
echo "Generated, won't push"
39+
exit 0
40+
fi
41+
42+
# Now let's go have some fun with the cloned repo
43+
cd out
44+
git config user.name "Travis CI"
45+
git config user.email "[email protected]"
46+
47+
if [ -z "$(git diff --exit-code)" ]; then
48+
echo "No changes to the output on this push; exiting."
49+
exit 0
50+
fi
51+
52+
git add .
53+
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
54+
55+
# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
56+
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
57+
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
58+
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
59+
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
60+
openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in deploy_key.enc -out deploy_key -d
61+
chmod 600 deploy_key
62+
eval $(ssh-agent -s)
63+
ssh-add deploy_key
64+
65+
# Now that we're all set up, we can push.
66+
git push "$SSH_REPO" "$TARGET_BRANCH"

.github/deploy_key.enc

1.64 KB
Binary file not shown.

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Used by Travis to be able to push:
2+
/.github/deploy_key
3+
out
4+
15
# Compiled files
26
*.o
37
*.so
@@ -16,3 +20,6 @@ Cargo.lock
1620

1721
# Generated by dogfood
1822
/target_recur/
23+
24+
# gh pages docs
25+
util/gh-pages/lints.json

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ after_success:
4646
else
4747
echo "Ignored"
4848
fi
49+
- |
50+
if [ "$TRAVIS_PULL_REQUEST" == "false" ] &&
51+
[ "$TRAVIS_REPO_SLUG" == "Manishearth/rust-clippy" ] &&
52+
[ "$TRAVIS_BRANCH" == "master" ] ; then
53+
54+
python util/export.py
55+
56+
fi

util/export.py

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/usr/bin/env python
2+
# Build the gh-pages
3+
4+
import json
5+
import os
6+
import re
7+
import sys
8+
9+
10+
level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
11+
conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
12+
confvar_re = re.compile(r'''/// Lint: (\w+). (.*).*\n *\("([^"]*)", (?:[^,]*), (.*) => (.*)\),''')
13+
lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
14+
15+
conf_template = """
16+
This lint has the following configuration variables:
17+
18+
* `%s: %s`: %s (defaults to `%s`).
19+
"""
20+
21+
22+
# TODO: actual logging
23+
def warn(*args):
24+
print(*args)
25+
26+
27+
def debug(*args):
28+
print(*args)
29+
30+
31+
def info(*args):
32+
print(*args)
33+
34+
35+
def parse_path(p="clippy_lints/src"):
36+
lints = []
37+
for f in os.listdir(p):
38+
if f.endswith(".rs"):
39+
parse_file(lints, os.path.join(p, f))
40+
41+
conf = parse_conf(p)
42+
info(conf)
43+
44+
for lint_id in conf:
45+
lint = next(l for l in lints if l['id'] == lint_id)
46+
if lint:
47+
lint['docs']['Configuration'] = (conf_template % conf[lint_id]).strip()
48+
49+
return lints
50+
51+
52+
def parse_conf(p):
53+
c = {}
54+
with open(p + '/utils/conf.rs') as f:
55+
f = f.read()
56+
57+
m = re.search(conf_re, f)
58+
m = m.groups()[0]
59+
60+
m = re.findall(confvar_re, m)
61+
62+
for (lint, doc, name, default, ty) in m:
63+
c[lint.lower()] = (name, ty, doc, default)
64+
65+
return c
66+
67+
68+
def parseLintDef(level, comment, name):
69+
lint = {}
70+
lint['id'] = name
71+
lint['level'] = level
72+
lint['docs'] = {}
73+
74+
last_section = None
75+
76+
for line in comment:
77+
if len(line.strip()) == 0:
78+
continue
79+
80+
match = re.match(lint_subheadline, line)
81+
if match:
82+
last_section = match.groups()[0]
83+
if match:
84+
text = match.groups()[1]
85+
else:
86+
text = line
87+
88+
if not last_section:
89+
warn("Skipping comment line as it was not preceded by a heading")
90+
debug("in lint `%s`, line `%s`" % name, line)
91+
92+
lint['docs'][last_section] = (lint['docs'].get(last_section, "") + "\n" + text).strip()
93+
94+
return lint
95+
96+
97+
def parse_file(d, f):
98+
last_comment = []
99+
comment = True
100+
101+
with open(f) as rs:
102+
for line in rs:
103+
if comment:
104+
if line.startswith("///"):
105+
if line.startswith("/// "):
106+
last_comment.append(line[4:])
107+
else:
108+
last_comment.append(line[3:])
109+
elif line.startswith("declare_lint!"):
110+
comment = False
111+
deprecated = False
112+
restriction = False
113+
elif line.startswith("declare_restriction_lint!"):
114+
comment = False
115+
deprecated = False
116+
restriction = True
117+
elif line.startswith("declare_deprecated_lint!"):
118+
comment = False
119+
deprecated = True
120+
else:
121+
last_comment = []
122+
if not comment:
123+
l = line.strip()
124+
m = re.search(r"pub\s+([A-Z_][A-Z_0-9]*)", l)
125+
126+
if m:
127+
name = m.group(1).lower()
128+
129+
# Intentionally either a never looping or infinite loop
130+
while not deprecated and not restriction:
131+
m = re.search(level_re, line)
132+
if m:
133+
level = m.group(0)
134+
break
135+
136+
line = next(rs)
137+
138+
if deprecated:
139+
level = "Deprecated"
140+
elif restriction:
141+
level = "Allow"
142+
143+
info("found %s with level %s in %s" % (name, level, f))
144+
d.append(parseLintDef(level, last_comment, name=name))
145+
last_comment = []
146+
comment = True
147+
if "}" in l:
148+
warn("Warning: Missing Lint-Name in", f)
149+
comment = True
150+
151+
152+
def main():
153+
lints = parse_path()
154+
info("got %s lints" % len(lints))
155+
156+
outdir = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
157+
with open(outdir, "w") as file:
158+
json.dump(lints, file, indent=2)
159+
info("wrote JSON for great justice")
160+
161+
if __name__ == "__main__":
162+
main()

0 commit comments

Comments
 (0)