rakish 0.9.01.beta

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,216 @@
1
+ myPath = File.dirname(File.expand_path(__FILE__));
2
+ require "#{myPath}/RakishProject.rb"
3
+ require 'tmpdir'
4
+
5
+
6
+ module Rakish
7
+
8
+ class ArchiveBuilder < BuildConfig
9
+
10
+ public
11
+
12
+ # archiveContents has these "fields"
13
+ # :files - list of file paths (can use wild cards)
14
+ # :baseDir - base directory of file list as "source root dir" to be truncated from resolved paths
15
+ # :destDir - destination folder in jar file to have truncated files paths added to in jar file.
16
+ # :cacheList - cache the file list and auto-add dependencies only defined if true
17
+ # requres that utility 'unzip' is in the path
18
+
19
+ attr_reader :archiveContents_ # :nodoc:
20
+
21
+ addInitBlock do |pnt,opts|
22
+ @archiveContents_ = [];
23
+ end
24
+
25
+ def unzipPath # :nodoc:
26
+ @@unzipPath_ ||= Rakish::Util.findInBinPath('unzip');
27
+ end
28
+
29
+ # Adds all the files from a subtree into the destdir
30
+ # the subtree will have it's leading "basedir" removed from the file path
31
+ # and replaced with the "basedir" before adding to the archive.
32
+ # note: all "destdir" paths are relative to the root of the archive
33
+ # ie:
34
+ # file = '/a/b/c/d/e/file.txt'
35
+ # basedir = '/a/b/c'
36
+ # destdir = './archive/dir'
37
+ #
38
+ # added to archive = 'archive/dir/file.txt'
39
+ #
40
+ # Note: the file list not resolved until configured archive task is
41
+ # checked for being "needed?" or invoked.
42
+
43
+ def addFileTree(destdir, basedir, *files)
44
+
45
+ # ensure all destdirs are relative to an implicit folder
46
+ if(destdir =~ /^\//)
47
+ destdir="./#{$'}"
48
+ end
49
+
50
+ entry = {};
51
+ entry[:destDir]=(destdir);
52
+
53
+ (basedir=File.expand_path(basedir)) unless basedir=='#';
54
+
55
+ entry[:baseDir]=basedir;
56
+
57
+ filePaths = [];
58
+ files.flatten.each do |file|
59
+ filePaths << File.expand_path(file);
60
+ end
61
+
62
+ entry[:files]=filePaths;
63
+ @archiveContents_ << entry;
64
+ end
65
+
66
+
67
+
68
+ # Add files in the *files list into the 'destdir' in the archive
69
+ # note: all "destdir" paths are relative to the root of the archive
70
+ def addFiles(destdir,*files)
71
+ addFileTree(destdir,'#',*files); # note '#' is flag to do addFiles
72
+ end
73
+
74
+ # Sets up a task to load contents from a directory to the root of the archive file recursively.
75
+ # filters - if filters are specified, they select files within the directory to put in the jar
76
+ # with the wildcard path relative to the source directory in the format of a Rake::FileList
77
+ # the default if unspecified is to select all files in the directory.
78
+ # The list of files is resolved when the builder task is invoked.
79
+
80
+ def addDirectory(dir,*filters)
81
+ if(filters.length < 1)
82
+ filters=['**/*'];
83
+ end
84
+ filters.map! do |filter|
85
+ File.join(dir,filter);
86
+ end
87
+ addFileTree('.',dir,*filters);
88
+ end
89
+
90
+
91
+ # Add task to extract contents from the given zip file, will apply filters
92
+ # and add the extracted files/folders to the root of the
93
+ # new archive recursively, the extraction is done when the
94
+ # builder task is invoked.
95
+ # filters - if filters are specified, they select files within the source to put in the jar
96
+ # with the wildcard path relative to the source root in the format of a Rake::FileList
97
+ # the default if unspecified is to select all files in the source.
98
+ # The list of files is resolved when the builder task is invoked.
99
+
100
+ def addZipContents(archivePath,*filters)
101
+
102
+ if(filters.length < 1)
103
+ filters=['*'];
104
+ end
105
+ entry = {};
106
+ entry[:destDir]=('.');
107
+ entry[:baseDir]=("#{File.expand_path(archivePath)}###"); # note "###" is flag to indicate source is an archive
108
+ entry[:files]=filters;
109
+ @archiveContents_ << entry;
110
+ end
111
+
112
+ def loadTempDir(dir) # :nodoc: TODO "the "####" and '#' flag thing is messy maybe :type in entry ??
113
+
114
+
115
+ archiveContents_.each do |entry|
116
+
117
+ # copy or extract all the files for the jar to a temporary folder
118
+ # then create a jar containing the contents
119
+ # and delete the directory
120
+
121
+ baseDir = entry[:baseDir];
122
+
123
+ spl = baseDir.split('###',2)
124
+ if(spl.length > 1)
125
+
126
+ # from unzip man page
127
+ # "*.c" matches "foo.c" but not "mydir/foo.c"
128
+ # "**.c" matches both "foo.c" and "mydir/foo.c"
129
+ # "*/*.c" matches "bar/foo.c" but not "baz/bar/foo.c"
130
+ # "??*/*" matches "ab/foo" and "abc/foo"
131
+ # but not "a/foo" or "a/b/foo"
132
+
133
+ cmd = "\"#{unzipPath}\" -q \"#{spl[0]}\" \"#{entry[:files].join("\" \"")}\" -x \"META-INF/*\" -d \"#{dir}\"";
134
+
135
+ execLogged(cmd, :verbose=>verbose?);
136
+
137
+ else
138
+ contents = entry[:files];
139
+ unless(FileCopySet === contents)
140
+ contents = FileCopySet.new; # a new set for each entry.
141
+ # for each entry add files to a copy set
142
+ if(baseDir=="#")
143
+ contents.addFiles(entry[:destDir],entry[:files]);
144
+ else
145
+ contents.addFileTree(entry[:destDir],baseDir,entry[:files]);
146
+ end
147
+ end
148
+ # copy the file set to the temp folder
149
+ contents.filesByDir do |destDir,files|
150
+ FileUtils.mkdir_p destDir;
151
+ files.each do |file|
152
+ FileUtils.cp(file,destDir)
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+
159
+
160
+ class ArchiveTask < Rake::FileTask
161
+
162
+ # I wonder if there is a better way in rake.
163
+ # This will auto generate source prerequisites
164
+ # from the specified FileSets when
165
+ # they are demanded
166
+
167
+ protected
168
+
169
+ def resolvePrerequisites
170
+ # TODO "the "####" and '#' flag thing is messy maybe :type in entry ??
171
+ unless defined? @filesResolved_
172
+ @filesResolved_ = true;
173
+ contents = config.archiveContents_;
174
+
175
+ contents.each do |entry|
176
+ baseDir = entry[:baseDir];
177
+ spl = baseDir.split('###',2)
178
+ if(spl.length > 1)
179
+ @prerequisites << spl[0]
180
+ else
181
+ copySet = FileCopySet.new;
182
+ # for each entry add files to the copy set
183
+ if(baseDir=='#')
184
+ copySet.addFiles(entry[:destDir],entry[:files]);
185
+ else
186
+ copySet.addFileTree(entry[:destDir],baseDir,entry[:files]);
187
+ end
188
+ @prerequisites |= copySet.sources;
189
+ # replace file list in entry with the resolved copy set
190
+ entry[:files] = copySet if entry[:cacheList]
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ public
197
+
198
+ # Override of Rake::Task::prerequisite_tasks to return list of prerequisite tasks,
199
+ # generated and cached upon first access.
200
+ def prerequisite_tasks
201
+ resolvePrerequisites unless defined? @filesResolved_
202
+ prerequisites.collect { |pre| lookup_prerequisite(pre) }
203
+ end
204
+
205
+ # Override of Rake::FileTask::needed? this resolves all the specified source file lists
206
+ # and adds them all as prerequisites to the task for which the purpose is to copy the sources into
207
+ # a destination archive.
208
+ def needed?
209
+ resolvePrerequisites unless defined? @filesResolved_
210
+ !File.exist?(name) || out_of_date?(timestamp);
211
+ end
212
+ end
213
+ end
214
+
215
+ end # Rakish
216
+
@@ -0,0 +1,254 @@
1
+ myDir = File.dirname(File.expand_path(__FILE__));
2
+ require "#{myDir}/Rakish.rb"
3
+
4
+ module Rakish
5
+
6
+ class InvalidConfigError < Exception # :nodoc:
7
+ def initialize(cfg, msg)
8
+ super("Invalid Configuration \"#{cfg}\": #{msg}.");
9
+ end
10
+ end
11
+
12
+ module BuildConfigModule
13
+ include PropertyBagMod
14
+ include Rake::DSL
15
+
16
+ addInitBlock do |pnt,opts|
17
+
18
+ init_PropertyBag(pnt);
19
+ # log.debug("initializing BuildConfig #{pnt}")
20
+ enableNewFields do |cfg|
21
+ if(pnt)
22
+ cfg.nativeConfigName = getAnyAbove(:nativeConfigName);
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ # constants
29
+ SUPPORTED_HOST_TYPES = [ 'Win64', 'Win32', 'Linux32', 'Linux64', 'Macosx64' ];
30
+
31
+ begin
32
+ # get per process/machine constants
33
+ USERNAME = (ENV['USERNAME']||ENV['LOGNAME']);
34
+ def USERNAME
35
+ USERNAME
36
+ end
37
+
38
+ os = ENV['OS'];
39
+ if(os =~ /Windows/)
40
+ arch = ENV['PROCESSOR_ARCHITEW6432']
41
+ if(arch =~ /AMD64/)
42
+ HOSTTYPE = 'Win64';
43
+ else
44
+ HOSTTYPE = 'Win32';
45
+ end
46
+ BASEHOSTTYPE = 'Windows';
47
+ else
48
+ uname = %x[uname]
49
+ if(uname =~ /Darwin/)
50
+ htype = 'Macosx'
51
+ else
52
+ htype = 'Linux'
53
+ end
54
+ arch = %x[arch]
55
+ if(arch =~ /x86_64/)
56
+ HOSTTYPE = "#{htype}64"
57
+ else
58
+ HOSTTYPE = "#{htype}32"
59
+ end
60
+ BASEHOSTTYPE = 'Linux'
61
+ end
62
+ def HOSTTYPE
63
+ HOSTTYPE
64
+ end
65
+ def BASEHOSTTYPE
66
+ BASEHOSTTYPE
67
+ end
68
+ end
69
+
70
+ # folder to output native libraries and "linkref" files
71
+ # pointing to the actual libraries if not there ( windows DLL libs )
72
+ attr_property :nativeLibDir
73
+
74
+ # folder to output native object and intermediate files to
75
+ attr_property :nativeObjDir
76
+
77
+ # folder to output native binary dll and so files to
78
+ attr_property :binDir
79
+
80
+ # parsable native configuration name as configuration and
81
+ # used as a reference to which librarys to link with for a particular
82
+ # compiler and processor configuration
83
+ attr_property :nativeConfigName
84
+
85
+ # suffix to append to native output binary and library files
86
+ # defaults to the nativeConfigName
87
+ attr_property :nativeOutputSuffix
88
+
89
+ # root folder for build output files
90
+ def buildDir
91
+ @buildDir||=getAnyAbove(:buildDir);
92
+ end
93
+
94
+ # folder to output native executable and dll files to.
95
+ # defaults to (buildDir)/bin
96
+ def binDir
97
+ @binDir||=getAnyAbove(:binDir)||"#{buildDir()}/bin";
98
+ end
99
+
100
+ # folder to output native library files and link references to.
101
+ # defaults to (buildDir)/lib
102
+ def nativeLibDir
103
+ @nativeLibDir||=getAnyAbove(:nativeLibDir)||"#{buildDir()}/lib";
104
+ end
105
+
106
+ # folder to output native intermedite and object files to.
107
+ # config defaults to (buildDir)/obj
108
+ # in a project module defaults to the value set in th (configValue)/(moduleName)
109
+ def nativeObjDir
110
+ @nativeObjDir||=getAnyAbove(:nativeObjDir)||"#{buildDir()}/obj";
111
+ end
112
+
113
+ # suffix to add to native output files
114
+ # defaults to nativeConfigName
115
+ def nativeOutputSuffix
116
+ @nativeOutputSuffix||=nativeConfigName();
117
+ end
118
+
119
+ attr_accessor :verbose
120
+
121
+ def verbose?
122
+ @verbose ||= getAnyAbove(:verbose);
123
+ end
124
+
125
+ end
126
+
127
+
128
+ class BuildConfig
129
+ include Util
130
+
131
+ # this may need to be changed as rake evolves
132
+ def self.task(*args,&block)
133
+ Rake::Task.define_task(*args, &block)
134
+ end
135
+
136
+ def initialize(pnt=nil,opts=nil)
137
+ self.class.initializeIncluded(self,pnt,opts);
138
+ yield self if block_given?
139
+ end
140
+ include BuildConfigModule
141
+
142
+ end
143
+
144
+ protected
145
+
146
+ # global singleton default Rakish.Project configuration
147
+ class GlobalConfig < BuildConfig
148
+
149
+ @@gcfg = nil
150
+
151
+ def globalPaths(&b)
152
+ @initGlobalPaths = b;
153
+ end
154
+
155
+ def self.includeConfigType(mod)
156
+ unless GlobalConfig.include? mod
157
+ include(mod);
158
+ end
159
+ end
160
+
161
+ def buildDir=(val)
162
+ @buildDir=val;
163
+ end
164
+
165
+ def initialize(*args, &b)
166
+
167
+ if @@gcfg
168
+ raise("Exeption !! You can only initialize one GlobalConfig !!!")
169
+ end
170
+
171
+ @@gcfg = self
172
+
173
+ opts = (Hash === args.last) ? args.pop : {}
174
+
175
+ ensureIncluded = opts[:include];
176
+ if(ensureIncluded != nil)
177
+ ensureIncluded.each do |ei|
178
+ GlobalConfig.includeConfigType(ei);
179
+ end
180
+ end
181
+
182
+ super(nil,{}) {}
183
+
184
+ enableNewFields() do |cfg|
185
+
186
+ enableNewFields(&b);
187
+
188
+ enableNewFields(&@initGlobalPaths) if @initGlobalPaths;
189
+
190
+ @buildDir ||= ENV['RakishBuildRoot']||"#{Rake.original_dir}/build";
191
+ @buildDir = File.expand_path(@buildDir);
192
+
193
+ config = nil;
194
+ if(HOSTTYPE =~ /Macosx/)
195
+ defaultConfig = "iOS-gcc-fat-Debug";
196
+ else
197
+ defaultConfig = "Win32-VC10-MD-Debug";
198
+ end
199
+
200
+
201
+ # set defaults if not set above
202
+ @nativeLibDir ||= "#{@buildDir}/lib"
203
+ @binDir ||= "#{@buildDir}/bin"
204
+ @INCDIR ||= "#{@buildDir}/include"
205
+
206
+ # get config from command line
207
+ cfg.nativeConfigName ||= ENV['nativeConfigName'];
208
+ cfg.nativeConfigName ||= defaultConfig
209
+
210
+ end
211
+
212
+ puts("host is #{HOSTTYPE()}") if self.verbose?
213
+
214
+ ensureDirectoryTask(@buildDir);
215
+
216
+ RakeFileUtils.verbose(@@gcfg.verbose?)
217
+ if(@@gcfg.verbose?)
218
+ puts("Global configuration initialized")
219
+ end
220
+ end
221
+
222
+ # return the instance of the GlobalConfig nil if not initialized
223
+ def GlobalConfig.instance
224
+ @@gcfg
225
+ end
226
+ end
227
+
228
+ public
229
+
230
+ # Declare (create) a new named configuration
231
+ #
232
+ # named arguments:
233
+ # :name => Name for this configuration. This must be unique for all loaded projects,
234
+ # defaults to 'root'.
235
+ # :include => [ Array of configuration modules to include ]
236
+ # :inheritsFrom => Parent configuration's name.
237
+ # Defaults to 'root' if name != 'root'
238
+
239
+ def self.Configuration(opts={},&block)
240
+ name = opts[:name]||='root'
241
+ me = nil;
242
+ if(name == 'root')
243
+ me = GlobalConfig.new(opts,&block);
244
+ else
245
+ return(nil); # for now.
246
+ end
247
+ me.name=name;
248
+ build.registerConfiguration(me);
249
+ me
250
+ end
251
+
252
+
253
+ end # module Rakish
254
+