summaryrefslogtreecommitdiffstats
path: root/travis-deps
blob: 8df9147f692e946499bb5075cfdf825f260ecca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/ruby

class TravisDepsBuilder
  def self.make(name)
    instance = klass.new(name)
    instance.fill_data
    instance.deps
    instance.build
  end

  def self.klass
    Module.const_get([self.name, self.os.capitalize].join)
  rescue NameError
    self
  end

  def self.os
    ENV['TRAVIS_OS_NAME']
  end

  attr_reader :name, :url, :action, :os

  def initialize(name)
    @name, @os = name, self.class.os
  end

  def fill_data
    data = build_map.fetch(name)
    @url, @action = data[:url], data[:action]
  end

  def build
    send(action)
  end

  def deps; end

  private
  def package_manager_update
    # yes class variable, you wanna update only once across all instances
    @@updated ||= false
    return if @@updated
    sh({'linux' => 'sudo apt-get update -y', 'osx' => 'brew update'}[os])
    @@updated = true
  end

  def package_install(*packages)
    cmd = {
      'linux' => 'sudo apt-get install %s -y',
      'osx'   => 'brew install %s'
    }[os] % [packages.join(" ")]

    sh cmd
  end

  def git
    sh "git clone --depth=1 #{url} #{name}"
    compile name
  end

  def stable
    filename = File.basename(url)
    sh "wget #{url}"
    sh "tar -xzvf #{filename}"
    dirname  = File.basename(url, ".tar.gz"  )
    compile dirname
  end

  def package
    package_install(url)
  end

  def compile(dirname)
    sh "cd #{dirname} && #{configure} && make && sudo make install"
    sh "cd $TRAVIS_BUILD_DIR"
  end

  def configure
    "./configure"
  end

  def sh(command)
    `#{command}`
  end
end

class Libav < TravisDepsBuilder
  def build_map
    {
      "libav-stable" => {
        :action => :stable,
        :url    => 'http://libav.org/releases/libav-10.tar.gz'
      },
      "libav-git" => {
        :action => :git,
        :url    => "git://git.libav.org/libav.git"
      },
      "ffmpeg-stable" => {
        :action => :stable,
        :url    => 'http://www.ffmpeg.org/releases/ffmpeg-2.1.4.tar.gz'
      },
      "ffmpeg-git" => {
        :action => :git,
        :url    => "git://github.com/FFmpeg/FFmpeg.git"
      }
    }
  end

  def configure
    [super, "--cc=#{ENV['CC']}"].join(" ")
  end
end

class LibavOsx < Libav
  def build_map
    {
      "ffmpeg-stable" => { :action => :package, :url => 'ffmpeg' },
    }
  end
end

class Libass < TravisDepsBuilder
  def build_map
    {
      "libass-stable" => {
        :action => :stable,
        :url    => 'http://libass.googlecode.com/files/libass-0.10.1.tar.gz'
      }
    }
  end
end

class Dependencies < TravisDepsBuilder
  def deps
    packages = {
      'linux' => 'pkg-config fontconfig libfribidi-dev yasm',
      'osx'   => 'pkg-config fontconfig freetype fribidi yasm'
    }
    package_manager_update
    package_install(packages.fetch(os))
  end
end

Dependencies.new(:deps).deps

Libass.make(ARGV[0])
Libav.make(ARGV[1])