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
@@ -0,0 +1,30 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ module BuildTool
4
+
5
+ class Version
6
+
7
+ def initialize( major, minor, patch, rc = nil )
8
+ @MAJOR_VERSION = major
9
+ @MINOR_VERSION = minor
10
+ @PATCH_LEVEL = patch
11
+ @RC = rc
12
+ end
13
+
14
+ def to_s()
15
+ version = '%d.%d.%d' % [ @MAJOR_VERSION, @MINOR_VERSION, @PATCH_LEVEL ]
16
+ if not @RC.nil?
17
+ version += '.rc%d' % @RC
18
+ end
19
+ return version
20
+ end
21
+
22
+ # During a minor release build-tool guarantess recipe compatibility.
23
+ def recipe_version()
24
+ return '%s.%s' % [ @MAJOR_VERSION, @MINOR_VERSION ]
25
+ end
26
+
27
+ end
28
+
29
+ VERSION = Version.new( 0, 6, 0, 1 )
30
+ end
data/lib/mj/error.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  #
2
4
  #
3
5
  module MJ
data/lib/mj/logging.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  require 'ansi/code'
2
4
  require 'logging'
3
5
 
@@ -0,0 +1,73 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ # A mixin that implements inheriting values from a parent module. The parent object can be set in
4
+ # two ways.
5
+ #
6
+ # object.parent = parent
7
+ # object.parent = lambda { some_function_returning_parent() }
8
+ #
9
+ # Set the inherited values with
10
+ #
11
+ # class MyClass
12
+ #
13
+ # include GetValuesFromParent
14
+ #
15
+ # inheritated_attr_accessor :myattr
16
+ # inheritated_attr_accessor :myotherattr.
17
+ #
18
+ # end
19
+
20
+ module MJ module Mixins
21
+
22
+ module InheritedAttributes
23
+
24
+ # Class methods
25
+ module ClassMethods
26
+
27
+ def inherited_attr_accessor( name )
28
+ class_eval <<-EOF
29
+
30
+ attr_writer :#{name}
31
+
32
+ def #{name}
33
+ return @#{name} if @#{name}
34
+ return parent.#{name} if @parent
35
+ return nil
36
+ end
37
+ EOF
38
+ end
39
+
40
+ end
41
+
42
+ # Instance methods
43
+ module InstanceMethods
44
+
45
+ def initialize( *args )
46
+ @parent = nil
47
+ end
48
+
49
+ # Set the parent object.
50
+ attr_writer :parent
51
+
52
+ # Get the parent object.
53
+ def parent
54
+ return nil if not @parent
55
+ if @parent.is_a?( Proc )
56
+ @parent.call()
57
+ else
58
+ @parent
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ # Include
65
+ def self.included( receiver )
66
+ receiver.extend ClassMethods
67
+ receiver.send :include, InstanceMethods
68
+ end
69
+
70
+ end # module InheritedAttributes
71
+
72
+ end end # module MJ::InheritedAttributes
73
+
@@ -0,0 +1,34 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'tempfile'
4
+
5
+ module MJ; module Tools
6
+
7
+ # A class that puts the given content in a tmpfile, opens an editor for the user to play with
8
+ # it. After the user closed the editor it will give back the new content.
9
+ class TmpFileEditor
10
+
11
+ def initialize( content )
12
+ @file = Tempfile.new( [ 'configuration', '.yaml' ] )
13
+ # First write the old content into the file
14
+ @file.write( content )
15
+ @file.close()
16
+ end
17
+
18
+ def editor()
19
+ "gvim -f"
20
+ end
21
+
22
+ def edit()
23
+ system( "#{editor()} #{@file.path}" )
24
+ return $? == 0
25
+ end
26
+
27
+ def path()
28
+ @file.path()
29
+ end
30
+
31
+ end
32
+
33
+
34
+ end; end # module MJ::Tools
data/lib/mj/tools/ssh.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  require 'mj/tools/subprocess.rb'
2
4
 
3
5
  module MJ; module Tools
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  module MJ; module Tools
2
4
 
3
5
  module SubProcess
@@ -11,7 +13,6 @@ module ClassMethods
11
13
  # Executes the given command and yields each line of output.
12
14
  # Returns +$?+ .
13
15
  def execute( command, wd = ENV["HOME"], env = nil )
14
- cwd ||= Dir.getwd
15
16
  logger.trace "(#{wd}) > #{command} 2>&1"
16
17
  if !$noop
