Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 24f504d

Browse files
committed
Add GA tracking for flavors; more build tooling.
1 parent eebe33b commit 24f504d

File tree

7 files changed

+266
-17
lines changed

7 files changed

+266
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ packages/
99
src/generic/Build
1010
src/generic/haskell-platform-*
1111
src/macos/dist*
12+
.shake/
13+
config.platform
14+
ghc-*.tar.xz

BUILD.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
Synopsis of build instructions:
3+
4+
1. Use `find-bindist` to download a GHC bindist:
5+
6+
$ ./find-bindist apple
7+
... url displayed ...
8+
$ wget ...url...
9+
10+
2. If necessary, build `cabal` version >= 1.24:
11+
12+
$ cabal get cabal-install-1.24.0.0
13+
$ cd cabal-install-1.24.0.0
14+
$ cabal sandbox init
15+
$ cabal install --only-dependencies
16+
$ cabal install
17+
$ cp ./dist/dist-sandbox-.../build/cabal/cabal /usr/local/bin/cabal
18+
19+
3. Use `platform-init` to initialize the `config.platform` file:
20+
21+
$ ./platform-init
22+
23+
Make sure the version of cabal is >= 1.24. Edit entries as needed.
24+
25+
4. Run `./new-platform.sh`
26+
27+
$ ./new-platform.sh build-all
28+
$ ./new-platform.sh build-website
29+
30+
The website files reside in `build/product/website`.
31+
32+
5. In a new terminal, start up the python server:
33+
34+
$ ./server ./build/product/website 12345
35+
36+
You can leave this running - it will track changes as you re-build
37+
the website.
38+

find-bindist

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python
2+
#
3+
# Return the url for a GHC bindist.
4+
#
5+
# Examples:
6+
# find-bindist apple
7+
# find-bindist deb8 64
8+
# find-bindist i3 ming
9+
# find-bindist apple 7.10.2
10+
# find-bindist -- shows all bin dists
11+
12+
import requests
13+
import re
14+
import os
15+
import sys
16+
17+
BASE_URL = "http://downloads.haskell.org/~ghc"
18+
DEFAULT_GHC_VERSION = "8.0.1"
19+
20+
def list_bin_dists(url):
21+
r = requests.get(url)
22+
contents = r.text
23+
return re.findall('a href="(ghc-.*?.tar.xz)"', contents)
24+
25+
def has_words(words, m):
26+
for w in words:
27+
if not (w in m):
28+
return False
29+
return True
30+
31+
def is_ghc_vers(arg):
32+
return re.match("(\d+)\.(\d+)\.(\d+)\Z", arg)
33+
34+
def process_args(args):
35+
versions = []
36+
others = []
37+
for arg in args:
38+
if is_ghc_vers(arg):
39+
versions.append(arg)
40+
else:
41+
others.append(arg)
42+
return versions, others
43+
44+
def main():
45+
args = sys.argv[1:]
46+
47+
versions, words = process_args(sys.argv[1:])
48+
if not versions:
49+
versions.append(DEFAULT_GHC_VERSION)
50+
51+
ghc_vers = versions[0]
52+
53+
url = BASE_URL + "/" + ghc_vers + "/"
54+
matches = [ m for m in list_bin_dists(url) if has_words(words, m) ]
55+
if not matches:
56+
if words:
57+
msg = " contain the words: " + ", ".join(words)
58+
else:
59+
msg = ""
60+
print "no bindists for version " + ghc_vers + msg
61+
elif len(matches) == 1:
62+
print url + matches[0]
63+
else:
64+
print "Multiple matching bindists:"
65+
for m in matches:
66+
print " ", url + m
67+
68+
main()
69+

