File: tags.rake

package info (click to toggle)
ruby-builder 3.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 368 kB
  • sloc: ruby: 1,945; makefile: 4
file content (62 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

module Tags
  extend Rake::DSL if defined?(Rake::DSL)

  PROG = ENV['TAGS'] || 'ctags'

  RAKEFILES = FileList['Rakefile', '**/*.rake']

  FILES = FileList['**/*.rb', '**/*.js'] + RAKEFILES
  FILES.exclude('pkg', 'dist')

  PROJECT_DIR = ['.']

  RVM_GEMDIR = File.join(`rvm gemdir`.strip, "gems") rescue nil
  SYSTEM_DIRS = RVM_GEMDIR && File.exists?(RVM_GEMDIR) ? RVM_GEMDIR : []

  module_function

  # Convert key_word to --key-word.
  def keyword(key)
    k = key.to_s.gsub(/_/, '-')
    (k.length == 1) ? "-#{k}" : "--#{k}"
  end

  # Run ctags command
  def run(*args)
    opts = {
      :e => true,
      :totals => true,
      :recurse => true,
    }
    opts = opts.merge(args.pop) if args.last.is_a?(Hash)
    command_args = opts.map { |k, v|
      (v == true) ? keyword(k) : "#{keyword(k)}=#{v}"
    }.join(" ")
    sh %{#{Tags::PROG} #{command_args} #{args.join(' ')}}
  end
end

namespace "tags" do
  desc "Generate an Emacs TAGS file"
   task :emacs, [:all] => Tags::FILES do |t, args|
    puts "Making Emacs TAGS file"
    verbose(true) do
      Tags.run(Tags::PROJECT_DIR)
      Tags.run(Tags::RAKEFILES,
        :language_force => "ruby",
        :append => true)
      if args.all
        Tags::SYSTEM_DIRS.each do |dir|
          Tags.run(dir,
            :language_force => "ruby",
            :append => true)
        end
      end
    end
  end
end

desc "Generate the TAGS file"
task :tags, [:all] => ["tags:emacs"]