build-tool 0.5.7 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/.gitignore +1 -0
  2. data/.rvmrc +1 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +5 -0
  5. data/Gemfile.lock +56 -0
  6. data/History.txt +64 -0
  7. data/README.txt +0 -7
  8. data/Rakefile +8 -56
  9. data/bin/build-tool +4 -1
  10. data/build-tool.gemspec +62 -0
  11. data/db/migrations/20110703074000_add_command_logs.rb +17 -0
  12. data/db/migrations/20110703075000_add_module_logs.rb +20 -0
  13. data/db/migrations/20110815170000_add_features.rb +17 -0
  14. data/db/migrations/20120103204700_add_modules.rb +17 -0
  15. data/db/migrations/20120106181200_add_settings.rb +18 -0
  16. data/lib/build-tool.rb +3 -4
  17. data/lib/build-tool/application.rb +127 -37
  18. data/lib/build-tool/build-system/autoconf.rb +2 -8
  19. data/lib/build-tool/build-system/base.rb +12 -4
  20. data/lib/build-tool/build-system/cmake.rb +2 -0
  21. data/lib/build-tool/build-system/custom.rb +2 -0
  22. data/lib/build-tool/build-system/kdel10n.rb +2 -0
  23. data/lib/build-tool/build-system/make.rb +2 -0
  24. data/lib/build-tool/build-system/none.rb +2 -0
  25. data/lib/build-tool/build-system/qmake.rb +2 -0
  26. data/lib/build-tool/build-system/qt.rb +4 -0
  27. data/lib/build-tool/cfg/lexer.rex +40 -8
  28. data/lib/build-tool/cfg/lexer_base.rb +3 -1
  29. data/lib/build-tool/cfg/node.rb +17 -1
  30. data/lib/build-tool/cfg/parser.y +92 -10
  31. data/lib/build-tool/cfg/visitor.rb +202 -78
  32. data/lib/build-tool/command_actions.rb +26 -10
  33. data/lib/build-tool/commands.rb +289 -197
  34. data/lib/build-tool/commands/build.rb +13 -9
  35. data/lib/build-tool/commands/configuration.rb +25 -0
  36. data/lib/build-tool/commands/configuration/edit.rb +42 -0
  37. data/lib/build-tool/commands/configuration/list.rb +48 -0
  38. data/lib/build-tool/commands/configure.rb +9 -5
  39. data/lib/build-tool/commands/ctags.rb +8 -3
  40. data/lib/build-tool/commands/environments.rb +2 -4
  41. data/lib/build-tool/commands/environments/list.rb +13 -10
  42. data/lib/build-tool/commands/environments/set.rb +5 -1
  43. data/lib/build-tool/commands/features.rb +24 -0
  44. data/lib/build-tool/commands/features/disable.rb +70 -0
  45. data/lib/build-tool/commands/features/enable.rb +66 -0
  46. data/lib/build-tool/commands/features/list.rb +92 -0
  47. data/lib/build-tool/commands/fetch.rb +9 -3
  48. data/lib/build-tool/commands/files.rb +9 -5
  49. data/lib/build-tool/commands/gc.rb +48 -15
  50. data/lib/build-tool/commands/history.rb +21 -16
  51. data/lib/build-tool/commands/info.rb +16 -13
  52. data/lib/build-tool/commands/install.rb +8 -4
  53. data/lib/build-tool/commands/modules.rb +2 -4
  54. data/lib/build-tool/commands/modules/cleanup.rb +52 -0
  55. data/lib/build-tool/commands/modules/disable.rb +95 -0
  56. data/lib/build-tool/commands/modules/enable.rb +52 -0
  57. data/lib/build-tool/commands/modules/info.rb +44 -35
  58. data/lib/build-tool/commands/modules/list.rb +67 -15
  59. data/lib/build-tool/commands/modules/shell.rb +8 -2
  60. data/lib/build-tool/commands/rebase.rb +15 -7
  61. data/lib/build-tool/commands/recipes.rb +2 -4
  62. data/lib/build-tool/commands/recipes/add.rb +16 -2
  63. data/lib/build-tool/commands/recipes/edit.rb +72 -0
  64. data/lib/build-tool/commands/recipes/incoming.rb +11 -7
  65. data/lib/build-tool/commands/recipes/info.rb +12 -8
  66. data/lib/build-tool/commands/recipes/install.rb +37 -42
  67. data/lib/build-tool/commands/recipes/list.rb +6 -2
  68. data/lib/build-tool/configuration.rb +88 -3
  69. data/lib/build-tool/environment.rb +2 -0
  70. data/lib/build-tool/errors.rb +5 -0
  71. data/lib/build-tool/history.rb +3 -181
  72. data/lib/build-tool/model/command_log.rb +93 -0
  73. data/lib/build-tool/model/feature.rb +80 -0
  74. data/lib/build-tool/{module.rb → model/module.rb} +110 -29
  75. data/lib/build-tool/model/module_log.rb +64 -0
  76. data/lib/build-tool/model/setting.rb +84 -0
  77. data/lib/build-tool/recipe.rb +40 -18
  78. data/lib/build-tool/repository.rb +39 -33
  79. data/lib/build-tool/server.rb +27 -3
  80. data/lib/build-tool/singleton.rb +2 -0
  81. data/lib/build-tool/sshkey.rb +2 -0
  82. data/lib/build-tool/state_helper.rb +64 -0
  83. data/lib/build-tool/vcs/archive.rb +3 -1
  84. data/lib/build-tool/vcs/base.rb +13 -0
  85. data/lib/build-tool/vcs/git-svn.rb +36 -14
  86. data/lib/build-tool/vcs/git.rb +180 -44
  87. data/lib/build-tool/vcs/mercurial.rb +25 -13
  88. data/lib/build-tool/vcs/svn.rb +20 -15
  89. data/lib/build-tool/version.rb +30 -0
  90. data/lib/mj/error.rb +2 -0
  91. data/lib/mj/logging.rb +2 -0
  92. data/lib/mj/mixins/inherited_attributes.rb +73 -0
  93. data/lib/mj/tools/editor.rb +34 -0
  94. data/lib/mj/tools/ssh.rb +2 -0
  95. data/lib/mj/tools/subprocess.rb +2 -1
  96. data/lib/mj/vcs/git.rb +14 -2
  97. data/lib/mj/visitor.rb +22 -0
  98. data/tasks/db.rake +36 -0
  99. data/tasks/racc.rake +14 -0
  100. data/tasks/rdoc.rake +8 -0
  101. data/tasks/rexical.rake +14 -0
  102. data/tasks/test.rake +21 -0
  103. data/test/integration/history_test.rb +88 -0
  104. data/test/integration/parser_configuration.rb +36 -0
  105. data/test/integration/parser_environment_parser.rb +156 -0
  106. data/test/integration/parser_feature_test.rb +75 -0
  107. data/test/integration/parser_git-svn_test.rb +92 -0
  108. data/test/integration/parser_git_test.rb +97 -0
  109. data/test/integration/parser_mercurial_test.rb +77 -0
  110. data/test/integration/parser_module_test.rb +103 -0
  111. data/test/integration/parser_svn_test.rb +92 -0
  112. data/test/integration/parser_test.rb +73 -0
  113. data/test/test_helper.rb +61 -0
  114. data/test/unit/configuration_test.rb +36 -0
  115. data/test/unit/git_configuration_test.rb +163 -0
  116. data/test/unit/git_svn_configuration_test.rb +240 -0
  117. data/test/unit/mercurial_configuration_test.rb +64 -0
  118. data/test/unit/model/command_log_test.rb +103 -0
  119. data/test/unit/model/feature_test.rb +29 -0
  120. data/test/unit/model/module_log_test.rb +70 -0
  121. data/test/unit/model/module_test.rb +32 -0
  122. data/test/unit/repository_test.rb +110 -0
  123. data/test/unit/server_test.rb +66 -0
  124. data/test/unit/svn_configuration_test.rb +90 -0
  125. metadata +134 -93
  126. data/Manifest.txt +0 -80
  127. data/db/migrations/001_command_histories.rb +0 -20
  128. data/db/migrations/002_module_events.rb +0 -24
  129. data/db/migrations/003_command_histories_add_logfile.rb +0 -19
  130. data/lib/build-tool/GUI.rb +0 -360
  131. data/lib/build-tool/commands/help.rb +0 -22
  132. data/lib/build-tool/commands/lsfeatures.rb +0 -76
  133. data/lib/build-tool/feature.rb +0 -47
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  require 'build-tool/commands'
2
4
  require 'build-tool/recipe'
