build-tool 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data.tar.gz.sig +3 -0
  2. data/History.txt +7 -0
  3. data/Manifest.txt +51 -0
  4. data/PostInstall.txt +3 -0
  5. data/README.rdoc +55 -0
  6. data/Rakefile +30 -0
  7. data/TODO +2 -0
  8. data/bin/kde-build.rb +21 -0
  9. data/config/website.yml +2 -0
  10. data/config/website.yml.sample +2 -0
  11. data/lib/kde-build.rb +18 -0
  12. data/lib/kde-build/application.rb +258 -0
  13. data/lib/kde-build/build_system.rb +26 -0
  14. data/lib/kde-build/build_system/autoconf.rb +109 -0
  15. data/lib/kde-build/build_system/base.rb +132 -0
  16. data/lib/kde-build/build_system/cmake.rb +82 -0
  17. data/lib/kde-build/build_system/qtcopy.rb +125 -0
  18. data/lib/kde-build/command.rb +30 -0
  19. data/lib/kde-build/command/build.rb +119 -0
  20. data/lib/kde-build/command/fetch.rb +28 -0
  21. data/lib/kde-build/command/help.rb +71 -0
  22. data/lib/kde-build/command/info.rb +42 -0
  23. data/lib/kde-build/command/version.rb +43 -0
  24. data/lib/kde-build/configuration.rb +186 -0
  25. data/lib/kde-build/exception.rb +6 -0
  26. data/lib/kde-build/metaaid.rb +18 -0
  27. data/lib/kde-build/module.rb +203 -0
  28. data/lib/kde-build/module_configuration.rb +107 -0
  29. data/lib/kde-build/moduleregistry.rb +85 -0
  30. data/lib/kde-build/subprocess.rb +82 -0
  31. data/lib/kde-build/tools/ctags.rb +34 -0
  32. data/lib/kde-build/tools/logging.rb +49 -0
  33. data/lib/kde-build/tools/make.rb +58 -0
  34. data/lib/kde-build/tools/ssh.rb +47 -0
  35. data/lib/kde-build/vcs.rb +26 -0
  36. data/lib/kde-build/vcs/base.rb +81 -0
  37. data/lib/kde-build/vcs/git-svn.rb +133 -0
  38. data/lib/kde-build/vcs/git.rb +96 -0
  39. data/lib/kde-build/vcs/svn.rb +105 -0
  40. data/script/console +10 -0
  41. data/script/destroy +14 -0
  42. data/script/generate +14 -0
  43. data/script/txt2html +71 -0
  44. data/test.yaml.tmpl +552 -0
  45. data/test/test_helper.rb +12 -0
  46. data/test/test_kde-build.rb +11 -0
  47. data/test/test_vcs_svn.rb +44 -0
  48. data/website/index.html +84 -0
  49. data/website/index.txt +59 -0
  50. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  51. data/website/stylesheets/screen.css +159 -0
  52. data/website/template.html.erb +50 -0
  53. metadata +171 -0
  54. metadata.gz.sig +0 -0
