Class: Zayin::Rake::HaskellTasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/zayin/rake/haskell.rb

Overview

Defines a set of Rake tasks for working with Haskell/Cabal projects.

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ HaskellTasks

Returns a new instance of HaskellTasks.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
# File 'lib/zayin/rake/haskell.rb', line 9

def initialize
  yield self if block_given?
  define
end

Instance Method Details

#defineObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/zayin/rake/haskell.rb', line 14

def define
  namespace :hs do
    # Cabal-related tasks.
    desc 'Configures the project for development.'
    task :config, [:target] do |t, args|
      target = args[:target] || 'development'
      flags = []
      flags << %w{-f development --enable-tests} if target == 'development'
      sh %{cabal configure #{flags.join(' ')}}
    end

    desc 'Cleans up everything.'
    task :clean do
      sh %{cabal clean}
    end

    desc 'Runs Haddock to generate documentation.'
    task :docs do
      sh %{cabal haddock}
    end

    desc 'Runs tests.'
    task :test => 'hs:build' do
      sh %{cabal test}
    end

    desc 'Builds the Haskell project.'
    task :build, [:args] do |t, args|
      params = []
      params << args[:args] unless args[:args].nil?
      sh %{cabal build}
    end

    desc 'Installs the project locally.'
    task :install do
      sh %{cabal install}
    end

    desc 'Checks the project.'
    task :check do
      sh %{cabal check}
    end

    desc 'Uploads the project to Hackage.'
    task :upload, [:username, :password] do |t, args|
      username = args[:target]
      password = args[:target]
      params = []
      params << "--username=#{username}" unless not username.nil?
      params << "--password=#{password}" unless not password.nil?
      sh %{cabal upload #{params.join(' ')}}
    end

    # Other tools.
    desc 'Generates the tags file.'
    task :tags do
      FileUtils.rm('tags', :verbose => true)
      hs_tags = `find . -name '*.hs' | xargs hothasktags`
      File.open('tags', 'w') { |f| f.write(hs_tags) }
    end

    desc 'Runs hlint.'
    task :lint do
      sh %{hlint src}
    end

    desc 'Strips out the extra comments and fluff from the binary.'
    task :strip, [:target] do |t, args|
      target = args[:target]
      raise 'You must specify a target.' if target.nil?
      sh %{strip -p --strip-unneeded --remove-section=.comment -o #{target} ./dist/build/#{target}/#{target}}
    end

    namespace :hpc do
      desc 'This builds the executable with -fhpc.'
      task :build => ['hs:clean', 'hs:config'] do
        Rake::Task['hs:build'].invoke('--ghc-option=-fhpc')
      end

      desc 'This runs the hpc report.'
      task :report, [:tix, :modules] do |t, args|
        target  = args[:tix]
        modules = args[:modules]
        raise 'TIX file must be supplied.' if target.nil?
        raise 'Modules must be supplied.' if modules.nil?
        sh %{hpc report #{target} #{modules}}
      end

      desc 'This runs hpc markup.'
      task :markup, [:tix, :modules] do |t, args|  
        target  = args[:tix]
        modules = args[:modules]
        raise 'TIX file must be supplied.' if target.nil?
        raise 'Modules must be supplied.' if modules.nil?
        sh %{hpc markup #{target} #{modules}}
      end
    end
  end
end