3
5
 
@@ -13,14 +15,16 @@ class List < Standard
13
15
  long_description [ "Shows the list of recipes." ]
14
16
 
15
17
  def initialize_options
16
- @options.banner = "Usage: #{Pathname.new($0).basename} #{self.fullname}"
18
+ options.banner = "Usage: #{self.fullname} [OPTIONS]..."
19
+ options.separator( "" )
20
+ options.separator( "Options" )
17
21
  super
18
22
  end
19
23
 
20
24
  def do_execute( args )
21
25
  recipes = Recipe.all_recipes
22
26
  recipes.keys.sort.each do |name|
23
- say format( "%-20s - %s", name, recipes[name].short_description )
27
+ info( format( "%-20s - %s", name, recipes[name].short_description ) )
24
28
  end
25
29
 
26
30
  return 0
@@ -1,9 +1,17 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'mj/tools/editor'
4
+
1
5
  require 'build-tool/vcs/git'
2
6
  require 'build-tool/vcs/git-svn'
3
7
  require 'build-tool/vcs/svn'
4
8
  require 'build-tool/vcs/archive'
5
9
  require 'build-tool/vcs/mercurial'
6
10
 
11
+ require 'build-tool/model/module'
12
+ require 'build-tool/model/feature'
13
+ require 'build-tool/model/setting'
14
+
7
15
  require 'build-tool/build-system/cmake'
