ruby_make_script 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b85b310f3fca899111a9a318643189ce056c1dd247f4f12e85ec3a840ee3ef0c
4
- data.tar.gz: 0c85142b81f27c6cadd8824c79a8f9595f386a27fdbca49f4697ba96656dae13
3
+ metadata.gz: 39795ddc3d0820433555bb57ffd41639be77a702ee4e3ff72cac6dd243fa9bb8
4
+ data.tar.gz: 629a6e4804bd3112e66660e3b921965d16456d94478da616453824de2ccd53ee
5
5
  SHA512:
6
- metadata.gz: 752c14fc7c3c18285462f1663e6e38a9246e4e3ef81dbbea08986ce10508f40771cc51169cb6c3ef062b45f1c27fd564336964c568f3c991b2f15abdd2a395d3
7
- data.tar.gz: a8047c2bcf0ccb99e2a06499630032b7725e3cfed0d32d58fad69f62f5b69b870f2339fdcab515cb14158377047fc30e64f2fab23a5aead5b43ae82d3e7ffe27
6
+ metadata.gz: d6dec45593827ae2055b5cef614fcb2ca905d61bc3b85c02524cff4cdaeb2b8397e255d4550aa9079557af32d0baed3082ac858d81608c885a1226d99130e648
7
+ data.tar.gz: 784d568d21a7ac1a3120ca7b125079a9bc2fc42a030e19e668cd99e18332b66739550561be954ce4f61be025b7076526f091c66a866d66d0213c9e3b11d2b273
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ .make_script.yaml
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem 'pastel'
3
4
 
4
5
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
6
 
@@ -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) || force_exec
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,64 @@ 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.green.bold("ruby_make_script> ") + "start"
165
+ puts Pastel.new.bright_cyan("make> ") + "start"
166
+
162
167
  begin
163
- if ARGV.length <= 1
168
+ if ARGV.length == 0
164
169
  $targetlist[0].resolve_all
165
170
  else
166
- resolve(ARGV[1], force_exec=true)
171
+ resolve(ARGV[0], true)
167
172
  end
168
173
 
169
174
  rescue StandardError => e
170
- puts Pastel.new.red.bold("ruby_make_script failed> ") + e.message
175
+ puts Pastel.new.red.bold("make failed> ") + e.message
171
176
  if e.message != "make command failed"
172
177
  puts e.backtrace
173
178
  end
174
179
  else
175
- puts Pastel.new.green.bold("ruby_make_script> ") + "completed"
180
+ puts Pastel.new.bright_cyan("make> ") + "completed"
181
+ end
182
+ if !File.exist?('./.make_script.yaml')
183
+ File.open('.gitignore', 'a') do |f|
184
+ f << "\n.make_script.yaml\n"
185
+ end
176
186
  end
177
-
178
187
  File.open('./.make_script.yaml', 'w') { |f| f.write(YAML.dump($cur_file_time_dict)) }
188
+ end
179
189
 
190
+ def dump_md(filename, thisfile="make.rb")
191
+ puts Pastel.new.bright_cyan("make> ") + "dumping markdown file #{filename}"
192
+ File.open(filename, 'w') do |f|
193
+ f.puts "# #{thisfile} Documentation"
194
+ f.puts ""
195
+ if block_given?
196
+ yield f
197
+ f.puts ""
198
+ end
199
+ f.puts "## Usage"
200
+ f.puts ""
201
+ f.puts "Please install ruby and some package first:"
202
+ f.puts ""
203
+ f.puts "```sh"
204
+ f.puts "$ apt instal ruby"
205
+ f.puts "$ gem instal pastel ruby_make_script"
206
+ f.puts "```"
207
+ f.puts ""
208
+ f.puts "then you can run these command below."
209
+ $targetlist.each { |t|
210
+ if t.class == PhonyTarget
211
+ args = t.doc.arglist.map{ |a| a[0] }.join(' ')
212
+ f.puts "### `./#{thisfile} #{t.target} #{args}`"
213
+ f.puts ""
214
+ f.puts "#{t.doc.descr}"
215
+ f.puts ""
216
+ t.doc.arglist.each { |a|
217
+ f.puts "* `#{a[0]}` : #{a[1]}"
218
+ }
219
+ if t.doc.arglist != []
220
+ f.puts ""
221
+ end
222
+ end
223
+ }
224
+ end
180
225
  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
