ruby_make_script 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/ruby_make_script.rb +54 -8
- data/lib/ruby_make_script/doc.rb +42 -0
- data/lib/ruby_make_script/package.rb +28 -0
- data/lib/ruby_make_script/target.rb +10 -1
- data/lib/ruby_make_script/utils.rb +95 -22
- data/lib/ruby_make_script/version.rb +1 -1
- data/make.md +19 -0
- data/ruby_make_script.gemspec +1 -2
- data/test.rb +14 -0
- metadata +10 -7
- data/Gemfile.lock +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 200ba58b3736310403ce67c88d2d802498c34fa560432760cfd7525e9c4ad44d
|
4
|
+
data.tar.gz: 3f4843b9dbc4c10d98f11358f4219abbef5780acc223e91439a1bc33caa61237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a75146d567c82c901802a52d5b5de733db593f00907ffde817d1f14dc93a763513119c597555cdff3dd68a127c4a7fdedb60fc34f38d2ffc3b747a69015a2e71
|
7
|
+
data.tar.gz: f2f0948c8f5ac4a02d9292cb4ede85a476dd9bccfe93516a28b82a9a61db21e95078cd544386bf8fe9f75e4074d523a0fa60d26cd694859636d2aeff5e6580b2
|
data/.gitignore
CHANGED
data/lib/ruby_make_script.rb
CHANGED
@@ -15,6 +15,10 @@
|
|
15
15
|
#
|
16
16
|
#
|
17
17
|
|
18
|
+
if !system('gem list | grep pastel > /dev/null')
|
19
|
+
puts "pastel not install automaticly, please 'gem install pastel'"
|
20
|
+
end
|
21
|
+
|
18
22
|
require 'pastel'
|
19
23
|
require 'yaml'
|
20
24
|
|
@@ -35,7 +39,7 @@ require 'ruby_make_script/target'
|
|
35
39
|
|
36
40
|
# check a file (recursively) and run the commands of the target.
|
37
41
|
def resolve(file, force_exec=false)
|
38
|
-
if file_modified?(file)
|
42
|
+
if force_exec || file_modified?(file)
|
39
43
|
t = $file_target_dict[file]
|
40
44
|
# when t == nil, its a file not used for target
|
41
45
|
if t != nil
|
@@ -108,7 +112,7 @@ class Symbol
|
|
108
112
|
# end
|
109
113
|
# ```
|
110
114
|
def then
|
111
|
-
from()
|
115
|
+
PhonyTarget.new(String(self)).from() { yield }
|
112
116
|
end
|
113
117
|
end
|
114
118
|
|
@@ -158,23 +162,65 @@ def make
|
|
158
162
|
$file_time_dict = YAML.load(File.read('./.make_script.yaml'))
|
159
163
|
$cur_file_time_dict = $file_time_dict.clone()
|
160
164
|
end
|
161
|
-
puts Pastel.new.
|
165
|
+
puts Pastel.new.bright_cyan("make> ") + "start"
|
166
|
+
|
162
167
|
begin
|
163
|
-
if ARGV.length
|
168
|
+
if ARGV.length == 0
|
164
169
|
$targetlist[0].resolve_all
|
165
170
|
else
|
166
|
-
|
171
|
+
p ARGV[0]
|
172
|
+
resolve(ARGV[0], true)
|
167
173
|
end
|
168
174
|
|
169
175
|
rescue StandardError => e
|
170
|
-
puts Pastel.new.red.bold("
|
176
|
+
puts Pastel.new.red.bold("make failed> ") + e.message
|
171
177
|
if e.message != "make command failed"
|
172
178
|
puts e.backtrace
|
173
179
|
end
|
174
180
|
else
|
175
|
-
puts Pastel.new.
|
181
|
+
puts Pastel.new.bright_cyan("make> ") + "completed"
|
182
|
+
end
|
183
|
+
if !File.exist?('./.make_script.yaml')
|
184
|
+
File.open('.gitignore', 'a') do |f|
|
185
|
+
f << "\n.make_script.yaml\n"
|
186
|
+
end
|
176
187
|
end
|
177
|
-
|
178
188
|
File.open('./.make_script.yaml', 'w') { |f| f.write(YAML.dump($cur_file_time_dict)) }
|
189
|
+
end
|
179
190
|
|
191
|
+
def dump_md(filename, thisfile="make.rb")
|
192
|
+
puts Pastel.new.bright_cyan("make> ") + "dumping markdown file #{filename}"
|
193
|
+
File.open(filename, 'w') do |f|
|
194
|
+
f.puts "# #{thisfile} Documentation"
|
195
|
+
f.puts ""
|
196
|
+
if block_given?
|
197
|
+
yield f
|
198
|
+
f.puts ""
|
199
|
+
end
|
200
|
+
f.puts "## Usage"
|
201
|
+
f.puts ""
|
202
|
+
f.puts "Please install ruby and some package first:"
|
203
|
+
f.puts ""
|
204
|
+
f.puts "```sh"
|
205
|
+
f.puts "$ apt instal ruby"
|
206
|
+
f.puts "$ gem instal pastel ruby_make_script"
|
207
|
+
f.puts "```"
|
208
|
+
f.puts ""
|
209
|
+
f.puts "then you can run these command below."
|
210
|
+
$targetlist.each { |t|
|
211
|
+
if t.class == PhonyTarget
|
212
|
+
args = t.doc.arglist.map{ |a| a[0] }.join(' ')
|
213
|
+
f.puts "### `./#{thisfile} #{t.target} #{args}`"
|
214
|
+
f.puts ""
|
215
|
+
f.puts "#{t.doc.descr}"
|
216
|
+
f.puts ""
|
217
|
+
t.doc.arglist.each { |a|
|
218
|
+
f.puts "* `#{a[0]}` : #{a[1]}"
|
219
|
+
}
|
220
|
+
if t.doc.arglist != []
|
221
|
+
f.puts ""
|
222
|
+
end
|
223
|
+
end
|
224
|
+
}
|
225
|
+
end
|
180
226
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
class TargetDoc
|
3
|
+
attr_accessor :arglist
|
4
|
+
attr_accessor :descr
|
5
|
+
attr_accessor :name
|
6
|
+
|
7
|
+
def initialize()
|
8
|
+
@arglist = []
|
9
|
+
@descr = ""
|
10
|
+
@name = ""
|
11
|
+
end
|
12
|
+
def set_name(name)
|
13
|
+
@name = name
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_arg(name, doc)
|
17
|
+
@arglist += [[name, doc]]
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_descr(str)
|
21
|
+
@descr += str + "\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
def empty?()
|
25
|
+
@arglist == [] || @descr == ""
|
26
|
+
end
|
27
|
+
|
28
|
+
def form_str()
|
29
|
+
[@name, *@arglist].join(" ")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
$targetdoc = TargetDoc.new
|
34
|
+
|
35
|
+
def descr!(str)
|
36
|
+
$targetdoc.add_descr(str)
|
37
|
+
end
|
38
|
+
|
39
|
+
def arg!(name, doc)
|
40
|
+
$targetdoc.add_arg(name, doc)
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
$system_to_pack = Hash[
|
3
|
+
"Ubuntu" => "apk",
|
4
|
+
"Darwin" => "brew"
|
5
|
+
]
|
6
|
+
$pack = Hash[]
|
7
|
+
|
8
|
+
$pack['apt'] = Hash[
|
9
|
+
"uninstall" => "remove"
|
10
|
+
]
|
11
|
+
|
12
|
+
$pack['brew'] = Hash[
|
13
|
+
"remove" => "uninstall"
|
14
|
+
]
|
15
|
+
|
16
|
+
def PACK(cmd, *args)
|
17
|
+
cmd = String(cmd)
|
18
|
+
$system_to_pack.each do |k,v|
|
19
|
+
if `uname -a`[k]
|
20
|
+
if $pack[v][cmd]
|
21
|
+
cmd = $pack[v][cmd]
|
22
|
+
end
|
23
|
+
r v, cmd, *args
|
24
|
+
break
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -1,8 +1,10 @@
|
|
1
1
|
$t = []
|
2
2
|
$d = []
|
3
3
|
|
4
|
-
|
4
|
+
require "ruby_make_script/doc"
|
5
5
|
|
6
|
+
module Target
|
7
|
+
|
6
8
|
def depend_each
|
7
9
|
depend.each { |f|
|
8
10
|
yield f
|
@@ -39,6 +41,7 @@ class FileTarget
|
|
39
41
|
resolve(f)
|
40
42
|
}
|
41
43
|
end
|
44
|
+
|
42
45
|
def run
|
43
46
|
if ! @completed
|
44
47
|
@update_proc.call
|
@@ -53,6 +56,7 @@ class FileTarget
|
|
53
56
|
@depend = []
|
54
57
|
@completed = false
|
55
58
|
end
|
59
|
+
|
56
60
|
def from(*dependlist)
|
57
61
|
@depend = dependlist
|
58
62
|
@update_proc = Proc.new {
|
@@ -72,7 +76,9 @@ end
|
|
72
76
|
|
73
77
|
class PhonyTarget
|
74
78
|
include Target
|
79
|
+
attr_accessor :target
|
75
80
|
attr_accessor :depend
|
81
|
+
attr_accessor :doc
|
76
82
|
def resolve_all
|
77
83
|
resolve(@target)
|
78
84
|
end
|
@@ -88,6 +94,9 @@ class PhonyTarget
|
|
88
94
|
@target = str
|
89
95
|
@depend = []
|
90
96
|
@completed = false
|
97
|
+
|
98
|
+
@doc = $targetdoc
|
99
|
+
$targetdoc = TargetDoc.new
|
91
100
|
end
|
92
101
|
|
93
102
|
def from(*dependlist)
|
@@ -1,15 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
# since ~ "cd <path>" invalid, add a function here
|
4
2
|
def cd(str)
|
5
|
-
|
6
|
-
orig = Dir.pwd
|
7
|
-
Dir.chdir(str)
|
8
|
-
yield
|
9
|
-
Dir.chdir(orig)
|
10
|
-
else
|
11
|
-
Dir.chdir(str)
|
12
|
-
end
|
3
|
+
Dir.chdir(str)
|
13
4
|
end
|
14
5
|
|
15
6
|
# these were like cd function
|
@@ -21,9 +12,19 @@ end
|
|
21
12
|
def mkdir(*str)
|
22
13
|
r"mkdir #{str.join(' ')}"
|
23
14
|
end
|
15
|
+
# these were like cd function
|
16
|
+
def mv(*str)
|
17
|
+
r"mv #{str.join(' ')}"
|
18
|
+
end
|
24
19
|
|
25
|
-
|
26
|
-
|
20
|
+
# these were like cd function
|
21
|
+
def cp(*str)
|
22
|
+
r"cp #{str.join(' ')}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def r(cmd, *str)
|
26
|
+
cmd = String(cmd)
|
27
|
+
str = cmd + " " + str.join(" ")
|
27
28
|
puts Pastel.new.green("running> ") + str
|
28
29
|
if !system(str)
|
29
30
|
puts Pastel.new.red.bold("error> ") + "command error: " + str
|
@@ -34,14 +35,7 @@ end
|
|
34
35
|
# since ~ "cd <path>" invalid, add a function here
|
35
36
|
def cd?(str)
|
36
37
|
begin
|
37
|
-
|
38
|
-
orig = Dir.pwd
|
39
|
-
Dir.chdir(str)
|
40
|
-
yield
|
41
|
-
Dir.chdir(orig)
|
42
|
-
else
|
43
|
-
Dir.chdir(str)
|
44
|
-
end
|
38
|
+
Dir.chdir(str)
|
45
39
|
rescue => exception
|
46
40
|
puts Pastel.new.yellow("warning> ") + "command error: cd " + str + " (suppressed)"
|
47
41
|
return false
|
@@ -59,9 +53,20 @@ def mkdir?(*str)
|
|
59
53
|
r?"mkdir #{str.join(' ')}"
|
60
54
|
end
|
61
55
|
|
56
|
+
# these were like cd function
|
57
|
+
def mv?(*str)
|
58
|
+
r?"mv #{str.join(' ')}"
|
59
|
+
end
|
60
|
+
|
61
|
+
# these were like cd function
|
62
|
+
def cp?(*str)
|
63
|
+
r?"cp #{str.join(' ')}"
|
64
|
+
end
|
65
|
+
|
62
66
|
# no error
|
63
|
-
def r?(*str)
|
64
|
-
|
67
|
+
def r?(cmd, *str)
|
68
|
+
cmd = String(cmd)
|
69
|
+
str = cmd + " " + str.join(" ")
|
65
70
|
puts Pastel.new.green("running> ") + str
|
66
71
|
flag = system(str)
|
67
72
|
if !flag
|
@@ -74,7 +79,75 @@ def runfile(file, *args)
|
|
74
79
|
path = File.expand_path(file)
|
75
80
|
r path, *args
|
76
81
|
end
|
82
|
+
|
77
83
|
def runfile?(file, *args)
|
78
84
|
path = File.expand_path(file)
|
79
85
|
r? path, *args
|
80
86
|
end
|
87
|
+
|
88
|
+
class InDir
|
89
|
+
def initialize(path, err=true)
|
90
|
+
@path = path
|
91
|
+
@err = err
|
92
|
+
end
|
93
|
+
|
94
|
+
def enter
|
95
|
+
@orig = Dir.pwd
|
96
|
+
if @err
|
97
|
+
cd @path
|
98
|
+
else
|
99
|
+
cd? @path
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def exit
|
104
|
+
if @err
|
105
|
+
cd @orig
|
106
|
+
else
|
107
|
+
cd? @orig
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def dir(path)
|
113
|
+
InDir.new(path)
|
114
|
+
end
|
115
|
+
|
116
|
+
def dir?(path)
|
117
|
+
InDir.new(path, false)
|
118
|
+
end
|
119
|
+
|
120
|
+
class InEnv
|
121
|
+
def initialize(expr)
|
122
|
+
@k, @v = expr.split('=')
|
123
|
+
end
|
124
|
+
|
125
|
+
def enter
|
126
|
+
@v0 = ENV[@k]
|
127
|
+
ENV[@k] = @v
|
128
|
+
end
|
129
|
+
|
130
|
+
def exit
|
131
|
+
ENV[@k] = @v0
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def envir(expr)
|
136
|
+
InEnv.new(expr)
|
137
|
+
end
|
138
|
+
|
139
|
+
def use(*operation)
|
140
|
+
operation.each{ |o| o.enter}
|
141
|
+
yield
|
142
|
+
operation.each{ |o| o.exit}
|
143
|
+
end
|
144
|
+
|
145
|
+
def GIT(*args)
|
146
|
+
r "git", *args.map{|s| String(s)}
|
147
|
+
end
|
148
|
+
|
149
|
+
def DOCKER(*args)
|
150
|
+
r "docker", *args.map{|s| String(s)}
|
151
|
+
end
|
152
|
+
|
153
|
+
require 'ruby_make_script/package'
|
data/make.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# make.rb Documentation
|
2
|
+
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
Please install ruby and some package first:
|
7
|
+
|
8
|
+
```sh
|
9
|
+
$ apt instal ruby
|
10
|
+
$ gem instal pastel ruby_make_script
|
11
|
+
```
|
12
|
+
|
13
|
+
then you can run these command below.
|
14
|
+
### `./make.rb setup <args...>`
|
15
|
+
|
16
|
+
setup the environment
|
17
|
+
|
18
|
+
* `<args...>` : command to run
|
19
|
+
|
data/ruby_make_script.gemspec
CHANGED
@@ -32,7 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
33
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
34
|
end
|
35
|
-
p spec.files
|
36
35
|
spec.bindir = "exe"
|
37
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
37
|
spec.require_paths = ["lib"]
|
@@ -40,5 +39,5 @@ Gem::Specification.new do |spec|
|
|
40
39
|
spec.add_development_dependency "bundler", "~> 1.17"
|
41
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
42
41
|
spec.add_development_dependency "minitest", "~> 5.0"
|
43
|
-
spec.add_development_dependency "pastel"
|
42
|
+
spec.add_development_dependency "pastel" , "~> 0.7.4"
|
44
43
|
end
|
data/test.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_make_script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dnailz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: pastel
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.7.4
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.7.4
|
69
69
|
description: A ruby make DSL for ruby like GNU make. (very simple)
|
70
70
|
email:
|
71
71
|
- dnailzb@outlook.com
|
@@ -77,17 +77,20 @@ files:
|
|
77
77
|
- ".travis.yml"
|
78
78
|
- CODE_OF_CONDUCT.md
|
79
79
|
- Gemfile
|
80
|
-
- Gemfile.lock
|
81
80
|
- LICENSE.txt
|
82
81
|
- README.md
|
83
82
|
- Rakefile
|
84
83
|
- bin/console
|
85
84
|
- bin/setup
|
86
85
|
- lib/ruby_make_script.rb
|
86
|
+
- lib/ruby_make_script/doc.rb
|
87
|
+
- lib/ruby_make_script/package.rb
|
87
88
|
- lib/ruby_make_script/target.rb
|
88
89
|
- lib/ruby_make_script/utils.rb
|
89
90
|
- lib/ruby_make_script/version.rb
|
91
|
+
- make.md
|
90
92
|
- ruby_make_script.gemspec
|
93
|
+
- test.rb
|
91
94
|
homepage: https://github.com/DnailZ/ruby_make_script
|
92
95
|
licenses:
|
93
96
|
- MIT
|
data/Gemfile.lock
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ruby_make_script (0.1.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
equatable (0.6.1)
|
10
|
-
minitest (5.14.1)
|
11
|
-
pastel (0.7.4)
|
12
|
-
equatable (~> 0.6)
|
13
|
-
tty-color (~> 0.5)
|
14
|
-
rake (10.5.0)
|
15
|
-
tty-color (0.5.1)
|
16
|
-
|
17
|
-
PLATFORMS
|
18
|
-
ruby
|
19
|
-
|
20
|
-
DEPENDENCIES
|
21
|
-
bundler (~> 1.17)
|
22
|
-
minitest (~> 5.0)
|
23
|
-
pastel
|
24
|
-
rake (~> 10.0)
|
25
|
-
ruby_make_script!
|
26
|
-
|
27
|
-
BUNDLED WITH
|
28
|
-
1.17.2
|