8
16
  require 'build-tool/build-system/qt'
9
17
  require 'build-tool/build-system/autoconf'
@@ -17,16 +25,39 @@ module BuildTool
17
25
 
18
26
  class Configuration
19
27
 
20
- attr_reader :recipe
28
+ def self.edit( only = [] )
29
+
30
+ settings = BuildTool::Setting::export(
31
+ BuildTool::Application.instance.configuration.settings,
32
+ only )
33
+
34
+ editor = MJ::Tools::TmpFileEditor.new( YAML::dump( settings ) )
35
+
36
+ editor.edit()
37
+ if not Pathname.new( editor.path() ).exist?
38
+ info( "File deleted!" )
39
+ return 0
40
+ end
41
+ values = YAML::load( File.open( editor.path(), 'r:UTF-8' ) )
42
+
43
+ BuildTool::Setting::import(
44
+ BuildTool::Application.instance.configuration.settings,
45
+ values )
46
+ return 0
47
+ end
48
+
49
+ attr_accessor :recipe
21
50
  attr_reader :modules
22
51
  attr_reader :environments
23
52
  attr_reader :features
24
53
  attr_accessor :active_feature
54
+ attr_reader :settings
25
55
 
26
56
  def log_directory
27
57
  return @log_directory if @log_directory
28
58
  raise BuildTool::ConfigurationError, "No log directory configured"
29
59
  end
60
+
30
61
  def log_directory=( path )
31
62
  path = Pathname.new( path.sub( /\$HOME/, '~' ) )
32
63
  if path.to_s[0] != '~' and path.relative?
@@ -84,8 +115,12 @@ def add_sshkey( key )
84
115
  @sshkey[key.name] = key
85
116
  end
