-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move rbfiles_sorter to lib/; add libtest task
- Loading branch information
Showing
13 changed files
with
61 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'tsort' | ||
|
||
module MRuby | ||
class RbfilesSorter | ||
include TSort | ||
|
||
TAG_RXP = /^#\s*require:\s*['"]([\w\.\/]+)["']\s*$/ | ||
|
||
def initialize(root) | ||
@root = root | ||
@files = Dir.glob("#{root}/**/*.rb").sort | ||
@deps = {} | ||
end | ||
|
||
def sort | ||
@files.each { |f| parse_deps(f) } | ||
tsort | ||
end | ||
|
||
def tsort_each_child(node, &block) | ||
@deps[node].each(&block) | ||
end | ||
|
||
def tsort_each_node(&block) | ||
@deps.each_key(&block) | ||
end | ||
|
||
def parse_deps(file) | ||
f = File.new(file) | ||
|
||
deps_list = @deps[File.expand_path(file)] = [] | ||
|
||
f.each_line do |line| | ||
# Skip blank lines | ||
next if line =~ /^\s*$/ | ||
# All requires should be in the beginning of the file | ||
break if line !~ TAG_RXP | ||
|
||
dep = line.match(TAG_RXP)[1] | ||
|
||
dep += ".rb" unless dep.end_with?(".rb") | ||
|
||
deps_list << File.expand_path(dep, File.dirname(file)) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.