@@ -0,0 +1,6 @@
1
+ module BuildTool
2
+
3
+ class BuildToolError < Exception
4
+ end
5
+
6
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ class Object
4
+
5
+ # The hidden singleton lurks behind everyone
6
+ def metaclass; class << self; self; end; end
7
+ def meta_eval &blk; metaclass.instance_eval( &blk ); end
8
+
9
+ # Adds methods to a metaclass
10
+ def meta_def name, &blk
11
+ meta_eval { define_method name, &blk }
12
+ end
13
+
14
+ # Defines an instance method within a class
15
+ def class_def name, &blk
16
+ class_eval { define_method name, &blk }
17
+ end
18
+ end
@@ -0,0 +1,203 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'kde-build/tools/ssh.rb'
4
+ require 'kde-build/tools/logging.rb'
5
+
6
+ module BuildTool
7
+
8
+ class ConfigureError < Exception
9
+ end
10
+
11
+ class BuildError < Exception
12
+ end
13
+
14
+ class Module
15
+
16
+ def initialize(config)
17
+ @config = config
18
+ @build_system = nil
19
+ @vcs = nil
20
+ end
21
+
22
+ def activate_ssh_key
23
+ # No key, no cookies
24
+ return if !@config.ssh_key
25
+
26
+ ssh = MJ::Tools::SSH.new
27
+ if !ssh.has_key? ssh_key
28
+ ssh.add_key(ssh_file)
29
+ end
30
+ end
31
+
32
+ def name
33
+ @config.name
34
+ end
35
+
36
+ # The build directory
37
+ def build_directory
38
+ "#{workdir}/bld/#{local_path}"
39
+ end
40
+
41
+ def local_path
42
+ @local_path = @config.local_path || @config.remote_path
43
+ end
44
+
45
+ def build( install )
46
+ $log.info("Compiling")
47
+ rc = nil
48
+ while_logging_to( name, "50_build" ) do
49
+ rc =
50
+ if install
51
+ build_system.make( "install" )
52
+ else
53
+ build_system.make
54
+ end
55
+
56
+ if rc != 0
57
+ raise BuildError, "make returned error code #{rc}"
58
+ end
59
+ $log.info( "successfully built" )
60
+ end
61
+ end
62
+
63
+ # The build system
64
+ def build_system
65
+ if not @build_system
66
+ if not @config.build_system
67
+ klass = BuildTool::BuildSystem::Registry.guess( source_directory )
68
+ if !klass
69
+ raise ModuleError, "Failed to guess the build system for #{name}"
70
+ end
71
+ else
72
+ klass = BuildTool::BuildSystem::get(@config.build_system.name)
73
+ end
74
+ @build_system = klass.new( self )
75
+ @build_system.configuration = @config.build_system
76
+ end
77
+ @build_system
78
+ end
79
+
80
+
81
+ def remove_build_directory
82
+ $log.info("removing #{build_directory}")
83
+ build_system.remove_build_directory
84
+ end
85
+
86
+
87
+ # Configure the module
88
+ def reconfigure( clean = false )
89
+ $log.info("Reconfiguring")
90
+ while_logging_to( name, "30_configure" ) do
91
+ if !$noop and !vcs.checkedout?
92
+ raise ConfigureError, "Module is not checked out."
93
+ end
94
+ rc = build_system.reconfigure( clean )
95
+ if rc != 0
96
+ raise ConfigureError, "configure returned error code #{rc}"
97
+ end
98
+ end
99
+ end
100
+
101
+ # Configure the module
102
+ def configure
103
+ $log.info("configuring")
104
+ while_logging_to( name, "30_configure" ) do
105
+ if !$noop and !vcs.checkedout?
106
+ raise ConfigureError, "Module is not checked out."
107
+ end
108
+ rc = build_system.configure
109
+ if rc != 0
110
+ raise ConfigureError, "configure returned error code #{rc}"
111
+ end
112
+ end
113
+ end
114
+
115
+ # Is the module already configured?
116
+ def configured?
117
+ if !vcs.checkedout?
118
+ return false
119
+ end
120
+ build_system.configured?
121
+ end
122
+
123
+ def checkedout?
124
+ vcs.checkedout?
125
+ end
126
+
127
+ def env
128
+ @config.env
129
+ end
130
+
131
+ def fetch
132
+ $log.info("Fetching from #{remote_path}")
133
+ while_logging_to( name, "20_fetch" ) do
134
+ vcs.fetch
135
+ end
136
+ end
137
+
138
+ def init
139
+ $log.info("Initializing #{local_path} from #{remote_path}")
140
+ while_logging_to( name, "10_initialize" ) do
141
+ vcs.init
142
+ end
143
+ end
144
+
145
+ def ssh_key
146
+ return @config.ssh_key
147
+ end
148
+
149
+ def ssh_file
150
+ return @config.ssh_file
151
+ end
152
+
153
+ # The root directory for the +/bld+, +/src+ and +/log+ directories
154
+ def workdir
155
+ Application::instance.workdir
156
+ end
157
+
158
+ def rebase
159
+ $log.info("rebasing")
160
+ while_logging_to( name, "40_rebase" ) do
161
+ vcs.rebase
162
+ end
163
+ end
164
+
165
+ # The absolute remote path
166
+ def remote_path
167
+ "#{repository}/#{@config.remote_path}"
168
+ end
169
+
170
+ # The repository url
171
+ def repository
172
+ @config.repository
173
+ end
174
+
175
+ def prefix
176
+ @config.prefix
177
+ end
178
+
179
+ # The absolute source directory.
180
+ def source_directory
181
+ "#{workdir}/src/#{local_path}"
182
+ end
183
+
184
+ # reimplement
185
+ def to_yaml_type
186
+ "!michael-jansen.biz,2009-01-01/Module"
187
+ end
188
+
189
+ # #########
190
+ # protected
191
+ # #########
192
+
193
+ def vcs
194
+ if ! @vcs
195
+ @vcs = VCS::get(@config.vcs.name).new( remote_path, source_directory )
196
+ @vcs.configuration = @config.vcs
197
+ end
198
+ @vcs
199
+ end
200
+
201
+ end
202
+
203
+ end
@@ -0,0 +1,107 @@
1
+ require 'kde-build/configuration'
2
+ require 'kde-build/build_system'
3
+ require 'kde-build/module'
4
+ require 'kde-build/moduleregistry.rb'
5
+ require 'kde-build/vcs'
6
+
7
+ require 'yaml'
8
+
9
+ module BuildTool
10
+
11
+ class ModuleConfiguration
12
+
13
+ include MJ::Configuration::Configurable
14
+
15
+ option( "repository", "Remote repository url" ).
16
+ required
17
+
18
+ option( "ssh-key", "ssh-key for the repository" )
19
+ option( "ssh-file", "ssh-file for the repository" )
20
+
21
+ option( "name", "Name of the module" ).
22
+ required
23
+
24
+ option( "vcs", "VCS used for the module. # TODO" ).
25
+ on_write {
26
+ |val|
27
+ if val.instance_of?( String )
28
+ val = VCS::get( val ).config.new
29
+ elsif val.instance_of?( Array )
30
+ a = val.inject([]) {
31
+ |arr, v|
32
+ v.each_pair {
33
+ |val, key|
34
+ arr << val << key
35
+ }
36
+ arr
37
+ }
38
+ a = Hash[*a]
39
+ val = VCS::get(a['name']).config.new
40
+ val.parse(a)
41
+ else
42
+ throw :todo
43
+ end
44
+ val
45
+ }
46
+
47
+ option( "build-system", "Build System" ).
48
+ on_write {
49
+ |val|
50
+ if val.instance_of?( String )
51
+ val = BuildSystem::get( val ).config.new
52
+ elsif val.instance_of?( Array )
53
+ a = val.inject([]) {
54
+ |arr, v|
55
+ v.each_pair {
56
+ |val, key|
57
+ arr << val << key
58
+ }
59
+ arr
60
+ }
61
+ a = Hash[*a]
62
+ val = BuildSystem::get(a['name']).config.new
63
+ val.parse(a)
64
+ else
65
+ throw :todo
66
+ end
67
+ val
68
+ }
69
+
70
+ option( "env", "Environment Settings" ).
71
+ on_write { |val|
72
+ h = Hash.new
73
+ MJ::Configuration::flatten_values val do
74
+ |k, v|
75
+ h[k] = v
76
+ end
77
+ h
78
+ }
79
+
80
+ option( "local-path", "Local path to build. Relative to <stage>/src" )
81
+
82
+ option( "remote-path", "Path to fetch from. Relative to <repository>" ).
83
+ required
84
+
85
+ option( "prefix", "Installation Directory" ).
86
+ required
87
+
88
+ def to_s
89
+ self.name
90
+ end
91
+ end
92
+
93
+
94
+ YAML.add_domain_type(
95
+ "michael-jansen.biz,2009", "ModuleConfiguration" ) {
96
+ |type, val|
97
+ mc = ModuleConfiguration.new
98
+ MJ::Configuration::flatten_values val do
99
+ |k, v|
100
+ mc.set( k, v )
101
+ end
102
+ mc.validate
103
+ ModuleRegistry.instance.register_module( Module.new( mc ) )
104
+ mc
105
+ }
106
+
107
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'singleton'
4
+
5
+ module BuildTool
6
+
7
+ class ConfigurationError < Exception
8
+ end
9
+
10
+ class ModuleRegistry
11
+
12
+ include Singleton
13
+
14
+ include MJ::Configuration::Configurable
15
+
16
+ include Singleton
17
+
18
+ @@packages = {}
19
+ def set( name, string )
20
+ @@packages[name] = string.to_s.split( / */ )
21
+ end
22
+
23
+ def self.resolve_package( string, &block )
24
+ name = string[1..-1]
25
+ if @@packages.has_key? name
26
+ return self.get_modules( @@packages[name], &block )
27
+ else
28
+ $log.error( "Unknown package #{string}" )
29
+ end
30
+ end
31
+
32
+ @@modules = []
33
+
34
+ def register_module( mod )
35
+ if self.class.module_by_name mod.name
36
+ raise ConfigurationError, "Two configurations for #{mod.name} found"
37
+ end
38
+ @@modules.push( [mod.name ,mod] )
39
+ end
40
+
41
+ def self.module_by_name( name )
42
+ @@modules.each do |v|
43
+ if v[0] == name
44
+ return v[1]
45
+ end
46
+ end
47
+ nil
48
+ end
49
+
50
+
51
+ def self.get_modules( args, &block )
52
+ if args.instance_of?( String )
53
+ if args[0,1] == ':'
54
+ self.resolve_package( args, &block )
55
+ # Check if we have a exact match
56
+ elsif mod = module_by_name(args)
57
+ yield mod
58
+ elsif args[-1,1] == '/'
59
+ found = false
60
+ @@modules.select{ |a| a[0].index(args) == 0}.each do |a|
61
+ found = true
62
+ yield a[1]
63
+ end
64
+ $log.error( "Unknown module #{args}" ) if !found
65
+ else
66
+ $log.error( "Unknown module #{args}" )
67
+ end
68
+ elsif args.instance_of?( Array )
69
+ args.map { |arg| get_modules( arg, &block ) }
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ YAML.add_domain_type(
76
+ "michael-jansen.biz,2009", "Packages" ) {
77
+ |type, val|
78
+ mr = ModuleRegistry.instance
79
+ MJ::Configuration::flatten_values val do
80
+ |k, v|
81
+ mr.set( k, v )
82
+ end
83
+ }
84
+
85
+ end
@@ -0,0 +1,82 @@
1
+ module MJ; module Tools
2
+
3
+ module SubProcess
4
+
5
+ module ClassMethods
6
+
7
+ # Executes command
8
+ #
9
+ # Executes the given command and yields each line of output.
10
+ # Returns +$?+ .
11
+ def execute( command, wd = nil, env = nil )
12
+ cwd ||= Dir.getwd
13
+ $log.cmd( "(#{wd}) > #{command} 2>&1" )
14
+ if !$noop
15
+ adjust_environment( wd, env ) {
16
+ IO.popen( "#{command} 2>&1" ) {
17
+ |f|
18
+ begin
19
+ while
20
+ line = f.readline
21
+ $log.cmdout( line.chomp )
22
+ yield line if block_given?
23
+ end
24
+ rescue EOFError:
25
+ # Expected. Do nothing
26
+ end
27
+ }
28
+ $log.cmdout( "= #{$?}" )
29
+ return $?
30
+ }
31
+ else
32
+ $log.cmdout( "= 0 # noop" )
33
+ return 0
34
+ end
35
+
36
+ end
37
+
38
+ #########
39
+ protected
40
+ #########
41
+
42
+ # Helper method to adjust LANG to "C"
43
+ def adjust_environment( wd=nil, env=nil, lang="C" )
44
+ if wd
45
+ cwd = Dir.getwd
46
+ Dir.chdir(wd)
47
+ end
48
+ # Set the environment the user wants
49
+ oldenv = Hash.new
50
+ if env
51
+ env.each do |var, value|
52
+ oldenv[var] = ENV[var]
53
+ ENV[var] = value
54
+ end
55
+ end
56
+ # Save old LANG setting and switch to 'C'
57
+ oldlang = ENV['LANG']
58
+ ENV['LANG'] = lang
59
+ yield
60
+ # Reset the old LANG setting
61
+ ENV['LANG'] = oldlang
62
+ # Reset our changes to ENV
63
+ oldenv.each do |var, value|
64
+ ENV[var] = value
65
+ end
66
+ # Reset the current working directory
67
+ if wd
68
+ Dir.chdir(cwd)
69
+ end
70
+ end
71
+ end
72
+
73
+ def self.included( klass )
74
+ klass.extend( ClassMethods )
75
+ end
76
+
77
+
78
+ end
79
+
80
+
81
+ end; end
82
+