mtbuild 0.0.1

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,46 @@
1
+ module MTBuild
2
+
3
+ module Utils
4
+
5
+ require 'rake'
6
+ require 'pathname'
7
+
8
+ def self.path_difference(root, subdir)
9
+ root_path = Pathname.new(root)
10
+ subdir_path = Pathname.new(subdir)
11
+ difference_path = subdir_path.relative_path_from(root_path)
12
+ difference = difference_path.to_path
13
+ return nil if difference.include? '..'
14
+ return '' if difference.eql? '.'
15
+ return difference
16
+ end
17
+
18
+ def self.expand_file_list(included_files, excluded_files, base_folder=nil)
19
+ file_list = FileList.new()
20
+
21
+ included_files = Utils.ensure_array(included_files).flatten.collect{|s| base_folder ? File.join(base_folder, s) : s}
22
+ file_list.include(included_files)
23
+
24
+ excluded_files = Utils.ensure_array(excluded_files).flatten.collect{|e| base_folder ? File.join(base_folder, e) : e}
25
+ file_list.exclude(excluded_files)
26
+
27
+ return file_list.to_ary.collect{|f| File.expand_path(f)}
28
+ end
29
+
30
+ def self.expand_folder_list(included_folders, base_folder=nil)
31
+ included_folders = Utils.ensure_array(included_folders).flatten.collect{|f| base_folder ? File.join(base_folder, f) : f}
32
+ return Dir.glob(included_folders).to_ary.reject{|f| !File.directory?f}.collect{|f| File.expand_path(f)}
33
+ end
34
+
35
+ def self.ensure_array(input)
36
+ input = [input] unless input.respond_to?(:to_ary)
37
+ return input
38
+ end
39
+
40
+ def self.merge_configurations(default, override)
41
+ return default.merge(override) {|key, old_value, new_value| if old_value.is_a? Hash and new_value.is_a? Hash then merge_configurations(old_value, new_value) else new_value end}
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,4 @@
1
+ module MTBuild
2
+ # The current MTBuild version.
3
+ VERSION = "0.0.1"
4
+ end
@@ -0,0 +1,54 @@
1
+ module MTBuild
2
+
3
+ # This is the base class for all versioner types.
4
+ class Versioner
5
+
6
+ def initialize(project_name, project_folder, output_folder, configuration_name, configuration)
7
+ @project_name = project_name
8
+ @project_folder = project_folder
9
+ @output_folder = output_folder
10
+ @configuration_name = configuration_name
11
+
12
+ check_configuration(configuration)
13
+
14
+ @versioner_name = configuration[:name]
15
+ end
16
+
17
+ # Create the actual Rake tasks that will perform the versioner's work
18
+ def create_version_tasks
19
+ fail "Versioner didn't provide create_version_tasks"
20
+ end
21
+
22
+ private
23
+
24
+ def check_configuration(configuration)
25
+ fail "error. No name specified for versioner in #{@project_name}:#{@configuration_name}" if configuration.fetch(:name, nil).nil?
26
+ end
27
+
28
+ @registered_versioners = {}
29
+
30
+ def self.register_versioner(versioner_name, versioner_class)
31
+ @registered_versioners[versioner_name] = versioner_class;
32
+ end
33
+
34
+ def self.create_versioner(project_name, project_folder, output_folder, configuration_name, versioner_configuration)
35
+ versioner_name = versioner_configuration.fetch(:name, nil)
36
+ fail "error: versioner name not specified for #{project_name}:#{configuration_name}." if versioner_name.nil?
37
+
38
+ versioner_class = @registered_versioners.fetch(versioner_name, nil)
39
+ if !versioner_class
40
+ versioner = File.join('mtbuild', 'versioners', versioner_name.to_s)
41
+ begin
42
+ require versioner
43
+ rescue LoadError
44
+ end
45
+ end
46
+ versioner_class = @registered_versioners.fetch(versioner_name, nil)
47
+ fail "error: version file #{versioner_name} could not be found." if versioner_class.nil?
48
+ return Object::const_get(versioner_class).new(project_name, project_folder, output_folder, configuration_name, versioner_configuration)
49
+ end
50
+
51
+ include Rake::DSL
52
+ end
53
+
54
+ end
@@ -0,0 +1,72 @@
1
+ module MTBuild
2
+ require 'mtbuild/versioner'
3
+
4
+ Versioner.register_versioner(:mt_std_version, 'MTBuild::VersionerMTStdVersion')
5
+
6
+ # This Versioner subclass can update files that follow the standard MindTribe version format.
7
+ class VersionerMTStdVersion < Versioner
8
+
9
+ def initialize(project_name, project_folder, output_folder, configuration_name, configuration)
10
+ super
11
+ @version_files = Utils.expand_file_list(configuration.fetch(:files, []), [], @project_folder)
12
+ end
13
+
14
+ # Create the actual Rake tasks that will perform the versioner's work
15
+ def create_version_tasks
16
+ namespace @configuration_name do
17
+ desc "Update version for '#{@project_name}' with configuration '#{@configuration_name}'"
18
+ @version_files.each do |file|
19
+ version_task = task :Version, [:major, :minor, :revision, :build, :version_string, :git_SHA] => file do |t, args|
20
+ args.with_defaults(:major => '', :minor => '', :revision => '', :build => '', :version_string => '', :git_SHA => '')
21
+ update_version(file, args.major, args.minor, args.revision, args.build, args.version_string, args.git_SHA)
22
+ puts "updated version in '#{file}'"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def check_configuration(configuration)
31
+ super
32
+ fail "No version files specified for #{@project_name}:#{@configuration_name}" if configuration.fetch(:files, nil).nil?
33
+ end
34
+
35
+ # This method searches through a file for version definitions of roughly the following format:
36
+ #
37
+ # #define xxxMAJOR 0
38
+ # #define xxxMINOR 0
39
+ # #define xxxREVISION 0
40
+ # #define xxxBUILD 0
41
+ # #define xxxVERSIONSTRING "0"
42
+ # #define xxxGITSHA "0000000000000000000000000000000000000000"
43
+ #
44
+ # The "xxx" can include almost any valid C/C++ identifier text as needed for the particular application. The spacing
45
+ # between the identifier and the defined value is flexible. The order of the definitions is not important and
46
+ # definitions can be repeated or omitted. For more detail on the exact search criteria, review the regular expressions
47
+ # below.
48
+ #
49
+ # When one or more of the above lines is found, the defined value is replaced by the respective value passed into this
50
+ # method.
51
+ def update_version(file_name, major=nil, minor=nil, revision=nil, build=nil, version_string=nil, git_SHA=nil)
52
+ matching_list = []
53
+
54
+ matching_list << [/(\s*#define\s.+?MAJOR\s*)(\S+?)(\s*.*$)/, "\\1#{major}\\3"] unless major.empty?
55
+ matching_list << [/(\s*#define\s.+?MINOR\s*)(.+?)(\s*$)/, "\\1#{minor}\\3"] unless minor.empty?
56
+ matching_list << [/(\s*#define\s.+?REVISION\s*)(.+?)(\s*$)/, "\\1#{revision}\\3"] unless revision.empty?
57
+ matching_list << [/(\s*#define\s.+?BUILD\s*)(.+?)(\s*$)/, "\\1#{build}\\3"] unless build.empty?
58
+ matching_list << [/(\s*#define\s.+?VERSIONSTRING\s*\")(.+?)(\"\s*$)/, "\\1#{version_string}\\3"] unless version_string.empty?
59
+ matching_list << [/(\s*#define\s.+?GITSHA\s*\")(.+?)(\"\s*$)/, "\\1#{git_SHA}\\3"] unless git_SHA.empty?
60
+
61
+ fail "Nothing to do. Please specify at least one version component to update." if matching_list.empty?
62
+
63
+ file_contents = File.read(file_name)
64
+ matching_list.each do |matching_expression, replacement_text|
65
+ file_contents = file_contents.gsub(matching_expression, replacement_text)
66
+ end
67
+ File.open(file_name, "w") {|file| file.puts file_contents}
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,112 @@
1
+ module MTBuild
2
+
3
+ # Use this class to create a workspace
4
+ class Workspace
5
+ require 'mtbuild/utils'
6
+ require 'rake/clean'
7
+
8
+ # The workspace's name
9
+ attr_reader :workspace_name
10
+
11
+ # The workspace's folder. Relative path references are interpreted as
12
+ # relative to this folder.
13
+ attr_reader :workspace_folder
14
+
15
+ # The workspace's output folder
16
+ attr_reader :output_folder
17
+
18
+ def initialize(workspace_name, workspace_folder, &configuration_block)
19
+ @workspace_name = workspace_name
20
+ @workspace_folder = File.expand_path(workspace_folder)
21
+ @output_folder = File.expand_path(File.join(@workspace_folder, MTBuild.default_output_folder))
22
+ @projects = []
23
+ @default_tasks = []
24
+
25
+ # Only process the first workspace found.
26
+ # Subsequent workspaces will be ignored
27
+ if MTBuild::Workspace.workspace.nil?
28
+ MTBuild::Workspace.set_workspace(self)
29
+
30
+ configuration_block.call(self) if configuration_block
31
+
32
+ @projects.each do |project|
33
+ require project
34
+ end
35
+
36
+ CLOBBER.include(@output_folder)
37
+
38
+ task :workspace do
39
+ puts "built workspace #{@workspace_name}"
40
+ end
41
+
42
+ task :default => @default_tasks+[:workspace]
43
+ end
44
+ end
45
+
46
+ # Adds a project subfolder
47
+ def add_project(project_location)
48
+ new_projects = []
49
+ Utils.expand_folder_list(project_location, Rake.original_dir).each do |project_path|
50
+ if File.directory? project_path
51
+ project_rakefile = File.join(project_path,'Rakefile.rb')
52
+ new_projects << project_rakefile if File.file? project_rakefile
53
+ end
54
+ end
55
+ $stderr.puts "Could not find a valid project at '#{project_location}'. Ignored." if new_projects.empty?
56
+ @projects += new_projects
57
+ end
58
+
59
+ # Adds tasks to be run by default when MTBuild is invoked with no arguments.
60
+ def add_default_tasks(default_tasks)
61
+ @default_tasks |= Utils.ensure_array(default_tasks).flatten
62
+ end
63
+
64
+ # Sets defaults for all configurations with the specified name
65
+ def set_configuration_defaults(configuration_name, defaults_hash)
66
+ Workspace.set_configuration_defaults(configuration_name, defaults_hash)
67
+ end
68
+
69
+ # Sets the build output folder location
70
+ def set_output_folder(output_folder)
71
+ @output_folder = File.expand_path(File.join(@workspace_folder,output_folder))
72
+ end
73
+
74
+ @workspace = nil
75
+
76
+ # The singleton workspace instance
77
+ def self.workspace
78
+ return @workspace
79
+ end
80
+
81
+ # Sets the singleton workspace instance
82
+ def self.set_workspace(workspace)
83
+ @workspace = workspace
84
+ end
85
+
86
+ # Queries whether a workspace exists
87
+ def self.have_workspace?
88
+ return !@workspace.nil?
89
+ end
90
+
91
+ # Add default tasks to the singleton workspace instance
92
+ def self.add_default_tasks(default_tasks)
93
+ @workspace.add_default_tasks(default_tasks) unless @workspace.nil?
94
+ end
95
+
96
+ @configuration_defaults = {}
97
+
98
+ # Gets the singleton configuration defaults
99
+ def self.configuration_defaults
100
+ return @configuration_defaults
101
+ end
102
+
103
+ # Adds or updates defaults to the singleton configuration defaults
104
+ def self.set_configuration_defaults(configuration_name, defaults_hash)
105
+ @configuration_defaults[configuration_name] = defaults_hash
106
+ end
107
+
108
+ include Rake::DSL
109
+
110
+ end
111
+
112
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mtbuild
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jerry Ryle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.6
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.6
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '0.9'
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 0.9.6
53
+ - !ruby/object:Gem::Dependency
54
+ name: rdoc
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '4.0'
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 4.0.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '4.0'
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 4.0.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: rspec
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: '2.14'
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.8
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.14'
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: 2.14.8
93
+ description: mtbuild is a rake-based build system for C/C++ projects. It provides
94
+ a DSL for declaring workspaces and projects, which generate rake tasks.
95
+ email:
96
+ - info@mindtribe.com
97
+ executables:
98
+ - mtbuild
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - bin/mtbuild
103
+ - lib/mtbuild/application.rb
104
+ - lib/mtbuild/application_configuration.rb
105
+ - lib/mtbuild/application_project.rb
106
+ - lib/mtbuild/application_task.rb
107
+ - lib/mtbuild/compiled_configuration.rb
108
+ - lib/mtbuild/configuration.rb
109
+ - lib/mtbuild/dsl.rb
110
+ - lib/mtbuild/mtbuild.rb
111
+ - lib/mtbuild/project.rb
112
+ - lib/mtbuild/staticlibrary_configuration.rb
113
+ - lib/mtbuild/staticlibrary_project.rb
114
+ - lib/mtbuild/staticlibrary_task.rb
115
+ - lib/mtbuild/test_application_configuration.rb
116
+ - lib/mtbuild/test_application_project.rb
117
+ - lib/mtbuild/test_application_task.rb
118
+ - lib/mtbuild/toolchain.rb
119
+ - lib/mtbuild/toolchains/arm_none_eabi_gcc.rb
120
+ - lib/mtbuild/toolchains/gcc.rb
121
+ - lib/mtbuild/utils.rb
122
+ - lib/mtbuild/version.rb
123
+ - lib/mtbuild/versioner.rb
124
+ - lib/mtbuild/versioners/mt_std_version.rb
125
+ - lib/mtbuild/workspace.rb
126
+ - lib/mtbuild.rb
127
+ - LICENSE.md
128
+ - README.md
129
+ homepage: https://github.com/MindTribe/MTBuild
130
+ licenses:
131
+ - BSD-3-Clause
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.0.14
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: rake-based build system for C/C++ projects
153
+ test_files: []