17
18
  adjust_environment( wd, env ) {
data/lib/mj/vcs/git.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  require 'mj/tools/subprocess'
2
4
  require 'mj/error'
3
5
 
@@ -5,6 +7,16 @@
5
7
  #
6
8
  module MJ; module VCS; module Git;
7
9
 
10
+ @git_available = nil
11
+
12
+ # Is the git executable available?
13
+ def self.git_available?()
14
+ return @git_available unless @git_available.nil?
15
+ %x( git --version 2>&1 )
16
+ @git_available = $?.success?
17
+ return @git_available
18
+ end
19
+
8
20
  # Thrown if git signals a problem
9
21
  class GitError < MJ::Error; end
10
22
 
@@ -34,12 +46,12 @@ def checkout(opts)
34
46
  end
35
47
 
36
48
  # Clone a repository
37
- def clone(url)
49
+ def clone(url, branch = 'master' )
38
50
  # Initialize the repository
39
51
  init(url)
40
52
  remote_add(url, "origin")
41
53
  fetch("origin")
42
- checkout("-b master origin/master")
54
+ checkout("-b master origin/#{branch}")
43
55
  end # def clone
44
56
 
45
57
  # Check if the repository exists
data/lib/mj/visitor.rb CHANGED
@@ -1,8 +1,11 @@
1
+ # -*- coding: UTF-8 -*-
2
+
1
3
  module MJ;
2
4
 
3
5
  class Visitable
4
6
 
5
7
  def accept( visitor )
8
+ raise "#{visitor.class} is not a visitable class" if visitor.instance_of? VisitorBase
6
9
  method_name = nil
7
10
  klass = self.class.ancestors.find do |ancestor|
8
11
  method_name = "visit_#{ancestor.name.split('::')[-1]}"
@@ -18,4 +21,23 @@ def accept( visitor )
18
21
 
19
22
  end
20
23
 
24
+
25
+ # Base class for all Visitors.
26
+ class VisitorBase
27
+
28
+ # The configuration object to fill with our parse results.
29
+ attr_reader :configuration
30
+
31
+ class ArgumentsError < StandardError
32
+ end
33
+
34
+ def initialize( configuration )
35
+ @configuration = configuration
36
+ end
37
+
38
+ def visit_Object( object )
39
+ raise "#{self.class}: Not a visitor for #{object.class}!"
40
+ end
41
+
42
+ end # class VisitorBase
21
43
  end
data/tasks/db.rake ADDED
@@ -0,0 +1,36 @@
1
+ # Tasks to work with the databases
2
+
3
+
4
+
5
+ namespace :db do
6
+
7
+ desc "Migrate the given database"
8
+ task :up, :database, :steps do |t, args|
9
+ database = args[:database]
10
+ steps = ( args[:steps] || 1 ).to_i
11
+
12
+ raise "No database specified" unless args[:database]
13
+
14
+ require 'active_record'
15
+
16
+ ActiveRecord::Base.establish_connection(
17
+ :adapter => 'sqlite3',
18
+ :database => args[:database] )
19
+ ActiveRecord::Migrator.forward( 'db/migrations', steps )
20
+ end
21
+
22
+ desc "Rollback the given database"
23
+ task :down, :database, :steps do |t, args|
24
+ database = args[:database]
25
+ steps = ( args[:steps] || 1 ).to_i
26
+
27
+ raise "No database specified" unless args[:database]
28
+
29
+ require 'active_record'
30
+
31
+ ActiveRecord::Base.establish_connection(
32
+ :adapter => 'sqlite3',
33
+ :database => args[:database] )
34
+ ActiveRecord::Migrator.rollback( 'db/migrations', steps )
35
+ end
36
+ end
data/tasks/racc.rake ADDED
@@ -0,0 +1,14 @@
1
+ # Find all racc files and generate the parser.
2
+ #
3
+ RACC_FILES = FileList[ 'lib/**/*.y'].ext( '.rb' )
4
+
5
+
6
+ namespace :bt do
7
+
8
+ desc "Generate parser with racc"
9
+ task :racc => RACC_FILES
10
+ rule '.rb' => '.y' do |target|
11
+ sh "racc -g #{target.source} -o #{target.name}"
12
+ end
13
+
14
+ end
data/tasks/rdoc.rake ADDED
@@ -0,0 +1,8 @@
1
+ require 'yard'
2
+
3
+ YARD::Rake::YardocTask.new do |t|
4
+ t.files = ['lib/**/*.rb']
5
+ # t.options = [] -> see .yardopts
6
+ t.name = 'doc'
7
+ end
8
+
@@ -0,0 +1,14 @@
1
+ # Find all racc files and generate the parser.
2
+ #
3
+ REXICAL_FILES = FileList[ 'lib/**/*.rex'].ext( '.rb' )
4
+
5
+ namespace :bt do
6
+
7
+ desc "Generate lexer with rexical"
8
+ task :rexical => REXICAL_FILES
9
+ rule '.rb' => '.rex' do |target|
10
+ sh "rex #{target.source} -o #{target.name}"
11
+ end
12
+
13
+ end
14
+
data/tasks/test.rake ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new('test') do |t|
4
+ t.pattern = 'test/**/*_test.rb'
5
+ t.ruby_opts=[ "-Itest" ]
6
+ end
7
+ task 'test' => 'bt:genall'
8
+
9
+
10
+ Rake::TestTask.new('test:unit') do |t|
11
+ t.pattern = 'test/unit/*_test.rb'
12
+ t.ruby_opts=[ "-Itest" ]
13
+ end
14
+ task 'test:unit' => 'bt:genall'
15
+
16
+ Rake::TestTask.new('test:integration') do |t|
17
+ t.pattern = 'test/integration/*_test.rb'
18
+ t.ruby_opts=[ "-Itest" ]
19
+ end
20
+ task 'test:integration' => 'bt:genall'
21
+
@@ -0,0 +1,88 @@
1
+ require 'test_helper.rb'
2
+
3
+ setup_database()
4
+
5
+ require 'build-tool/model/command_log'
6
+ require 'build-tool/model/module'
7
+
8
+ class HistoryTest < ActiveSupport::TestCase
9
+
10
+ test "Module/Command Logs successfully created" do
11
+
12
+ # Create some modules.
13
+ kdelibs = BuildTool::Module.new( :name => 'KDE/kdelibs' )
14
+ kdelibs.save!()
15
+
16
+ kdebase_runtime = BuildTool::Module.new( :name => 'KDE/kdebase/runtime' )
17
+ kdebase_runtime.save!()
18
+
19
+ kdebase_workspace = BuildTool::Module.new( :name => 'KDE/kdebase/workspace' )
20
+ kdebase_workspace.save!()
21
+
22
+ # Create a command history touching alls three modules.
23
+ cmd = BuildTool::History::CommandLog.new(
24
+ :command => 'first_command',
25
+ :logdir => '/home/build-tool/log')
26
+ cmd.started()
27
+
28
+ assert( cmd.id )
29
+ assert( kdelibs.id )
30
+
31
+ cmd.module_logs.build(
32
+ :module => kdelibs,
33
+ :event => "build",
34
+ :logfile => "build.log" )
35
+
36
+ cmd.module_logs.build(
37
+ :module => kdebase_runtime,
38
+ :event => "fetch",
39
+ :logfile => "fetch.log" )
40
+
41
+ cmd.module_logs.build(
42
+ :module => kdebase_runtime,
43
+ :event => "build",
44
+ :logfile => "build.log" )
45
+
46
+ cmd.module_logs.build(
47
+ :module => kdebase_workspace,
48
+ :event => "build",
49
+ :logfile => "build.log" )
50
+
51
+ cmd.finished( BuildTool::History::CommandLog::FINISHED_SUCCESSFUL )
52
+ cmd = nil
53
+
54
+ # Check all module logs are found
55
+ cmd = BuildTool::History::CommandLog.where( :command => 'first_command' ).first()
56
+ assert( cmd )
57
+ assert_equal( 4, cmd.module_logs.count() )
58
+ assert_equal( 'KDE/kdelibs', cmd.module_logs[0].module.name )
59
+ assert_equal( 'KDE/kdebase/runtime', cmd.module_logs[1].module.name )
60
+ assert_equal( 'KDE/kdebase/runtime', cmd.module_logs[2].module.name )
61
+ assert_equal( 'KDE/kdebase/workspace', cmd.module_logs[3].module.name )
62
+
63
+ # Now check from the module site.
64
+ mod = BuildTool::Module.where( :name => 'KDE/kdebase/runtime' ).first
65
+ assert( mod )
66
+ assert_equal( 'KDE/kdebase/runtime', mod.name )
67
+ assert_equal( 2, mod.module_logs.count() )
68
+
69
+ # Delete the module and check it takes the modules logs with it.
70
+ mod.destroy()
71
+ mod = nil
72
+
73
+ # Check all module logs are found but the kdebase/runtime ones.
74
+ cmd = BuildTool::History::CommandLog.where( :command => 'first_command' ).first()
75
+ assert( cmd )
76
+ assert_equal( 2, cmd.module_logs.count() )
77
+ assert_equal( 'KDE/kdelibs', cmd.module_logs[0].module.name )
78
+ assert_equal( 'KDE/kdebase/workspace', cmd.module_logs[1].module.name )
79
+
80
+ # Now delete the command log and check all module and command logs are gone
81
+ cmd.destroy()
82
+ assert_equal( 0, BuildTool::History::ModuleLog::count() )
83
+ assert_equal( 0, BuildTool::History::CommandLog::count() )
84
+
85
+ end
86
+
87
+ end # HistoryTest
88
+
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ setup_database()
4
+
5
+ require 'build-tool/application'
6
+ require 'build-tool/recipe'
7
+
8
+ class TestParser < ActiveSupport::TestCase
9
+
10
+ def setup
11
+ create_parser()
12
+ end
13
+
14
+ def create_parser
15
+ @configuration = BuildTool::Configuration.new()
16
+ @configuration.truncate()
17
+ @configuration.add_setting( BuildTool::Setting.new( :name => 'BUILD_PREFIX', :value => '$HOME/bld' ) )
18
+ @configuration.add_setting( BuildTool::Setting.new( :name => 'PREFIX', :value => '/opt' ) )
19
+
20
+ @recipe = BuildTool::Recipe.new( 'test', find = false )
21
+
22
+ end
23
+
24
+ test "Substitutes settings" do
25
+ assert_nothing_raised() do
26
+ @recipe.load_from_string( <<-EOF, @configuration )
27
+ log-directory "<%= settings['BUILD_PREFIX'] %>/log"
28
+ EOF
29
+ end
30
+
31
+ assert_equal( "#{ENV['HOME']}/bld/log", @configuration.log_directory().to_s() )
32
+ end
33
+
34
+ end
35
+
36
+