c-dependencies 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +24 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/c-dependencies.gemspec +31 -0
- data/lib/c-dependencies/compiler_invocation.rb +59 -0
- data/lib/c-dependencies/dependency_list.rb +41 -0
- data/lib/c-dependencies/version.rb +3 -0
- data/lib/c-dependencies.rb +29 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4710ae38237a141810ec0bfab78b5a00f7f19f74
|
4
|
+
data.tar.gz: c21b6ab27d7456536c22ff292278dece6e15da53
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c641b8d87f6596e3a48b53bcb9f8e7208aa4fe025cbf22873a7afcd9f50f0e000a5802514f8c2d1c8fee7a51688fb9108f6428a9c96d48d57755e7cd5d864f05
|
7
|
+
data.tar.gz: 8eb08801174891763d9705852888429a9cab76de56e279ca44bab9c26b1b239bff89a7eb4a25fe6fbfa1b8ddf988b79e6bf05bd1c33fa8236e2d916de9bb6279
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
c-dependencies (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.4.3)
|
10
|
+
rake (10.4.2)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.10)
|
17
|
+
c-dependencies!
|
18
|
+
minitest
|
19
|
+
rake (~> 10.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.10.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# CDependencies
|
2
|
+
|
3
|
+
Simple gem to help discover and work with C/C++/ASM file dependencies.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'c-dependencies'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install c-dependencies
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
24
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "c-dependencies"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'c-dependencies/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'c-dependencies'
|
8
|
+
spec.version = CDependencies::VERSION
|
9
|
+
spec.authors = ['Matt Massicotte']
|
10
|
+
|
11
|
+
spec.summary = 'Manage C/C++ file dependencies with Ruby'
|
12
|
+
spec.homepage = 'https://github.com/mattmassicotte/c-dependencies'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "minitest"
|
31
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module CDependencies
|
2
|
+
class FileUnsupportedError < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class CompilerInvocation
|
6
|
+
attr_accessor :tool_name
|
7
|
+
attr_accessor :flags
|
8
|
+
attr_accessor :input_path
|
9
|
+
attr_accessor :output_file
|
10
|
+
attr_accessor :output_path
|
11
|
+
|
12
|
+
EXTENSION_MAP = { '.c' => 'cc',
|
13
|
+
'.cc'=> 'c++',
|
14
|
+
'.cpp' => 'c++',
|
15
|
+
'.hpp' => 'c++',
|
16
|
+
'.S' => 'gas',
|
17
|
+
'.asm' => 'nasm' }
|
18
|
+
|
19
|
+
def initialize(path, compiler_flags=nil)
|
20
|
+
self.input_path = path
|
21
|
+
self.flags = compiler_flags
|
22
|
+
|
23
|
+
if tool_name.nil?
|
24
|
+
raise FileUnsupportedError.new("Unsure how to compile a file with extension '#{input_extension}'")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def input_extension
|
29
|
+
File.extname(input_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def tool_name
|
33
|
+
EXTENSION_MAP[input_extension]
|
34
|
+
end
|
35
|
+
|
36
|
+
def dependency_cmd
|
37
|
+
"#{tool_cmd} #{dependency_flag} '#{input_path}'"
|
38
|
+
end
|
39
|
+
|
40
|
+
def has_flags?
|
41
|
+
!flags.nil? && flags != ''
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def tool_cmd
|
46
|
+
has_flags? ? "#{tool_name} #{flags}" : tool_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def dependency_flag
|
50
|
+
case tool_name
|
51
|
+
when 'cc', 'c++'
|
52
|
+
# -MM suppresses system header dependencies
|
53
|
+
'-MM'
|
54
|
+
when 'nasm'
|
55
|
+
'-M'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module CDependencies
|
4
|
+
class DependencyList
|
5
|
+
attr_reader :paths
|
6
|
+
|
7
|
+
def initialize(array)
|
8
|
+
@paths = array.map { |x| File.absolute_path(x) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def write_to_file(path)
|
12
|
+
File.open(path, 'w+') do |file|
|
13
|
+
file << serializable_entries.join("\n")
|
14
|
+
file << "\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.read_from_file(path)
|
19
|
+
list = File.readlines(path)
|
20
|
+
list.map! { |x| x.chomp() }
|
21
|
+
|
22
|
+
# make a non-empty list of files that also exist
|
23
|
+
list.reject! { |x| x.empty? || !File.exist?(x) }
|
24
|
+
|
25
|
+
DependencyList.new(list)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def serializable_dependency_entry(entry)
|
30
|
+
entry
|
31
|
+
end
|
32
|
+
|
33
|
+
def serializable_entries
|
34
|
+
paths.map { |x| serializable_dependency_entry(x) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def file_hash(path)
|
38
|
+
Digest::SHA1.file(path).hexdigest
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "c-dependencies/version"
|
2
|
+
require 'c-dependencies/compiler_invocation'
|
3
|
+
require 'c-dependencies/dependency_list'
|
4
|
+
|
5
|
+
module CDependencies
|
6
|
+
def self.for_source_file(path, flags=nil)
|
7
|
+
invocation = CompilerInvocation.new(path, flags)
|
8
|
+
|
9
|
+
cmd = invocation.dependency_cmd
|
10
|
+
|
11
|
+
# consult rake's verbose function, if defined
|
12
|
+
if defined? verbose
|
13
|
+
puts(cmd) if verbose()
|
14
|
+
end
|
15
|
+
|
16
|
+
output = `#{cmd}`.chomp()
|
17
|
+
list = output.split()
|
18
|
+
raise("unexpected dependency output for '#{path}'") if list.size < 2
|
19
|
+
|
20
|
+
# remove blanks and line continuations, which can come up as a side-effect
|
21
|
+
# of the split
|
22
|
+
list.reject! { |x| x.empty? || x == '\\' }
|
23
|
+
|
24
|
+
# first element is the object file, second is the source itself
|
25
|
+
list = list[2..-1]
|
26
|
+
|
27
|
+
DependencyList.new(list)
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: c-dependencies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Massicotte
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-15 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- CODE_OF_CONDUCT.md
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- c-dependencies.gemspec
|
71
|
+
- lib/c-dependencies.rb
|
72
|
+
- lib/c-dependencies/compiler_invocation.rb
|
73
|
+
- lib/c-dependencies/dependency_list.rb
|
74
|
+
- lib/c-dependencies/version.rb
|
75
|
+
homepage: https://github.com/mattmassicotte/c-dependencies
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata:
|
79
|
+
allowed_push_host: https://rubygems.org
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Manage C/C++ file dependencies with Ruby
|
100
|
+
test_files: []
|