86
117
 
87
- def initialize( recipe = nil )
88
- @recipe = recipe
118
+ def add_setting( s )
119
+ @settings[s.name] = s
120
+ end
121
+
122
+ def initialize()
123
+ @recipe = nil
89
124
  @server = {}
90
125
  @log_directory = nil
91
126
  @environments = {}
@@ -96,6 +131,7 @@ def initialize( recipe = nil )
96
131
  @sshkey = {}
97
132
  @active_feature = nil
98
133
  @features = {}
134
+ @settings = {}
99
135
  end
100
136
 
101
137
  def vcs( name )
@@ -151,6 +187,55 @@ def add_build_system( bs )
151
187
  return @build_system[bs.name] = bs
152
188
  end
153
189
 
190
+ def save
191
+ logger.debug "Saving features to database."
192
+ @features.each do |name, f|
193
+ logger.debug2( " Feature %s" % [ f.name ] ) if f.changed?
194
+ f.save! if f.changed?
195
+ end
196
+ logger.debug "Saving modules to database."
197
+ @modules.each do |m|
198
+ logger.debug2( " Module %s" % [ m.name ] ) if m.changed?
199
+ m.save! if m.changed?
200
+ end
201
+ logger.debug "Saving settings to database."
202
+ @settings.each do |n, s|
203
+ logger.debug2( " Setting %s: %s" % [ s.name, s.value ] ) if s.changed?
204
+ s.save! if s.changed?
205
+ end
206
+ end
207
+
208
+ def load
209
+ logger.debug "Loading features from database."
210
+ BuildTool::Feature.all.each do |f|
211
+ logger.debug2 " - Feature %s" % [ f.name ]
212
+ add_feature( f )
213
+ end
214
+ logger.debug "Loading modules from database."
215
+ BuildTool::Module.all.each do |m|
216
+ logger.debug2 " - Module %s" % [ m.name ]
217
+ add_module( m )
218
+ end
219
+ logger.debug "Loading settings from database."
220
+ BuildTool::Setting.all.each do |s|
221
+ logger.debug2 " - Setting %s: %s" % [ s.name, s.value ]
222
+ add_setting( s )
223
+ end
224
+ end
225
+
226
+ def truncate
227
+ logger.debug "Deleting all features from database."
228
+ BuildTool::Feature.delete_all()
229
+ @features = {}
230
+ logger.debug "Deleting all modules from database."
231
+ BuildTool::Module.delete_all()
232
+ @module = {}
233
+ @modules = []
234
+ logger.debug "Deleting all settings from database."
235
+ BuildTool::Setting.delete_all()
236
+ @settings = {}
237
+ end
238
+
154
239
  end # Configuration
155
240
 
156
241
  end # module BuildTool
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  require 'mj/tools/subprocess'
2
4
 
3
5
  module BuildTool
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  module BuildTool
2
4
 
3
5
  # Base class for all BuildTool Errors
@@ -6,4 +8,7 @@ class Error < StandardError; end
6
8
  # A configuration error happened.
7
9
  class ConfigurationError < Error; end
8
10
 
11
+ # A parser error happend
12
+ class ParseError < Error; end
13
+
9
14
  end
@@ -1,183 +1,5 @@
1
- require 'sequel'
2
- require 'ansi'
3
-
4
- module BuildTool
5
-
6
- #
7
- # Provide method to add and retrieve entries from the history
8
- #
9
- module History
10
-
11
- module StateHelper
12
-
13
- # ATTENTION
14
- #
15
- # Ansi::Code and Sequel don't like each other. Do not include Ansi::Code here.
16
-
17
- # Needed for both Module and Command History
18
- STARTED = 0
19
- CANCELED_BY_USER = 1
20
- FINISHED_SUCCESSFUL = 2
21
- FINISHED_WITH_ERRORS = 3
22
-
23
- def state_str
24
- case self.state
25
- when STARTED
26
- "STARTED"
27
- when CANCELED_BY_USER
28
- ANSI::Code.red { "CANCELED" }
29
- when FINISHED_SUCCESSFUL
30
- ANSI::Code.green { "SUCCESS" }
31
- when FINISHED_WITH_ERRORS
32
- ANSI::Code.red { "ERRORS" }
33
- else
34
- "#{self.state.to_s}?"
35
- end
36
- end
37
-
38
- module ClassMethods
39
- end
40
-
41
- def self.included( klass )
42
- klass.extend ClassMethods
43
- end
44
-
45
- end
46
-
47
- # Represents a log entry for a command.
48
- class CommandLog < Sequel::Model( :command_logs )
49
-
50
- include StateHelper
51
-
52
- # A command can have many module events
53
- one_to_many :module_logs, :order => :id
54
-
55
- def duration
56
- if self.finished_at
57
- dur = self.finished_at - self.started_at
58
- "%02d:%02d" % [ dur.to_i / 60, (dur% 60 ).to_i ]
59
- else
60
- "-----"
61
- end
62
- end
63
-
64
- # Call this if the command is finished. [:finished] will be set to Time.now,
65
- # [:state] to the given value and the object is saved.
66
- def finished( state )
67
- self.finished_at = Time.now
68
- self.state = state
69
- save
70
- end
71
-
72
- # Call this if the command is started. [:started] will be set to Time.now, [:state]
73
- # to STARTED and the object is saved.
74
- def started
75
- self.started_at = Time.now
76
- save
77
- end
78
-
79
- # Sequel Hook
80
- #
81
- # Make sure a finished command has one of the accepted finished states.
82
- def before_update
83
- super
84
- if !self.finished_at.nil?
85
- raise StandardError, "Wrong state for finished Command" if ! [ FINISHED_SUCCESSFUL, FINISHED_WITH_ERRORS, CANCELED_BY_USER ].include? self.state
86
- end
87
- end
88
-
89
- def before_destroy
90
- self.module_logs_dataset.delete
91
- super
92
- end
93
-
94
- # Class Methods
95
- class << self
96
-
97
- # Loads the most recents entry from the database
98
- def most_recent( offset = nil )
99
- if offset.nil?
100
- return where( "id = (SELECT MAX(id) FROM #{table_name})" ).first
101
- else
102
- return order( :id.desc ).limit( 1, offset ).first
103
- end
104
- end # def most_recent
105
-
106
- # Get the last :count issued commands
107
- #
108
- # @param [Integer] count Number of commands to return
109
- # @return [Array] List containing the last count issued commands
110
- def last( count = 50 )
111
- order(:id.desc).limit(count).all
112
- end
113
-
114
- # Get the last :count command entries containing module :modname.
115
- def last_by_module( modname, count = 3 )
116
- where( 'id in ( select distinct command_log_id from module_logs where module = ? )', modname ).order( :id.desc ).first( count );
117
- end
118
-
119
- # Get all commands older than :days
120
- def older_than
121
- where( 'finished_at < ?', Date.today - 10 )
122
- end
123
-
124
-
125
- end # ClassMethods
126
-
127
- end
128
-
129
- # Represents a module event.
130
- #
131
- # A module event is updating, compiling etc. a module.
132
- class ModuleLog < Sequel::Model( :module_logs )
133
-
134
- include StateHelper
135
-
136
- # A module event belongs to a command
137
- many_to_one :command_log
138
-
139
- def duration
140
- if self.finished_at
141
- dur = self.finished_at - self.started_at
142
- "%02d:%02d" % [ dur.to_i / 60, (dur% 60 ).to_i ]
143
- else
144
- "-----"
145
- end
146
- end
147
-
148
- # Call this if the command is finished. [:finished] will be set to Time.now,
149
- # [:state] to the given value and the object is saved.
150
- def finished( state )
151
- self.finished_at = Time.now
152
- self.state = state
153
- save
154
- end
155
-
156
- # Call this when the command is started. [:started] will be set to Time.now and
157
- # the object is saved.
158
- def started
159
- self.started_at = Time.now
160
- save
161
- end
162
-
163
- # Sequel Hook
164
- #
165
- # Make sure a finished command has one of the accepted finished states.
166
- def before_update
167
- super
168
- if !self.finished_at.nil?
169
- raise StandardError, "Wrong state for finished Command" if ! [ FINISHED_SUCCESSFUL, FINISHED_WITH_ERRORS, CANCELED_BY_USER ].include? self.state
170
- end
171
- end
172
-
173
- class << self
174
-
175
- end # class self
176
-
177
- end
178
-
179
- end # module BuildTool::History
180
-
181
- end # module BuildTool
1
+ # -*- coding: UTF-8 -*-
182
2
 
3
+ require 'build-tool/model/command_log'
4
+ require 'build-tool/model/module_log'
183
5
 
@@ -0,0 +1,93 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'build-tool/state_helper'
4
+ require 'build-tool/model/module_log'
5
+
6
+ require 'active_record'
7
+
8
+ module BuildTool module History
9
+
10
+ # Represents a log entry for a command.
11
+ class CommandLog < ActiveRecord::Base
12
+
13
+ include StateHelper
14
+
15
+ # A command can have many module events
16
+ has_many :module_logs, :order => :id, :dependent => :destroy
17
+
18
+ def duration
19
+ if self.finished_at
20
+ dur = self.finished_at - self.started_at
21
+ "%02d:%02d" % [ dur.to_i / 60, (dur% 60 ).to_i ]
22
+ else
23
+ "-----"
24
+ end
25
+ end
26
+
27
+ # Call this if the command is finished. [:finished] will be set to Time.now,
28
+ # [:state] to the given value and the object is saved.
29
+ def finished( state )
30
+ self.finished_at = Time.now
31
+ self.state = state
32
+ save!
33
+ end
34
+
35
+ # Call this if the command is started. [:started] will be set to Time.now, [:state]
36
+ # to STARTED and the object is saved.
37
+ def started
38
+ self.started_at = Time.now
39
+ save!
40
+ end
41
+
42
+ # Sequel Hook
43
+ #
44
+ # Make sure a finished command has one of the accepted finished states.
45
+ def before_update
46
+ super
47
+ if !self.finished_at.nil?
48
+ raise StandardError, "Wrong state for finished Command" if ! [ FINISHED_SUCCESSFUL, FINISHED_WITH_ERRORS, CANCELED_BY_USER ].include? self.state
49
+ end
50
+ end
51
+
52
+ # def before_destroy
53
+ # self.module_logs_dataset.delete
54
+ # super
55
+ # end
56
+
57
+ # Class Methods
58
+ class << self
59
+
60
+ # Loads the most recents entry from the database
61
+ def most_recent( offset = nil )
62
+ if offset.nil?
63
+ return where( "id = (SELECT MAX(id) FROM #{table_name})" ).first
64
+ else
65
+ return order( 'id DESC' ).limit( 1 ).offset( offset ).first
66
+ end
67
+ end # def most_recent
68
+
69
+ # Get the last :count issued commands
70
+ #
71
+ # @param [Integer] count Number of commands to return
72
+ # @return [Array] List containing the last count issued commands
73
+ def last( count = 50 )
74
+ order( 'id DESC' ).limit(count).all
75
+ end
76
+
77
+ # Get the last :count command entries containing module :modname.
78
+ def last_by_module( modname, count = 3 )
79
+ where( 'id in ( select distinct command_log_id from module_logs where module = ? )', modname ).order( 'id DESC' ).first( count );
80
+ end
81
+
82
+ # Get all commands older than :days
83
+ def older_than
84
+ where( 'finished_at < ?', Date.today - 10 )
85
+ end
86
+
87
+
88
+ end # ClassMethods
89
+
90
+ end end # class CommandLog
91
+
92
+ end
93
+