Created
June 10, 2011 06:31
-
-
Save denisdefreyne/1018326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _system(*args) | |
system('echo', *args) | |
system(*args) | |
end | |
class CreateDependenciesFilter < Nanoc3::Filter | |
identifier :create_dependencies | |
type :binary | |
def run(filename, params={}) | |
content = File.read(filename) | |
content.scan(/^#include "([^"]+)"/) do |str| | |
# Find item | |
dependent_item = @items.find { |i| i[:filename] == str[0] } | |
puts "*** #{item.inspect} depends on #{dependent_item.inspect}" | |
# Notify | |
Nanoc3::NotificationCenter.post(:visit_started, dependent_item) | |
Nanoc3::NotificationCenter.post(:visit_ended, dependent_item) | |
# Raise unmet dependency error if item is not yet compiled | |
any_uncompiled_rep = dependent_item.reps.find { |r| !r.compiled? } | |
raise Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep | |
end | |
FileUtils.cp(filename, output_filename) | |
end | |
end | |
class CompileFilter < Nanoc3::Filter | |
identifier :compile | |
type :binary | |
def run(filename, params={}) | |
_system('clang', '-x', 'c', '-c', '-arch', 'i386', '-I.', '-o', output_filename, filename) | |
end | |
end | |
class LinkFilter < Nanoc3::Filter | |
identifier :link | |
type :binary | |
def run(filename, params={}) | |
filenames = *params[:files].map do |dependent_item| | |
# Notify | |
Nanoc3::NotificationCenter.post(:visit_started, dependent_item) | |
Nanoc3::NotificationCenter.post(:visit_ended, dependent_item) | |
# Raise unmet dependency error if item is not yet compiled | |
any_uncompiled_rep = dependent_item.reps.find { |r| !r.compiled? } | |
raise Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep | |
# Done | |
dependent_item.reps[0].raw_path | |
end | |
_system('clang', '-arch', 'i386', '-o', output_filename, *filenames) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment