neutron 0.0.0 → 0.1.0
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 +4 -4
- data/.gitignore +1 -2
- data/README.md +59 -6
- data/Rakefile +2 -2
- data/bin/console +5 -3
- data/lib/neutron.rb +106 -3
- data/lib/neutron/cc.rb +34 -0
- data/lib/neutron/pkgconf.rb +50 -0
- data/lib/neutron/valac.rb +14 -0
- data/lib/neutron/version.rb +1 -1
- data/neutron.gemspec +7 -6
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fcb3a8b875da195e8ce7c6e2b90c23f063d97e4
|
4
|
+
data.tar.gz: b0783ecb19dfd497cfdb196b58b88070e16e546f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 132fce6e5d3e697d417e938a7713ae7d0c8c1172341f96f420b9ca990fef3acd45c79e9782bead94f371b575ce6d22ab86b9b2cdeadcf79bea34569f757a2be1
|
7
|
+
data.tar.gz: 47d7b251754520c2e8d0f4e885b471618e72f432d50dade0b1d6269c4409a091861918a78f5c73c9069e2849e8d9a22eb7fb6ea1b3e14784424bf6ac0dd8ff3c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Neutron
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/neutron`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
@@ -22,7 +18,64 @@ Or install it yourself as:
|
|
22
18
|
|
23
19
|
## Usage
|
24
20
|
|
25
|
-
|
21
|
+
Rake & Neutron sample, which compiles Vala program:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# File structure:
|
25
|
+
# ./Rakefile
|
26
|
+
# src/main.vala
|
27
|
+
# src/gui.vala
|
28
|
+
# src/http.vala
|
29
|
+
# Required packages:
|
30
|
+
# glib-2.0
|
31
|
+
# gtk+-3.0
|
32
|
+
# libsoup-2.4
|
33
|
+
# Target file:
|
34
|
+
# ./sample
|
35
|
+
|
36
|
+
require 'neutron'
|
37
|
+
require 'neutron/pkgconf'
|
38
|
+
require 'neutron/cc'
|
39
|
+
require 'neutron/valac'
|
40
|
+
|
41
|
+
Dir.chdir('src/') # We'll compile our stuff here
|
42
|
+
|
43
|
+
# Neutron::PkgConf checks package availability for us
|
44
|
+
packages = Neutron::PkgConf.new %w[
|
45
|
+
glib-2.0
|
46
|
+
gtk+-3.0
|
47
|
+
libsoup-2.4
|
48
|
+
]
|
49
|
+
|
50
|
+
task :default => :build
|
51
|
+
task :build => %w[valac link]
|
52
|
+
|
53
|
+
# Compile our sources. Will not compile already compiled
|
54
|
+
# files because Neutron.files() excludes them
|
55
|
+
task :valac do
|
56
|
+
Neutron::Valac.compile(
|
57
|
+
*Neutron.files(Neutron::FileList['*.vala'], '.vala.o').sources, # Sources
|
58
|
+
args: packages.to_valac # Provide list of packages to valac
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Link .o files and libraries
|
63
|
+
task :link do
|
64
|
+
# Neutron:CC provides methods for using C and C++ compilers
|
65
|
+
Neutron::CC.link(
|
66
|
+
*Neutron::FileList['*.vala.o'], # Object files
|
67
|
+
'../sample', # Target file
|
68
|
+
args: packages.to_cc(cflags: false) # Package list
|
69
|
+
)
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
## ToDo
|
74
|
+
|
75
|
+
1. Gem-like version-checker
|
76
|
+
2. Shared-Object builder
|
77
|
+
3. `install` tool (must install headers, binaries, shared objects)
|
78
|
+
4. Finders for Boost, SFML, Qt, etc
|
26
79
|
|
27
80
|
## Development
|
28
81
|
|
@@ -32,7 +85,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
85
|
|
33
86
|
## Contributing
|
34
87
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/handicraftsman/neutron. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
89
|
|
37
90
|
|
38
91
|
## License
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
task :
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
task default: :spec
|
data/bin/console
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'neutron'
|
5
|
+
require 'neutron/pkgconf'
|
6
|
+
require 'neutron/cc'
|
5
7
|
|
6
8
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
9
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +12,5 @@ require "neutron"
|
|
10
12
|
# require "pry"
|
11
13
|
# Pry.start
|
12
14
|
|
13
|
-
require
|
15
|
+
require 'irb'
|
14
16
|
IRB.start
|
data/lib/neutron.rb
CHANGED
@@ -1,5 +1,108 @@
|
|
1
|
-
require
|
1
|
+
require 'json'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
require 'neutron/version'
|
2
5
|
|
3
6
|
module Neutron
|
4
|
-
|
5
|
-
|
7
|
+
class ExecutionError < StandardError; end
|
8
|
+
|
9
|
+
class FileList < Array
|
10
|
+
def self.[](filter)
|
11
|
+
arr = Dir[filter]
|
12
|
+
arr = arr.keep_if do |f|
|
13
|
+
File.file? f
|
14
|
+
end
|
15
|
+
self.new(arr)
|
16
|
+
end
|
17
|
+
|
18
|
+
def ext(ext)
|
19
|
+
self.map do |f|
|
20
|
+
m = /(.+)\..+/.match(f)
|
21
|
+
if m
|
22
|
+
m[1] + ext
|
23
|
+
else
|
24
|
+
f + ext
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class FilePairList < Array
|
31
|
+
def sources
|
32
|
+
self.map do |i|
|
33
|
+
i.source
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def targets
|
37
|
+
self.map do |i|
|
38
|
+
i.target
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.files(sources, t_ext)
|
44
|
+
targets = sources.ext(t_ext)
|
45
|
+
pairs = sources.zip(targets)
|
46
|
+
pairs = pairs.keep_if do |item|
|
47
|
+
source = item[0]
|
48
|
+
target = item[1]
|
49
|
+
if File.exist? target
|
50
|
+
st = File.stat(File.expand_path(source)).mtime
|
51
|
+
tt = File.stat(File.expand_path(target)).mtime
|
52
|
+
if st > tt
|
53
|
+
true
|
54
|
+
else
|
55
|
+
false
|
56
|
+
end
|
57
|
+
else
|
58
|
+
true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
pairs.map!{|item| Neutron::FilePair.new(item[0], item[1])}
|
62
|
+
Neutron::FilePairList.new(pairs)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.execute(string, **opts)
|
66
|
+
puts "> #{string}"
|
67
|
+
stdin, stdout, waiter = *Open3.popen2e(string)
|
68
|
+
out = ''
|
69
|
+
while s = stdout.getc
|
70
|
+
print s
|
71
|
+
out << s
|
72
|
+
end
|
73
|
+
stdin.close
|
74
|
+
stdout.close
|
75
|
+
if opts[:must_success] and waiter.value.exitstatus != 0
|
76
|
+
raise Neutron::ExecutionError, "Exitcode #{waiter.value.exitstatus} returned!"
|
77
|
+
end
|
78
|
+
return [out, waiter.value.exitstatus]
|
79
|
+
end
|
80
|
+
|
81
|
+
class FilePair
|
82
|
+
attr_reader :source, :target
|
83
|
+
def initialize(source, target)
|
84
|
+
@target = target
|
85
|
+
@source = source
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
module PkgStatus
|
90
|
+
class PkgNotFoundError < StandardError; end
|
91
|
+
|
92
|
+
FNAME = './.neutron_pkgs'.freeze
|
93
|
+
|
94
|
+
def self.get_checked
|
95
|
+
if File.exist?(FNAME)
|
96
|
+
JSON.load(File.read(FNAME))
|
97
|
+
else
|
98
|
+
[]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.add_found(found)
|
103
|
+
checked = get_checked
|
104
|
+
File.delete(FNAME) if File.exist?(FNAME)
|
105
|
+
File.write(FNAME, JSON.pretty_generate(found+checked))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/neutron/cc.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'neutron'
|
2
|
+
|
3
|
+
module Neutron::CC
|
4
|
+
def self.link(*files, target, **opts)
|
5
|
+
o = {
|
6
|
+
prog: 'cc',
|
7
|
+
debug: false,
|
8
|
+
args: ''
|
9
|
+
}.merge(opts)
|
10
|
+
Neutron.execute("#{o[:prog]} -o #{target} #{files.join(' ')} #{'-g' if o[:debug]} #{o[:args]}", must_success: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.cc(*files, **opts)
|
14
|
+
o = {
|
15
|
+
prog: 'cc',
|
16
|
+
debug: false,
|
17
|
+
args: ''
|
18
|
+
}.merge(opts)
|
19
|
+
files.each do |file|
|
20
|
+
Neutron.execute("#{o[:prog]} -c #{file} #{'-g' if o[:debug]} #{o[:args]}", must_success: true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.cpp(*files, **opts)
|
25
|
+
o = {
|
26
|
+
prog: 'c++',
|
27
|
+
debug: false,
|
28
|
+
args: ''
|
29
|
+
}.merge(opts)
|
30
|
+
files.each do |file|
|
31
|
+
Neutron.execute("#{o[:prog]} -c #{file} #{'-g' if o[:debug]} #{o[:args]}", must_success: true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'neutron'
|
2
|
+
|
3
|
+
class Neutron::PkgConf
|
4
|
+
class InvalidPkgConfError < StandardError; end
|
5
|
+
|
6
|
+
attr_reader :packages
|
7
|
+
|
8
|
+
def initialize(packages)
|
9
|
+
@packages = packages
|
10
|
+
@packages.freeze
|
11
|
+
found = []
|
12
|
+
checked = Neutron::PkgStatus.get_checked
|
13
|
+
begin
|
14
|
+
(packages-checked).each do |package|
|
15
|
+
_, code = *Neutron.execute("pkg-config --exists #{package}")
|
16
|
+
if code == 0
|
17
|
+
found << package
|
18
|
+
else
|
19
|
+
raise Neutron::PkgStatus::PkgNotFoundError, "Cannot find #{package}!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
rescue Neutron::PkgStatus::PkgNotFoundError
|
23
|
+
self.taint
|
24
|
+
raise
|
25
|
+
ensure
|
26
|
+
Neutron::PkgStatus.add_found(found)
|
27
|
+
end
|
28
|
+
freeze
|
29
|
+
end
|
30
|
+
|
31
|
+
def +(target)
|
32
|
+
raise InvalidPkgConfError, 'Current pkg-conf is invalid!' if tainted?
|
33
|
+
raise InvalidPkgConfError, 'Target pkg-conf is invalid!' if target.tainted?
|
34
|
+
Neutron::PkgConf.new((@packages+target.packages).uniq)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_cc(**opts)
|
38
|
+
raise InvalidPkgConfError if tainted?
|
39
|
+
o = {
|
40
|
+
libs: true,
|
41
|
+
cflags: true
|
42
|
+
}.merge(opts)
|
43
|
+
Neutron.execute("pkg-config #{"--libs" if o[:libs]} #{"--cflags" if o[:cflags]} #{@packages.join(' ')}")[0].strip
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_valac
|
47
|
+
raise InvalidPkgConfError if tainted?
|
48
|
+
@packages.map{|p|"--pkg #{p}"}.join(' ')
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'neutron'
|
2
|
+
|
3
|
+
class Neutron::Valac
|
4
|
+
def self.compile(*files, **opts)
|
5
|
+
o = {
|
6
|
+
prog: 'valac',
|
7
|
+
debug: false,
|
8
|
+
args: ''
|
9
|
+
}.merge(opts)
|
10
|
+
files.each do |file|
|
11
|
+
Neutron.execute("#{o[:prog]} -c #{file} #{'-X g' if o[:debug]} #{o[:args]}", must_success: true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/neutron/version.rb
CHANGED
data/neutron.gemspec
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'neutron/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'neutron'
|
8
9
|
spec.version = Neutron::VERSION
|
9
10
|
spec.authors = ['Nickolay Ilyushin']
|
10
11
|
spec.email = ['nickolay02@inbox.ru']
|
11
12
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = '
|
14
|
-
spec.homepage = ''
|
13
|
+
spec.summary = 'Build-Tool toolkit for Ruby'
|
14
|
+
spec.description = 'Build-Tool toolkit for Ruby'
|
15
|
+
spec.homepage = 'https://github.com/handicraftsman/neutron'
|
15
16
|
spec.license = 'MIT'
|
16
|
-
|
17
|
-
spec.files
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
19
|
f.match(%r{^(test|spec|features)/})
|
19
20
|
end
|
20
21
|
spec.bindir = 'exe'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neutron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nickolay Ilyushin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description:
|
41
|
+
description: Build-Tool toolkit for Ruby
|
42
42
|
email:
|
43
43
|
- nickolay02@inbox.ru
|
44
44
|
executables: []
|
@@ -54,9 +54,12 @@ files:
|
|
54
54
|
- bin/console
|
55
55
|
- bin/setup
|
56
56
|
- lib/neutron.rb
|
57
|
+
- lib/neutron/cc.rb
|
58
|
+
- lib/neutron/pkgconf.rb
|
59
|
+
- lib/neutron/valac.rb
|
57
60
|
- lib/neutron/version.rb
|
58
61
|
- neutron.gemspec
|
59
|
-
homepage:
|
62
|
+
homepage: https://github.com/handicraftsman/neutron
|
60
63
|
licenses:
|
61
64
|
- MIT
|
62
65
|
metadata: {}
|
@@ -79,5 +82,5 @@ rubyforge_project:
|
|
79
82
|
rubygems_version: 2.6.8
|
80
83
|
signing_key:
|
81
84
|
specification_version: 4
|
82
|
-
summary:
|
85
|
+
summary: Build-Tool toolkit for Ruby
|
83
86
|
test_files: []
|