Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jul 20, 2018
0 parents commit 3963104
Show file tree
Hide file tree
Showing 8 changed files with 756 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.stack-work
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: generic

cache:
directories:
- "$HOME/.stack"

script:
- mkdir -p ~/.local/bin
- export PATH=$HOME/.local/bin:$PATH
- travis_retry curl -L https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
- stack --no-terminal install hlint stylish-haskell
- travis_retry curl -L https://github.com/rubik/stack-hpc-coveralls/releases/download/v0.0.4.0/shc-linux-x64-7.10.3.tar.bz2 | tar -xj -C $HOME/.local/bin
- cp -a bin $HOME/.local/
# TODO(iphydf): Figure out how to do this more generically. How were we supposed
# to know that this file is needed and can be found here?
- cp $HOME/.stack/snapshots/x86_64-linux/lts-11.7/8.2.2/share/x86_64-linux-ghc-8.2.2/hlint-2.1.3/hlint.yaml $HOME/.local/bin/data/
- tar zcf hs-tools-$TRAVIS_TAG.tar.gz -C $HOME .local/bin

deploy:
provider: releases
api_key:
secure: B7li39EsjljhnhwdxoSdtgHl7z44+IzQlO9TZAtcZi3nJiXJB0xwtWr4i03b5OE2ApfJpSDWBZa5eSeNTqa8em/FiqiX7L2J3k/ZvHpupjSs8NRe30Rjb1boiwoN7WBh84MJqxFJOpKWBmJ1Jj38uOlsa4jRG5nMM6OSQBenq+Zp4sji2/HMD3OLeVxjHXjBmTMLWT9F5U7fDX8ZEUDw4Ky/gDzqq9GvL8RUGHyRIrtB/W8osy3jzi6TMrr0ZUGpMz4qgOjCD1HqZgqoSSDxyru0Gvzc7ZysjgnvHp79BLowog6Qqx4Xg56iPUezOMlsykDdYowjw4WeH1pnajrV/0slTFZTrmG1NbA+pJBoDZXzL11dR8ZXquzICDpbNn1Be/dWKH/15av9A9C0tKVWTXMYX38t5+YWIWpnwei0kNy86SdIkS8hPrlpM9X/oKaYx2lTPlAUZ+SameIajlJE8Apb47MxgGK/AZD3B+/6DxF+XeADCCgTx5/LE6OsbTmK87k8CdvsIjWVAo6gN1q/CDvKugFLYm8bccUaqBWsiCIF1IOIk1PTf2i2+rCDFLQDGkq4AoicpcOWGZUUcnDMMS17tEC2tuOZZ0JYwFYxgvGL7QVy3smMpHO273yKtXbh3OMJYYfc/ll7AFuiCOWtqQ0wKvjga1jBg5jonQAm6F0=
file: hs-tools-$TRAVIS_TAG.tar.gz
skip_cleanup: true
on:
repo: TokTok/hs-tools
tags: true
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load("//tools:project.bzl", "project")

project("hs-tools")
595 changes: 595 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Haskell tool repository

This repository contains tools for working with the TokTok Haskell
repositories. Its purpose is mainly to centralise the costly building of
external tools like `hlint` and `stylish-haskell`, which otherwise each Travis
build would have to do, itself. We also store some smaller scripts here that
support the Travis builds, so we can reduce duplication between the separate
Travis build configurations.
3 changes: 3 additions & 0 deletions bin/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Data files for stack-installed packages

This directory contains data files we need to manually copy from `~/.stack`.
117 changes: 117 additions & 0 deletions bin/stylish-haskell-lhs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env perl

use strict;
no warnings;
use utf8;

use v5.10.1;

use Data::Dumper;
use File::Find;
use IPC::Open2;

$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 1;

my $INPLACE = $ARGV[0] eq "-i";
shift @ARGV if $INPLACE;

my @FILES = @ARGV or die "Usage: format-haskell [-i] <file|dir>...";

sub parse_file {
my ($file) = @_;

my @lines = do { open my $fh, '<', $file or die "$file: $!"; <$fh> };
chomp for @lines;

my @docs;
my @code;

my $in_code = 0;
for (@lines) {
if ($in_code) {
if (/^\\end\{code\}$/) {
$in_code = 0;
push @docs, $_;
} else {
push @{ $code[0] }, $_;
}
} else {
push @docs, $_;
if (/^\\begin\{code\}$/) {
$in_code = 1;
unshift @code, ["-- CODE BLOCK " . scalar @code];
}
}
}

(\@lines, \@docs, map { @$_ } reverse @code)
}

sub stylish_haskell {
my ($out, $in);
my $pid = open2 $out, $in, "stylish-haskell";
print $in "$_\n" for @_;
close $in;

my @code = <$out>;
chomp for @code;
waitpid $pid, 0;

@code
}

sub format_file {
my ($file) = @_;

if ($file =~ /\.hs$/) {
system "stylish-haskell", "-i", $file;
} else {
my ($lines, $docs, @code) = parse_file $file;
@code = stylish_haskell @code;

# Split processed code back into blocks.
my @blocks;
for (@code) {
if (/^-- CODE BLOCK \d+$/) {
push @blocks, [];
} else {
push @{ $blocks[$#blocks] }, $_;
}
}

# Splice code into docs.
my @result;
for (@$docs) {
push @result, $_;
if (/^\\begin\{code\}$/) {
push @result, @{ shift @blocks };
}
}

if ($INPLACE) {
if (@result ~~ @$lines) {
# Nothing to do, no changes.
} else {
open my $fh, '>', $file or die "Could not open $file for writing: $!";
print $fh "$_\n" for @result;
}
} else {
print "$_\n" for @result;
}
}
}

for my $file (@FILES) {
if (-f $file) {
format_file $file;
} else {
find {
wanted => sub {
return unless /\.l?hs$/;
format_file $_;
}
}, $file;
}
}
2 changes: 2 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: []
resolver: lts-11.7

0 comments on commit 3963104

Please sign in to comment.