rub 0.4.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.
@@ -0,0 +1,80 @@
1
+ # Copyright 2013 Kevin Cox
2
+
3
+ ################################################################################
4
+ # #
5
+ # This software is provided 'as-is', without any express or implied #
6
+ # warranty. In no event will the authors be held liable for any damages #
7
+ # arising from the use of this software. #
8
+ # #
9
+ # Permission is granted to anyone to use this software for any purpose, #
10
+ # including commercial applications, and to alter it and redistribute it #
11
+ # freely, subject to the following restrictions: #
12
+ # #
13
+ # 1. The origin of this software must not be misrepresented; you must not #
14
+ # claim that you wrote the original software. If you use this software in #
15
+ # a product, an acknowledgment in the product documentation would be #
16
+ # appreciated but is not required. #
17
+ # #
18
+ # 2. Altered source versions must be plainly marked as such, and must not be #
19
+ # misrepresented as being the original software. #
20
+ # #
21
+ # 3. This notice may not be removed or altered from any source distribution. #
22
+ # #
23
+ ################################################################################
24
+
25
+ module R
26
+ # A target that executes a command.
27
+ #
28
+ # This is a target that executes a command. It can be used directly but
29
+ # it is easier and prettier to use {C.generator}
30
+ class TargetGenerator < TargetSmart
31
+ attr_accessor :action
32
+
33
+ def initialize
34
+ super
35
+
36
+ @action = 'Building'
37
+
38
+ @cmd = []
39
+ end
40
+
41
+ # Add a command to be executed.
42
+ #
43
+ # @param cmd [Array<String,#to_s]
44
+ # @return [Array<String>] The command.
45
+ def add_cmd(cmd)
46
+ cmd = cmd.map{|a| a.to_s}
47
+ exe = C.find_command(cmd[0])
48
+ if not exe
49
+ raise "Can't find #{cmd[0]}."
50
+ exit 1
51
+ end
52
+ cmd[0] = exe
53
+ @input << cmd[0]
54
+ @cmd << cmd
55
+
56
+ cmd
57
+ end
58
+
59
+ # Add multiple commands.
60
+ #
61
+ # @see add_cmd
62
+ #
63
+ # @param cmds [Array<Array<String,#to_s>>] The commands.
64
+ # @return [Array<Array<String>>] The commands.
65
+ def add_cmds(cmds)
66
+ cmds.map{|c| add_cmd c}
67
+ end
68
+
69
+ def hash_input
70
+ super + Digest::SHA1.digest(
71
+ @cmd.join("\0")
72
+ )
73
+ end
74
+
75
+ def build_self
76
+ R::run(['mkdir', '-pv', *@output.map{|o| o.dirname}], "Preparing output directories", importance: :low)
77
+ @cmd.all?{|c| R::run(c, "#@action #{@output.to_a.join", "}")} or exit 1
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,159 @@
1
+ # Copyright 2013 Kevin Cox
2
+
3
+ ################################################################################
4
+ # #
5
+ # This software is provided 'as-is', without any express or implied #
6
+ # warranty. In no event will the authors be held liable for any damages #
7
+ # arising from the use of this software. #
8
+ # #
9
+ # Permission is granted to anyone to use this software for any purpose, #
10
+ # including commercial applications, and to alter it and redistribute it #
11
+ # freely, subject to the following restrictions: #
12
+ # #
13
+ # 1. The origin of this software must not be misrepresented; you must not #
14
+ # claim that you wrote the original software. If you use this software in #
15
+ # a product, an acknowledgment in the product documentation would be #
16
+ # appreciated but is not required. #
17
+ # #
18
+ # 2. Altered source versions must be plainly marked as such, and must not be #
19
+ # misrepresented as being the original software. #
20
+ # #
21
+ # 3. This notice may not be removed or altered from any source distribution. #
22
+ # #
23
+ ################################################################################
24
+
25
+ require 'valid_array'
26
+
27
+ class Module
28
+ # Class attribute reader.
29
+ #
30
+ # @see attr_reader
31
+ def cattr_reader(*name)
32
+ name.each do |n|
33
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
34
+ unless defined? @@#{n}
35
+ @@#{n} = nil
36
+ end
37
+
38
+ def self.#{n}
39
+ @#{n}
40
+ end
41
+ EOS
42
+ end
43
+ end
44
+ # Class attribute writer.
45
+ #
46
+ # @see attr_writer
47
+ def cattr_writer(*name)
48
+ name.each do |n|
49
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
50
+ unless defined? @@#{n}
51
+ @#{n} = nil
52
+ end
53
+
54
+ def self.#{n}=(v)
55
+ @#{n} = v
56
+ end
57
+ EOS
58
+ end
59
+ end
60
+ # Class attribute accessor.
61
+ #
62
+ # @see attr_accessor
63
+ def cattr_accessor(*name)
64
+ cattr_reader(*name)
65
+ cattr_writer(*name)
66
+ end
67
+ end
68
+
69
+ # From: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/43424
70
+ class Object
71
+ # Recursively clone an object.
72
+ def deep_clone
73
+ return @deep_cloning_obj if @deep_cloning
74
+ @deep_cloning_obj = clone
75
+ @deep_cloning_obj.instance_variables.each do |var|
76
+ val = @deep_cloning_obj.instance_variable_get(var)
77
+ begin
78
+ @deep_cloning = true
79
+ val = val.deep_clone
80
+ rescue TypeError
81
+ next
82
+ ensure
83
+ @deep_cloning = false
84
+ end
85
+ @deep_cloning_obj.instance_variable_set(var, val)
86
+ end
87
+ deep_cloning_obj = @deep_cloning_obj
88
+ @deep_cloning_obj = nil
89
+ deep_cloning_obj
90
+ end
91
+ end
92
+
93
+ # Utility functions aimed at library writers.
94
+ module R::Tool
95
+ # Make argument an array.
96
+ #
97
+ # Turns a single item into an array or copies an array.
98
+ #
99
+ # R::Tool.make_array :item #=> [:item]
100
+ # R::Tool.make_array [:item] #=> [:item]
101
+ #
102
+ # a = ["string1", "string2"]
103
+ # b = R::Tool.make_array a #=> ["string1", "string2"]
104
+ # a.equal? b #=> false
105
+ # a[0].equal? b[0] #=> true
106
+ # a[1].equal? b[1] #=> true
107
+ #
108
+ def self.make_array(a)
109
+ if a.respond_to? :to_a
110
+ a.to_a.dup
111
+ else
112
+ [a]
113
+ end
114
+ end
115
+ # Make argument a set.
116
+ #
117
+ # @see make_array
118
+ def self.make_set(a)
119
+ make_array(a).to_set
120
+ end
121
+
122
+ # Make argument an array of Pathname objects.
123
+ #
124
+ # @see make_array
125
+ #
126
+ # a = C.path('root.rub') #=> #<Pathname:root.rub>
127
+ # b = 'dir.rub' #=> "dir.rub"
128
+ # R::Tool.make_array_paths a #=> [#<Pathname:/path/to/root.rub>]
129
+ # R::Tool.make_array_paths [a] #=> [#<Pathname:/path/to/root.rub>]
130
+ # R::Tool.make_array_paths [a, b] #=> [#<Pathname:/path/to/root.rub>, #<Pathname:/path/to/dir.rub>]
131
+ # R::Tool.make_array_paths b #=> [#<Pathname:/path/to/dir.rub>]
132
+ def self.make_array_paths(a)
133
+ make_array(a).map do |p|
134
+ C.path(p)
135
+ end
136
+ end
137
+
138
+ # Make argument a Set of Pathname objects.
139
+ #
140
+ # @see make_array_paths
141
+ def self.make_set_paths(a)
142
+ make_array_paths(a).to_set
143
+ end
144
+
145
+ # load every script in the directory +d+.
146
+ def self.load_dir(d)
147
+ d = C.path(d)
148
+
149
+ d.children.each {|i| load i}
150
+ end
151
+
152
+ class PathArray < Array
153
+ extend ValidArray
154
+
155
+ def self.validate(item)
156
+ C.path item
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright 2013 Kevin Cox
2
+
3
+ ################################################################################
4
+ # #
5
+ # This software is provided 'as-is', without any express or implied #
6
+ # warranty. In no event will the authors be held liable for any damages #
7
+ # arising from the use of this software. #
8
+ # #
9
+ # Permission is granted to anyone to use this software for any purpose, #
10
+ # including commercial applications, and to alter it and redistribute it #
11
+ # freely, subject to the following restrictions: #
12
+ # #
13
+ # 1. The origin of this software must not be misrepresented; you must not #
14
+ # claim that you wrote the original software. If you use this software in #
15
+ # a product, an acknowledgment in the product documentation would be #
16
+ # appreciated but is not required. #
17
+ # #
18
+ # 2. Altered source versions must be plainly marked as such, and must not be #
19
+ # misrepresented as being the original software. #
20
+ # #
21
+ # 3. This notice may not be removed or altered from any source distribution. #
22
+ # #
23
+ ################################################################################
24
+
25
+ module R::Version
26
+ @@cdto = "cd '#{Pathname.new(__FILE__).realpath.dirname}'"
27
+ @@regex = /^v([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9]+))?(-g([0-9a-f]+))?(-(dirty))?$/
28
+
29
+ # The latest version tag.
30
+ def self.tag
31
+ @@tagcache ||= `#{@@cdto}; git describe --match 'v[0-9]*.*.*' --abbrev=0`.chomp
32
+ end
33
+
34
+ # The number of commits from the latest version tag.
35
+ def self.dist_from_tag
36
+ `#{@@cdto}; git rev-list HEAD ^#{tag} --count`.to_i
37
+ end
38
+
39
+ # Major version number.
40
+ def self.version_major
41
+ tag.sub @@regex, '\1'
42
+ end
43
+ # Minor version number.
44
+ def self.version_minor
45
+ tag.sub @@regex, '\2'
46
+ end
47
+ # Patch number.
48
+ def self.version_patch
49
+ tag.sub @@regex, '\3'
50
+ end
51
+
52
+ # Return the latest commit that is running.
53
+ def self.commit
54
+ `#{@@cdto}; git rev-parse HEAD`.chomp
55
+ end
56
+
57
+ # If anything has changed since the last commit.
58
+ def self.dirty?
59
+ `#{@@cdto}; git diff --exit-code`
60
+ $? != 0
61
+ end
62
+ end
@@ -0,0 +1,145 @@
1
+ # Copyright 2013 Kevin Cox
2
+
3
+ ################################################################################
4
+ # #
5
+ # This software is provided 'as-is', without any express or implied #
6
+ # warranty. In no event will the authors be held liable for any damages #
7
+ # arising from the use of this software. #
8
+ # #
9
+ # Permission is granted to anyone to use this software for any purpose, #
10
+ # including commercial applications, and to alter it and redistribute it #
11
+ # freely, subject to the following restrictions: #
12
+ # #
13
+ # 1. The origin of this software must not be misrepresented; you must not #
14
+ # claim that you wrote the original software. If you use this software in #
15
+ # a product, an acknowledgment in the product documentation would be #
16
+ # appreciated but is not required. #
17
+ # #
18
+ # 2. Altered source versions must be plainly marked as such, and must not be #
19
+ # misrepresented as being the original software. #
20
+ # #
21
+ # 3. This notice may not be removed or altered from any source distribution. #
22
+ # #
23
+ ################################################################################
24
+
25
+ # Version info.
26
+ module R::Version
27
+ # Pretty Program Name.
28
+ def self.name
29
+ 'Rub'
30
+ end
31
+
32
+ # Short easy-to-type name.
33
+ def self.stub
34
+ 'rub'
35
+ end
36
+
37
+ # Command name.
38
+ def self.slug
39
+ stub + R::Version.version_major
40
+ end
41
+
42
+ # Version number as a list.
43
+ #
44
+ # Returns a list of three elements with the major, minor and patch numbers
45
+ # respectively.
46
+ def self.version
47
+ [version_major, version_minor, version_patch]
48
+ end
49
+
50
+ # Returns the version number as a string.
51
+ def self.number_string
52
+ version.join('.')
53
+ end
54
+
55
+ # Latest tag and current commit.
56
+ def self.version_commit
57
+ number_string + '.' + commit[0,8]
58
+ end
59
+
60
+ # Commit and if it is dirty.
61
+ def self.commit_dirty
62
+ commit + ( dirty? ? '-dirty' : '' )
63
+ end
64
+
65
+ # If the version information has been prerendered.
66
+ #
67
+ # If this is false dirty information is probably pretty accurate. If this
68
+ # is true they might have been changed since the rendering occurred.
69
+ def self.rendered?
70
+ false
71
+ end
72
+
73
+ # Returns a version string in the format of the +--version+ command switch.
74
+ def self.info_string
75
+ "#{slug} (#{name}) #{string}"
76
+ end
77
+
78
+ # Returns a formatted version string.
79
+ def self.string
80
+ a = []
81
+
82
+ a << number_string
83
+ if dist_from_tag > 0
84
+ a << dist_from_tag
85
+ a << "g#{commit[0,8]}"
86
+ end
87
+
88
+ if dirty?
89
+ a << 'dirty'
90
+ end
91
+
92
+ a.join '-'
93
+ end
94
+
95
+ # Return a string describing the current version.
96
+ #
97
+ # Returns an overly verbose string giving all useful (and more) information
98
+ # about the current state of the source.
99
+ def self.verbose
100
+ out = []
101
+
102
+ out << "You are using Rub, a platform and language independent build system.\n"
103
+ out << "https://github.com/kevincox/rub\n"
104
+
105
+ out << "\n"
106
+
107
+ out << "You are using commit #{commit}"
108
+ if dirty?
109
+ out << " but the source you are running has been modified since then"
110
+ end
111
+ out << ".\n"
112
+
113
+ out << "Commit #{commit[0,8]} is"
114
+ if dist_from_tag > 0
115
+ out << " #{dist_from_tag} commits after"
116
+ end
117
+ out << " version #{number_string}.\n"
118
+
119
+ if rendered?
120
+ out << "\n"
121
+ out << "NOTE: This information was accurate at the time of"
122
+ out << " installation. Rub can not detect changes since then."
123
+ end
124
+
125
+ out.join
126
+ end
127
+ end
128
+
129
+ R::VersionPure = R::Version.dup
130
+
131
+ cwd = Pathname.new(__FILE__).realpath.dirname
132
+
133
+ `cd '#{cwd}'; git rev-parse --git-dir > /dev/null 2>&1`
134
+ ingit = $?.exitstatus == 0
135
+
136
+ if cwd.join('version-git.rb').exist? && ingit
137
+ #puts 'Loading git'
138
+ load cwd.join('version-git.rb').to_s
139
+ elsif cwd.join('version-generated.rb').exist?
140
+ #puts 'Loading generated'
141
+ load cwd.join('version-generated.rb').to_s
142
+ else
143
+ raise "Couldn't fine version info!"
144
+ Sysexits.exit :software
145
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Cox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sysexits
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: xdg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: valid_array
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '5'
69
+ description: A platform and language independent build system.
70
+ email: kevincox@kevincox.ca
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/rub/dirs.rb
76
+ - lib/rub/l/template.rb
77
+ - lib/rub/l/test.rb
78
+ - lib/rub/l/c/compiler/clang.rb
79
+ - lib/rub/l/c/compiler/gcc.rb
80
+ - lib/rub/l/c.rb
81
+ - lib/rub/l/ld.rb
82
+ - lib/rub/l/util.rb
83
+ - lib/rub/l/ld/linker/clang.rb
84
+ - lib/rub/l/ld/linker/ld.rb
85
+ - lib/rub/l/ld/linker/gcc.rb
86
+ - lib/rub/d.rb
87
+ - lib/rub/init.rb
88
+ - lib/rub/r/command.rb
89
+ - lib/rub/r/persist.rb
90
+ - lib/rub/r/tool.rb
91
+ - lib/rub/r/targetgenerator.rb
92
+ - lib/rub/r/version-git.rb
93
+ - lib/rub/r/target.rb
94
+ - lib/rub/r/i/runner.rb
95
+ - lib/rub/r/i/commandline.rb
96
+ - lib/rub/r/version.rb
97
+ - lib/rub/r/env.rb
98
+ - lib/rub/c.rb
99
+ - lib/rub/l.rb
100
+ - lib/rub/help.rb
101
+ - lib/rub/r.rb
102
+ homepage: https://github.com/kevincox/rub
103
+ licenses:
104
+ - zlib
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A platform and language independent build system.
126
+ test_files: []
127
+ has_rdoc: