|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +#-- |
| 4 | +# Copyright (c) 2018 Shreyas Balakrishna |
| 5 | + |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files (the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions: |
| 12 | + |
| 13 | +# The above copyright notice and this permission notice shall be included in all |
| 14 | +# copies or substantial portions of the Software. |
| 15 | + |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +# SOFTWARE. |
| 23 | +#++ |
| 24 | + |
| 25 | +require 'optparse' |
| 26 | +require 'cpp_dependency_graph' |
| 27 | + |
| 28 | +include CppDependencyGraph |
| 29 | + |
| 30 | +options = {} |
| 31 | +optparse = OptionParser.new do |opts| |
| 32 | + opts.banner = 'Usage: cpp_dependency_graph [options]' |
| 33 | + |
| 34 | + opts.on('-r dir', '--root dir', 'top level root directory of C/C++ project') do |dir| |
| 35 | + options[:root_dir] = dir.gsub(/\\+/, '/') |
| 36 | + end |
| 37 | + |
| 38 | + opts.on('-o file', '--output file', 'output dot file to be generated') do |file| |
| 39 | + options[:output_file] = file |
| 40 | + end |
| 41 | + |
| 42 | + opts.on('-h', '--help', 'Prints this help') do |
| 43 | + puts opts |
| 44 | + exit |
| 45 | + end |
| 46 | +end |
| 47 | + |
| 48 | +begin |
| 49 | + optparse.parse! |
| 50 | + mandatory = [:root_dir, :output_file] |
| 51 | + missing = mandatory.select { |param| options[param].nil? } |
| 52 | + raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty? |
| 53 | +rescue OptionParser::InvalidOption, OptionParser::MissingArgument |
| 54 | + puts $ERROR_INFO.to_s |
| 55 | + puts optparse |
| 56 | + exit |
| 57 | +end |
| 58 | + |
| 59 | +unless File.directory?(options[:root_dir]) |
| 60 | + puts('Not a valid source directory') |
| 61 | + sys.exit(-1) |
| 62 | +end |
| 63 | + |
| 64 | +generate(options[:root_dir], options[:output_file]) |
0 commit comments