neutron 0.1.0 → 0.2.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/README.md +22 -4
- data/lib/neutron/cc.rb +15 -2
- data/lib/neutron/clean.rb +18 -0
- data/lib/neutron/install.rb +28 -0
- data/lib/neutron/pkgconf.rb +35 -0
- data/lib/neutron/static_lib.rb +10 -0
- data/lib/neutron/valac.rb +54 -3
- data/lib/neutron/version.rb +1 -1
- data/lib/neutron.rb +64 -6
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed6e7b52ccba90b2d31c4dcbd54897c0ad0257c4
|
4
|
+
data.tar.gz: 201733d607545352f5c569df22bc8641d5cd0ae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b096c82be55a889e2c5669d986610b847140ba34cd635f33c2cdcbd1a4f3d5227b18e3f0eb07e49d202ac5785d30da042a16eccec82ca0bbd5aa6e6075bbd64
|
7
|
+
data.tar.gz: d677ab4e1ca425852ede20f55401d2ae757c1397eae292867476ffe2497a15fea8f44df3873ff9d2edcbdf74237ddf3baaf642a40414a3f74b103d9661db9276
|
data/README.md
CHANGED
@@ -37,6 +37,8 @@ require 'neutron'
|
|
37
37
|
require 'neutron/pkgconf'
|
38
38
|
require 'neutron/cc'
|
39
39
|
require 'neutron/valac'
|
40
|
+
require 'neutron/install'
|
41
|
+
require 'neutron/clean'
|
40
42
|
|
41
43
|
Dir.chdir('src/') # We'll compile our stuff here
|
42
44
|
|
@@ -68,14 +70,30 @@ task :link do
|
|
68
70
|
args: packages.to_cc(cflags: false) # Package list
|
69
71
|
)
|
70
72
|
end
|
73
|
+
|
74
|
+
task :install do
|
75
|
+
# Installs results to #{prefix}/bin/. Uses ENV['PREFIX'] or '/usr/' as prefix
|
76
|
+
Neutron.install(
|
77
|
+
'../sample',
|
78
|
+
'bin/'
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
task :clean do
|
83
|
+
# Removes all listed files
|
84
|
+
Neutron.clean(
|
85
|
+
*Neutron::FileList['*.vala.o'],
|
86
|
+
'../sample'
|
87
|
+
)
|
88
|
+
end
|
71
89
|
```
|
72
90
|
|
73
91
|
## ToDo
|
74
92
|
|
75
|
-
1.
|
76
|
-
2.
|
77
|
-
3.
|
78
|
-
4. Finders for Boost, SFML, Qt, etc
|
93
|
+
1. Docs
|
94
|
+
2. Gem-like version-checker
|
95
|
+
3. Finish Neutron::Valac module
|
96
|
+
4. Finders for Boost, SFML, Qt, etc (should be implemented in separate gem)
|
79
97
|
|
80
98
|
## Development
|
81
99
|
|
data/lib/neutron/cc.rb
CHANGED
@@ -5,9 +5,20 @@ module Neutron::CC
|
|
5
5
|
o = {
|
6
6
|
prog: 'cc',
|
7
7
|
debug: false,
|
8
|
-
args: ''
|
8
|
+
args: '',
|
9
|
+
shared: false
|
9
10
|
}.merge(opts)
|
10
|
-
|
11
|
+
specific = ''
|
12
|
+
if o[:shared]
|
13
|
+
specific << ' -shared'
|
14
|
+
end
|
15
|
+
files.map! do |file|
|
16
|
+
File.expand_path(file)
|
17
|
+
end
|
18
|
+
Neutron.execute(
|
19
|
+
"#{o[:prog]} #{specific} -Wl,-rpath=./ -Wall -fpic -o #{target} #{files.join(' ')} #{'-g' if o[:debug]} #{o[:args]}",
|
20
|
+
must_success: true
|
21
|
+
)
|
11
22
|
end
|
12
23
|
|
13
24
|
def self.cc(*files, **opts)
|
@@ -17,6 +28,7 @@ module Neutron::CC
|
|
17
28
|
args: ''
|
18
29
|
}.merge(opts)
|
19
30
|
files.each do |file|
|
31
|
+
file = File.expand_path(file)
|
20
32
|
Neutron.execute("#{o[:prog]} -c #{file} #{'-g' if o[:debug]} #{o[:args]}", must_success: true)
|
21
33
|
end
|
22
34
|
end
|
@@ -28,6 +40,7 @@ module Neutron::CC
|
|
28
40
|
args: ''
|
29
41
|
}.merge(opts)
|
30
42
|
files.each do |file|
|
43
|
+
file = File.expand_path(file)
|
31
44
|
Neutron.execute("#{o[:prog]} -c #{file} #{'-g' if o[:debug]} #{o[:args]}", must_success: true)
|
32
45
|
end
|
33
46
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'neutron'
|
2
|
+
|
3
|
+
module Neutron
|
4
|
+
def self.clean(*files)
|
5
|
+
files << Neutron::PkgStatus::FNAME
|
6
|
+
files.map! do |file|
|
7
|
+
File.expand_path(file)
|
8
|
+
end
|
9
|
+
files.each do |file|
|
10
|
+
if File.exist?(file)
|
11
|
+
Neutron.execute(
|
12
|
+
"rm -r #{file}",
|
13
|
+
must_success: true
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'neutron'
|
2
|
+
|
3
|
+
module Neutron
|
4
|
+
def self.install(*files, dir)
|
5
|
+
prefix = if ENV['PREFIX'] then ENV['PREFIX'] else '/usr' end
|
6
|
+
dir = File.expand_path(File.join(prefix, dir))
|
7
|
+
sudo = if ENV['USE_SUDO'] then 'sudo ' else '' end
|
8
|
+
unless File.exist? dir
|
9
|
+
Neutron.execute(
|
10
|
+
"#{sudo}mkdir --parents --mode=755 #{dir}",
|
11
|
+
must_success: true
|
12
|
+
)
|
13
|
+
end
|
14
|
+
files.each do |file|
|
15
|
+
p file
|
16
|
+
dn = File.join(dir, File.dirname(file))
|
17
|
+
p dn
|
18
|
+
#file = File.expand_path(file)
|
19
|
+
unless File.exist?(dn)
|
20
|
+
Neutron.execute("#{sudo}mkdir --parents --mode=755 #{dn}")
|
21
|
+
end
|
22
|
+
Neutron.execute(
|
23
|
+
"#{sudo}rsync -a --relative --chmod=755 #{file} #{dir}/",
|
24
|
+
must_success: true
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/neutron/pkgconf.rb
CHANGED
@@ -47,4 +47,39 @@ class Neutron::PkgConf
|
|
47
47
|
raise InvalidPkgConfError if tainted?
|
48
48
|
@packages.map{|p|"--pkg #{p}"}.join(' ')
|
49
49
|
end
|
50
|
+
|
51
|
+
def self.gen_pc(filename, **opts)
|
52
|
+
prefix = if ENV['PREFIX'] then ENV['PREFIX'] else '/usr' end
|
53
|
+
filename = File.expand_path(filename)
|
54
|
+
|
55
|
+
content = ''
|
56
|
+
|
57
|
+
content << "prefix=#{prefix}\n"
|
58
|
+
content << "exec_prefix=${prefix}\n"
|
59
|
+
content << "includedir=${prefix}/include\n"
|
60
|
+
content << "libdir=${exec_prefix}/lib\n"
|
61
|
+
content << "\n"
|
62
|
+
|
63
|
+
reqs = if opts[:requires] then opts[:requires].packages.join(' ') else '' end
|
64
|
+
preqs = if opts[:prequires] then opts[:prequires].packages.join(' ') else '' end
|
65
|
+
|
66
|
+
lname = opts[:name]
|
67
|
+
if m = /lib(.+)/.match(lname.downcase)
|
68
|
+
lname = m[1]
|
69
|
+
end
|
70
|
+
|
71
|
+
content << "Name: #{opts[:name] or 'Unnamed'}\n"
|
72
|
+
content << "Description: #{opts[:description] or 'No description'}\n"
|
73
|
+
content << "Version: #{opts[:version] or '0.1.0'}\n"
|
74
|
+
content << "Requires: #{reqs}\n"
|
75
|
+
content << "Requires.private: #{preqs}\n"
|
76
|
+
content << "Cflags: #{opts[:cflags] or "-I${includedir}/#{opts[:name].downcase or 'undefined'}"}\n"
|
77
|
+
content << "Libs: -L${libdir} -l#{lname or 'undefined'}\n"
|
78
|
+
content << "Libs.private: #{opts[:plibs] or ''}\n"
|
79
|
+
|
80
|
+
File.delete(filename) if File.exist?(filename)
|
81
|
+
File.write(filename, content)
|
82
|
+
|
83
|
+
puts "] Done generating pkg-config #{filename}"
|
84
|
+
end
|
50
85
|
end
|
data/lib/neutron/valac.rb
CHANGED
@@ -1,14 +1,65 @@
|
|
1
1
|
require 'neutron'
|
2
2
|
|
3
|
-
|
3
|
+
module Neutron::Valac
|
4
4
|
def self.compile(*files, **opts)
|
5
5
|
o = {
|
6
6
|
prog: 'valac',
|
7
7
|
debug: false,
|
8
|
+
type: :object,
|
9
|
+
gen_vapi: false,
|
10
|
+
gen_header: false,
|
8
11
|
args: ''
|
9
12
|
}.merge(opts)
|
13
|
+
|
14
|
+
specific = ''
|
15
|
+
|
16
|
+
if o[:debug]
|
17
|
+
specific << ' -g'
|
18
|
+
end
|
19
|
+
|
20
|
+
case o[:type]
|
21
|
+
when :object
|
22
|
+
specific << ' -c'
|
23
|
+
when :ccode
|
24
|
+
specific << ' -C'
|
25
|
+
else
|
26
|
+
raise TypeError, "Invalid output type: #{o[:type]}!"
|
27
|
+
end
|
28
|
+
|
10
29
|
files.each do |file|
|
11
|
-
|
30
|
+
file = File.expand_path(file)
|
31
|
+
|
32
|
+
iter_specific = ''
|
33
|
+
|
34
|
+
if o[:gen_vapi]
|
35
|
+
puts "Warning: this part of Neutron::Valac module is not finished. Use it at own risk!"
|
36
|
+
iter_specific << " --vapi #{Neutron.file_to_ext(file, '.vapi')}"
|
37
|
+
end
|
38
|
+
|
39
|
+
if o[:gen_header]
|
40
|
+
iter_specific << " --header #{Neutron.file_to_ext(file, '.h')}"
|
41
|
+
end
|
42
|
+
|
43
|
+
Neutron.execute("#{o[:prog]} #{file} #{specific} #{iter_specific} -b ./ --thread #{o[:args]}", must_success: true)
|
12
44
|
end
|
13
45
|
end
|
14
|
-
|
46
|
+
|
47
|
+
def self.to_c(*files, **opts)
|
48
|
+
o = {
|
49
|
+
proc: 'valac',
|
50
|
+
args: ''
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.vapi_header(header)
|
55
|
+
"[CCode (cheader_filename = \"#{header}\")]\n\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
=begin
|
60
|
+
valac --vapi library.vapi --header library.h library.vala -C # Compiles library into C code and header to access it
|
61
|
+
cat *.vapi > libname.vapi # Concatenates all VAPIs into single file. Worked for me
|
62
|
+
gcc -c library.c -fpic `pkg-config --libs --cflags glib-2.0` # Compiles generated C code
|
63
|
+
gcc library.vala -o libname.so -shared -fpic `pkg-config --libs --cflags glib-2.0` # Compiles shared library
|
64
|
+
valac test.vala libname.vapi -X library.so -X -Wl,-rpath=./ # Compiles project using library
|
65
|
+
=end
|
data/lib/neutron/version.rb
CHANGED
data/lib/neutron.rb
CHANGED
@@ -3,10 +3,16 @@ require 'open3'
|
|
3
3
|
|
4
4
|
require 'neutron/version'
|
5
5
|
|
6
|
+
# Main module
|
6
7
|
module Neutron
|
8
|
+
# Execution error
|
7
9
|
class ExecutionError < StandardError; end
|
8
10
|
|
11
|
+
# Polyfill for Rake::FileList
|
9
12
|
class FileList < Array
|
13
|
+
# Selects all files which match given pattern/regex
|
14
|
+
# @param [String,Regexp] filter
|
15
|
+
# @return [Neutron::FileList]
|
10
16
|
def self.[](filter)
|
11
17
|
arr = Dir[filter]
|
12
18
|
arr = arr.keep_if do |f|
|
@@ -15,24 +21,56 @@ module Neutron
|
|
15
21
|
self.new(arr)
|
16
22
|
end
|
17
23
|
|
24
|
+
# Switches all files to given extension
|
25
|
+
# @param [String] ext New extension
|
18
26
|
def ext(ext)
|
19
27
|
self.map do |f|
|
20
|
-
|
21
|
-
if m
|
22
|
-
m[1] + ext
|
23
|
-
else
|
24
|
-
f + ext
|
25
|
-
end
|
28
|
+
Neutron.file_to_ext(f, ext)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
33
|
+
def self.file_to_ext(f, ext)
|
34
|
+
m = /(.+)\..+/.match(f)
|
35
|
+
if m
|
36
|
+
m[1] + ext
|
37
|
+
else
|
38
|
+
f + ext
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.cat(*files, out, **opts)
|
43
|
+
out = File.expand_path(out)
|
44
|
+
|
45
|
+
File.delete(out) if File.exist?(out)
|
46
|
+
|
47
|
+
f = File.open(out, 'w')
|
48
|
+
puts "] Open: #{out}"
|
49
|
+
|
50
|
+
if opts[:prepend]
|
51
|
+
f.write(opts[:prepend])
|
52
|
+
puts "] Prepended content to #{out}"
|
53
|
+
end
|
54
|
+
|
55
|
+
files.each do |s|
|
56
|
+
s = File.expand_path(s)
|
57
|
+
f.write(File.read(s))
|
58
|
+
puts "] Write #{s} to #{out}"
|
59
|
+
end
|
60
|
+
|
61
|
+
f.close
|
62
|
+
puts "] Close: #{out}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Small extension for array which is developed to be used in Neutron.files()
|
30
66
|
class FilePairList < Array
|
67
|
+
# @return [Array<String>]
|
31
68
|
def sources
|
32
69
|
self.map do |i|
|
33
70
|
i.source
|
34
71
|
end
|
35
72
|
end
|
73
|
+
# @return [Array<String>]
|
36
74
|
def targets
|
37
75
|
self.map do |i|
|
38
76
|
i.target
|
@@ -40,6 +78,10 @@ module Neutron
|
|
40
78
|
end
|
41
79
|
end
|
42
80
|
|
81
|
+
# Returns list of files which need to be processed
|
82
|
+
# @param [Array<String>] sources
|
83
|
+
# @param [String] t_ext Target extension
|
84
|
+
# @return [Neutron::FilePairList<FilePair>]
|
43
85
|
def self.files(sources, t_ext)
|
44
86
|
targets = sources.ext(t_ext)
|
45
87
|
pairs = sources.zip(targets)
|
@@ -62,6 +104,11 @@ module Neutron
|
|
62
104
|
Neutron::FilePairList.new(pairs)
|
63
105
|
end
|
64
106
|
|
107
|
+
# Executes given command
|
108
|
+
# @param [String] string Command to execute
|
109
|
+
# @param [Hash] opts
|
110
|
+
# @option opts [Boolean] :must_success If exit code is not 0 - raises an exception
|
111
|
+
# @return [Array[String,Integer]] Output and exit code
|
65
112
|
def self.execute(string, **opts)
|
66
113
|
puts "> #{string}"
|
67
114
|
stdin, stdout, waiter = *Open3.popen2e(string)
|
@@ -78,19 +125,28 @@ module Neutron
|
|
78
125
|
return [out, waiter.value.exitstatus]
|
79
126
|
end
|
80
127
|
|
128
|
+
# File pair
|
81
129
|
class FilePair
|
82
130
|
attr_reader :source, :target
|
83
131
|
def initialize(source, target)
|
84
132
|
@target = target
|
85
133
|
@source = source
|
86
134
|
end
|
135
|
+
def expand
|
136
|
+
@target = File.expand_path(@target)
|
137
|
+
@source = File.expand_path(@source)
|
138
|
+
self
|
139
|
+
end
|
87
140
|
end
|
88
141
|
|
142
|
+
# Package status utilities
|
89
143
|
module PkgStatus
|
90
144
|
class PkgNotFoundError < StandardError; end
|
91
145
|
|
92
146
|
FNAME = './.neutron_pkgs'.freeze
|
93
147
|
|
148
|
+
# Gets all checked packages
|
149
|
+
# @return [Array<String>]
|
94
150
|
def self.get_checked
|
95
151
|
if File.exist?(FNAME)
|
96
152
|
JSON.load(File.read(FNAME))
|
@@ -99,6 +155,8 @@ module Neutron
|
|
99
155
|
end
|
100
156
|
end
|
101
157
|
|
158
|
+
# Adds found packages to `checked` list
|
159
|
+
# @param [Array<String>] found
|
102
160
|
def self.add_found(found)
|
103
161
|
checked = get_checked
|
104
162
|
File.delete(FNAME) if File.exist?(FNAME)
|
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.2.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-
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,10 @@ files:
|
|
55
55
|
- bin/setup
|
56
56
|
- lib/neutron.rb
|
57
57
|
- lib/neutron/cc.rb
|
58
|
+
- lib/neutron/clean.rb
|
59
|
+
- lib/neutron/install.rb
|
58
60
|
- lib/neutron/pkgconf.rb
|
61
|
+
- lib/neutron/static_lib.rb
|
59
62
|
- lib/neutron/valac.rb
|
60
63
|
- lib/neutron/version.rb
|
61
64
|
- neutron.gemspec
|