platform-init

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python
2+
#
3+
# Generate the config.platform file
4+
5+
import glob
6+
import re
7+
import sys
8+
import os
9+
import subprocess
10+
11+
def kvpair(k,v):
12+
return k + '="{}"'.format(v)
13+
14+
def which(file):
15+
for path in os.environ["PATH"].split(os.pathsep):
16+
if os.path.exists(os.path.join(path, file)):
17+
return os.path.join(path, file)
18+
19+
return None
20+
21+
def cabal_version(cabal):
22+
output = subprocess.Popen([cabal, "--version"], stdout=subprocess.PIPE).communicate()[0]
23+
# cabal-install version 1.22.6.0
24+
m = re.match("cabal-install version (\d[.\d]*)", output)
25+
if m:
26+
return m.groups(1)[0]
27+
else:
28+
return None
29+
30+
def parse_version(s):
31+
# s must be a string of digits and '.'
32+
return [ int(x) for x in s.split('.') ]
33+
34+
def compare_versions(a,b):
35+
# print "compare_versions:, a:", a, "b:", b
36+
if (not a) and (not b):
37+
return 0
38+
if not a:
39+
if not b: return 0
40+
return compare_versions( [0], b)
41+
if not b:
42+
return compare_versions( a, [0])
43+
if int(a[0]) == int(b[0]):
44+
return compare_versions(a[1:], b[1:])
45+
return cmp(a[0], b[0])
46+
47+
def main():
48+
bindists = glob.glob("ghc-*.tar.xz")
49+
if not bindists:
50+
print "No GHC bindists found in the current working directory"
51+
sys.exit(1)
52+
elif len(bindists) > 1:
53+
print "Multiple bindists found:"
54+
for m in bindists:
55+
print " ", m
56+
sys.exit(1)
57+
58+
stack = which("stack")
59+
if not stack:
60+
print "unable to find stack in PATH"
61+
sys.exit(1)
62+
print "found stack at", stack
63+
64+
cabal = which("cabal")
65+
if not cabal:
66+
print "unable to find cabal in PATH"
67+
sys.exit(1)
68+
print "found cabal at", stack
69+
70+
# Check the cabal version
71+
cversion = cabal_version(cabal)
72+
if not cversion:
73+
print "unable to parse cabal version for", cabal
74+
sys.exit(1)
75+
76+
bad_cabal = compare_versions([1,24], parse_version(cversion)) > 0
77+
if bad_cabal:
78+
cok = "NOT OK"
79+
else:
80+
cok = "OK"
81+
print "cabal version is", cversion, "-", cok
82+
83+
if bad_cabal:
84+
print "\n*** WARNING - cabal >= 1.24 required"
85+
86+
contents = "\n".join([ kvpair("GHC_BINDIST", bindists[0]), kvpair("STACK", stack), kvpair("CABAL", cabal) ]) + "\n"
87+
with open("config.platform", "w") as f:
88+
f.write(contents)
89+
print "\nCreated the file config.platform with the contents:\n"
90+
print contents
91+
92+
main()

server

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
import SocketServer
4+
import SimpleHTTPServer
5+
import urllib
6+
import posixpath
7+
import os
8+
import sys
9+
10+
PORT = 1235
11+
BASE_DIR="/home/erantapaa/build-hp/haskell-platform/build/product/website"
12+
13+
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
14+
def translate_path(self, path):
15+
"""Translate a /-separated PATH to the local filename syntax.
16+
Components that mean special things to the local file system
17+
(e.g. drive or directory names) are ignored. (XXX They should
18+
probably be diagnosed.)
19+
"""
20+
# abandon query parameters
21+
path = path.split('?',1)[0]
22+
path = path.split('#',1)[0]
23+
path = posixpath.normpath(urllib.unquote(path))
24+
words = path.split('/')
25+
words = filter(None, words)
26+
path = BASE_DIR # os.getcwd()
27+
for word in words:
28+
drive, word = os.path.splitdrive(word)
29+
head, word = os.path.split(word)
30+
if word in (os.curdir, os.pardir): continue
31+
path = os.path.join(path, word)
32+
return path
33+
34+
def main():
35+
args = sys.argv[1:]
36+
if len(args) < 2:
37+
print "Usage: server directory port"
38+
sys.exit(1)
39+
BASE_DIR = args[0]
40+
PORT = int(args[1])
41+
httpd = SocketServer.ForkingTCPServer(('', PORT), Proxy)
42+
print "serving at port", PORT
43+
httpd.serve_forever()
44+
45+
main()
46+
47+

website/plan-a/js/download.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@ $(document).ready(function() {
44
$('body').addClass('js');
55
});
66

7-
$(document).ready(function() {
8-
$('.expandable').each(function() {
9-
var $this = $(this);
10-
$this.children().wrapAll('<div class="contents"></div>')
11-
var $contents = $this.children();
12-
$contents.hide();
13-
14-
var $link = $('<a href="#">Click to expand</a>');
15-
$this.prepend($link);
16-
17-
$link.click(function() {
18-
$contents.slideToggle();
19-
});
20-
});
21-
});
22-
237
function identifyPlatform() {
248
var ua = navigator.userAgent;
259
var userAgents = {
@@ -105,3 +89,18 @@ $(document).ready(function() {
10589
window.history.replaceState({}, '', distro);
10690
});
10791
});
92+
93+
// add GA events
94+
$(document).ready(function() {
95+
// $('.platform-name').click(function(e) {
96+
// console.log("--- platform-name clicked")
97+
// return true
98+
// });
99+
$('.flavors ul li a').click(function(e) {
100+
var which = this.getAttribute("href")
101+
// console.log("--- flavor anchor clicked", which)
102+
ga("send", "event", { eventCategory:"Download", eventAction:"flavor", eventLabel: which })
103+
return true
104+
});
105+
});
106+

website/templates/plan-a/footer.mu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
2020
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
2121

22-
go('create', 'UA-832905133-1', 'auto');
22+
ga('create', 'UA-83290513-1', 'auto');
23+
// ga('create', 'UA-78576289-1', 'auto'); // testing account
2324
ga('send', 'pageview');
2425
function dl(me) {
2526
ga('send','event',{eventCategory:'Download', eventAction:'Download HP', eventLabel:me.href})

0 commit comments

Comments
 (0)