jdepp 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96527f280981167b06226e29d5d4ad28184bfa0a
4
+ data.tar.gz: acc1201002bfab7b5d7ba31a815168a91dd2992d
5
+ SHA512:
6
+ metadata.gz: c24fcfaa1a0f5d15aca5e9704746ba94526c395e4e57cf3e98c85b69af464b6b47b927e639a188e5d0072577a0a64f41d99ff526e607c9ad9a1427b64305a40f
7
+ data.tar.gz: 80f0a310b9418d9fe1256dbc6ed6102e0be0eddc1436bfef46e6332f32dca703abd461c9c37b3bc692897ee459730eff4d13d3aeeb24100f269e7c5e288160ce
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.swp
2
+ /bin/
3
+ /_vendor/
4
+
5
+ # provided by bundler
6
+ /.bundle/
7
+ /.yardoc
8
+ /Gemfile.lock
9
+ /_yardoc/
10
+ /coverage/
11
+ /doc/
12
+ /pkg/
13
+ /spec/reports/
14
+ /tmp/
15
+ *.bundle
16
+ *.so
17
+ *.o
18
+ *.a
19
+ mkmf.log
20
+ # -----
21
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jdepp.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 michael lowell roberts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # the jaunty dependency preprocessor
2
+
3
+ this is a small utility that scans source files for dependency declarations. currently, it only supports [f*](http://fstar-lang.org).
4
+
5
+ ## installation
6
+
7
+ add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "jdepp", :git => "https://github.com/fmrl/jdepp.git"
11
+ ```
12
+
13
+ and then execute:
14
+
15
+ $ bundle
16
+
17
+ <!--
18
+ or install it yourself as:
19
+
20
+ $ gem install jdepp
21
+ -->
22
+
23
+ ## usage
24
+
25
+ documentation doesn't really exist yet but you can type `bundle exec jdepp` to see what documentation exists.
26
+
27
+ ## contributing
28
+
29
+ 1. fork it ( https://github.com/fmrl/jdepp/fork )
30
+ 2. create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. push to the branch (`git push origin my-new-feature`)
33
+ 5. create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/jdepp.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jdepp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jdepp"
8
+ spec.version = Jdepp::VERSION
9
+ spec.authors = ["michael lowell roberts"]
10
+ spec.email = ["mlr@fmrl.org"]
11
+ spec.summary = %q{a language-independent scanner for build utilities.}
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = "https://github.com/fmrl/jdepp.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,95 @@
1
+ require "pp"
2
+ require "set"
3
+
4
+ module Jdepp
5
+ module CLI
6
+
7
+ class Feedback
8
+ attr_reader :enabled_tags
9
+ attr_reader :output
10
+
11
+ def initialize(enabled_tags=[], output=$stderr)
12
+ @enabled_tags = Set.new([:error]) | enabled_tags
13
+ @output = output
14
+ end
15
+
16
+ def add_tag(tag)
17
+ @enabled_tags.add(tag)
18
+ end
19
+
20
+ def delete_tag(tag)
21
+ @enabled_tags.delete(tag)
22
+ end
23
+
24
+ def dry_run?
25
+ @enabled_tags.member?(:dry_run)
26
+ end
27
+
28
+ def dry_run
29
+ add_tag(:dry_run)
30
+ end
31
+
32
+ def verbose?
33
+ @enabled_tags.member?(:verbose)
34
+ end
35
+
36
+ def verbose
37
+ add_tag(:verbose)
38
+ end
39
+
40
+ def action?
41
+ @enabled_tags.member?(:action)
42
+ end
43
+
44
+ def action
45
+ add_tag(:action)
46
+ end
47
+
48
+ def quiet
49
+ preserve_dry = dry_run
50
+ @enabled_tags = Set.new([:error])
51
+ if preserve_dry then
52
+ dry_run
53
+ end
54
+ end
55
+
56
+ def puts_if(relevant_tags, &msg)
57
+ if relevant_tags.is_a?(Array) then
58
+ relevant_tags = Set.new(relevant_tags)
59
+ elsif not relevant_tags.is_a?(Set) then
60
+ relevant_tags = Set.new([relevant_tags])
61
+ end
62
+ tags = relevant_tags.intersection(@enabled_tags)
63
+ if tags.length > 0 then
64
+ @output.puts("#{prefix tags}#{msg.call()}")
65
+ end
66
+ nil
67
+ end
68
+
69
+ def system(cmds)
70
+ puts_if([:dry_run, :verbose, :action]) { cmds }
71
+ if not self.dry_run? then
72
+ Kernel::system(cmds)
73
+ else
74
+ nil
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def prefix(relevant_tags)
81
+ if relevant_tags.empty? then
82
+ raise "i cannot create a feedback from an empty tag set."
83
+ end
84
+ tags = (relevant_tags.map {|tag| tag.to_s}).sort
85
+ # todo: refactor to reduce
86
+ result = ""
87
+ tags[0..-2].each {|s| result += "#{s}, "}
88
+ result += "#{tags[-1]}: "
89
+ result
90
+ end
91
+
92
+ end
93
+ end
94
+ end
95
+
data/lib/jdepp/cli.rb ADDED
@@ -0,0 +1,112 @@
1
+ require "jdepp/cli/feedback"
2
+ require "jdepp/parser"
3
+
4
+ require "optparse"
5
+ require 'rbconfig'
6
+
7
+ module Jdepp::CLI
8
+
9
+ def self.cli(argv)
10
+
11
+ opts = {:feedback => Feedback.new([:action]), :locations => {}}
12
+
13
+ end_of_options = argv.index("--")
14
+ opts[:stdout] = end_of_options.nil?
15
+ if not opts[:stdout] then
16
+ if argv.length > 0 then
17
+ opts[:recipient] = argv[end_of_options + 1..-1].join(" ")
18
+ end
19
+ argv = ARGV.first(end_of_options)
20
+ end
21
+
22
+ OptionParser.new do
23
+ |o|
24
+ o.banner = "usage: jdepp.rb [options] FILE [FILE ...] [-- COMMAND]"
25
+ o.on("-v", "--[no-]verbose", "i will provide extra detail about my activity.") do
26
+ |v|
27
+ if (v) then
28
+ opts[:feedback].add_tag(:verbose)
29
+ end
30
+ end
31
+ o.on("-n", "--[no-]dry-run", "i will report what i would do if i were to perform the specified work.") do
32
+ |flag|
33
+ if (flag) then
34
+ opts[:feedback].add_tag(:dry_run)
35
+ end
36
+ end
37
+ o.on("-q", "--quiet", "i will suppress as much commentary as possible.") do
38
+ |flag|
39
+ if (flag) then
40
+ opts[:feedback].quiet
41
+ end
42
+ end
43
+ o.on("-D", "--define=LOCATION", 'if provided with a specification of the form "PREFIX=PATH", i will substitute PREFIX: for PATH if encountered.') do
44
+ |s|
45
+ name, path = s.split("=", 2)
46
+ opts[:locations][name] = Pathname.new(path)
47
+ end
48
+ o.on("-F","--feedback-tags=TAGS", "i will provide feedback related to the specified tags") do
49
+ |tag_list|
50
+ tags = tag_list.split(",")
51
+ tags.each {|t| opts[:feedback].add_tag(t.to_sym)}
52
+ end
53
+ o.on("-a","--[no-]append-dependents", "i will append the dependents to the list of dependencies") do
54
+ |flag|
55
+ opts[:append_dependents] = flag
56
+ end
57
+ o.on("--[no-]trace", "i will show the ruby callstack should an exception occur.") do
58
+ |flag|
59
+ opts[:trace] = flag
60
+ end
61
+ end.parse!(argv)
62
+
63
+ if opts.fetch(:trace, false) then
64
+ parse(argv, opts)
65
+ else
66
+ begin
67
+ parse(argv, opts)
68
+ rescue Exception => e
69
+ opts[:feedback].puts_if([:error]) {e.message}
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ private
76
+
77
+ def self.parse(argv, opts)
78
+ is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
79
+
80
+ parser = Jdepp::Parser.new(opts[:locations], opts[:feedback])
81
+ result = parser.parse(argv)
82
+ if opts.fetch(:append_dependents, false) then
83
+ result.concat(argv)
84
+ end
85
+
86
+ if opts[:stdout] then
87
+ if result.length == 0 then
88
+ $stderr.puts "i have an empty result-- is this what you intended?\n"
89
+ else
90
+ puts result
91
+ end
92
+ elsif not opts.fetch(:recipient, nil).nil? then
93
+ # todo: thread the exit status through
94
+ if is_windows then
95
+ result.map! {|s| if s.include? ' ' then '"%s"' % s else s end}
96
+ end
97
+ opts[:feedback].system "#{opts[:recipient]} #{result.join(' ')}"
98
+ else
99
+ $stderr.puts "i have nothing to do!"
100
+ end
101
+ end
102
+
103
+ end
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
@@ -0,0 +1,60 @@
1
+ require "pathname"
2
+ require "pp"
3
+ require "set"
4
+
5
+ module Jdepp
6
+
7
+ class Parser
8
+
9
+ def initialize(locations={}, feedback=Feedback.new)
10
+ @locations = locations
11
+ @feedback = feedback
12
+ end
13
+
14
+ def parse(file_list)
15
+
16
+ def recurse(accum, path)
17
+ re = /^\/\/\s*@requires\s*"(([^"\n:]+):)?([^"\n]+)"\s*$/
18
+ lines = File.readlines(path.to_s)
19
+ lines.reduce(accum) do
20
+ |a, ln|
21
+ matches = re.match(ln)
22
+ if matches != nil then
23
+ if matches[1].nil? then
24
+ rel = Pathname.new(path.dirname + matches[3])
25
+ else
26
+ loc_alias = matches[2]
27
+ if @locations.key?(loc_alias) then
28
+ rel = @locations[loc_alias].join(matches[3])
29
+ else
30
+ # todo: convert path to relative path.
31
+ raise "i don't recognize the location alias \"#{loc_alias}\" encountered in <#{path}>."
32
+ end
33
+ end
34
+ if not rel.exist? then
35
+ raise "i can't find #{rel.to_s} (required by #{path})."
36
+ end
37
+ abs = rel.realdirpath
38
+ if not a.key?(abs) then
39
+ @feedback.puts_if(:verbose) {"i matched #{rel} (#{abs})"}
40
+ recurse(a, rel)
41
+ a[abs] = rel
42
+ else
43
+ @feedback.puts_if(:verbose) {"i am ignoring a duplicate directive for #{rel} (#{abs})"}
44
+ end
45
+ end
46
+ a
47
+ end
48
+ end
49
+
50
+ # todo: default to returning relative paths; absolute on request.
51
+ (file_list.reduce({}) do
52
+ |accum, s|
53
+ recurse(accum, Pathname.new(s))
54
+ accum
55
+ end).values.map {|p| p.to_s}
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,3 @@
1
+ module Jdepp
2
+ VERSION = "0.2.1"
3
+ end
data/lib/jdepp.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "jdepp/version"
2
+ require "jdepp/cli"
3
+
4
+ module Jdepp
5
+ # Your code goes here...
6
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jdepp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - michael lowell roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - mlr@fmrl.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - jdepp.gemspec
54
+ - lib/jdepp.rb
55
+ - lib/jdepp/cli.rb
56
+ - lib/jdepp/cli/feedback.rb
57
+ - lib/jdepp/parser.rb
58
+ - lib/jdepp/version.rb
59
+ homepage: https://github.com/fmrl/jdepp.git
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: a language-independent scanner for build utilities.
83
+ test_files: []