+
@@ -1,8 +1,10 @@
1
1
  $t = []
2
2
  $d = []
3
3
 
4
- module Target
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
- if block_given?
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,6 +12,15 @@ 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
19
+
20
+ # these were like cd function
21
+ def cp(*str)
22
+ r"cp #{str.join(' ')}"
23
+ end
24
24
 
25
25
  def r(*str)
26
26
  str = str.join(" ")
@@ -34,14 +34,7 @@ end
34
34
  # since ~ "cd <path>" invalid, add a function here
35
35
  def cd?(str)
36
36
  begin
37
- if block_given?
38
- orig = Dir.pwd
39
- Dir.chdir(str)
40
- yield
41
- Dir.chdir(orig)
42
- else
43
- Dir.chdir(str)
44
- end
37
+ Dir.chdir(str)
45
38
  rescue => exception
46
39
  puts Pastel.new.yellow("warning> ") + "command error: cd " + str + " (suppressed)"
47
40
  return false
@@ -59,6 +52,16 @@ def mkdir?(*str)
59
52
  r?"mkdir #{str.join(' ')}"
60
53
  end
61
54
 
55
+ # these were like cd function
56
+ def mv?(*str)
57
+ r?"mv #{str.join(' ')}"
58
+ end
59
+
60
+ # these were like cd function
61
+ def cp?(*str)
62
+ r?"cp #{str.join(' ')}"
63
+ end
64
+
62
65
  # no error
63
66
  def r?(*str)
64
67
  str = str.join(" ")
@@ -74,7 +77,65 @@ def runfile(file, *args)
74
77
  path = File.expand_path(file)
75
78
  r path, *args
76
79
  end
80
+
77
81
  def runfile?(file, *args)
78
82
  path = File.expand_path(file)
79
83
  r? path, *args
80
84
  end
85
+
86
+ class InDir
87
+ def initialize(path, err=true)
88
+ @path = path
89
+ @err = err
90
+ end
91
+
92
+ def enter
93
+ @orig = Dir.pwd
94
+ if @err
95
+ cd @path
96
+ else
97
+ cd? @path
98
+ end
99
+ end
100
+
101
+ def exit
102
+ if @err
103
+ cd @orig
104
+ else
105
+ cd? @orig
106
+ end
107
+ end
108
+ end
109
+
110
+ def dir(path)
111
+ InDir.new(path)
112
+ end
113
+
114
+ def dir?(path)
115
+ InDir.new(path, false)
116
+ end
117
+
118
+ class InEnv
119
+ def initialize(expr)
120
+ @k, @v = expr.split('=')
121
+ end
122
+
123
+ def enter
124
+ @v0 = ENV[k]
125
+ ENV[k] = @v
126
+ end
127
+
128
+ def exit
129
+ ENV[k] = @v0
130
+ end
131
+ end
132
+
133
+ def envir(expr)
134
+ InEnv.new(expr)
135
+ end
136
+
137
+ def using(*operation)
138
+ operation.each{ |o| o.enter}
139
+ yield
140
+ operation.each{ |o| o.exit}
141
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyMakeScript
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
3
3
  end
data/make.md ADDED
@@ -0,0 +1 @@
1
+ # `make.rb` Usage### `make.rb setup <args...>`
@@ -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
@@ -0,0 +1,11 @@
1
+ require "ruby_make_script"
2
+
3
+ make do
4
+ descr! "setup the environment"
5
+ arg! "<args...>", "command to run"
6
+ :setup.from do
7
+ r "echo", "Hello", "World"
8
+ end
9
+ end
10
+
11
+ dump_md('make.md'){}
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.1
4
+ version: 0.1.6
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-23 00:00:00.000000000 Z
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: '0'
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: '0'
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,19 @@ 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
87
  - lib/ruby_make_script/target.rb
88
88
  - lib/ruby_make_script/utils.rb
89
89
  - lib/ruby_make_script/version.rb
90
+ - make.md
90
91
  - ruby_make_script.gemspec
92
+ - test.rb
91
93
  homepage: https://github.com/DnailZ/ruby_make_script
92
94
  licenses:
93
95
  - MIT
@@ -1,28 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ruby_make_script (0.1.0)
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