rake-delphi 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/2 +336 -0
  2. data/Gemfile +2 -1
  3. data/lib/rake/common/logger.rb +1 -1
  4. data/lib/rake/delphi/androidmanifest.rb +57 -0
  5. data/lib/rake/delphi/dcc32.rb +58 -59
  6. data/lib/rake/delphi/dcc32tool.rb +51 -0
  7. data/lib/rake/delphi/dccaarmtool.rb +29 -0
  8. data/lib/rake/delphi/envvariables.rb +19 -22
  9. data/lib/rake/delphi/paclient.rb +251 -0
  10. data/lib/rake/delphi/paclienttool.rb +20 -0
  11. data/lib/rake/delphi/project.rb +4 -2
  12. data/lib/rake/delphi/projectinfo.rb +73 -1
  13. data/lib/rake/delphi/resources.rb +1 -1
  14. data/lib/rake/delphi/tool.rb +8 -1
  15. data/lib/rake/delphi/version.rb +1 -1
  16. data/lib/rake/helpers/gemversion.rb +11 -0
  17. data/lib/rake/helpers/raketask.rb +16 -0
  18. data/lib/rake/helpers/string.rb +13 -0
  19. data/rake-delphi-cygwin.env.cmd +11 -0
  20. data/rake-delphi-cygwin.env.sh +12 -0
  21. data/rake-delphi.gemspec +4 -1
  22. data/test/helpers/consts.rb +6 -1
  23. data/test/helpers/verinfo.rb +22 -3
  24. data/test/resources/testproject-android/AndroidManifest.erb +35 -0
  25. data/test/resources/testproject-android/AndroidManifest.xml +35 -0
  26. data/test/resources/testproject-android/Rakefile.rb +55 -0
  27. data/test/resources/testproject-android/TestProject.cfg +4 -0
  28. data/test/resources/testproject-android/TestProject.dpr +15 -0
  29. data/test/resources/testproject-android/TestProject.rc +62 -0
  30. data/test/resources/testproject-android/TestProject.res +0 -0
  31. data/test/resources/testproject-android/TestProject.xe5.dproj +373 -0
  32. data/test/resources/testproject-android/fmTest.fmx +26 -0
  33. data/test/resources/testproject-android/fmTest.pas +31 -0
  34. data/test/resources/testproject-android/local.resources.txt +1 -0
  35. data/test/resources/testproject-android/release.dcc.cfg +1 -0
  36. data/test/resources/testproject-android/resources.rc +1 -0
  37. data/test/resources/testproject-android/resources.res +0 -0
  38. data/test/resources/testproject/Rakefile.rb +1 -1
  39. data/test/test-delphi-android.rb +192 -0
  40. data/test/test-delphi.rb +3 -11
  41. data/test/test-envvariables.rb +7 -0
  42. data/test/test-gemversion.rb +11 -0
  43. data/test/test-projectinfo-android.rb +81 -0
  44. data/test/test-projectinfo.rb +0 -11
  45. data/test/test-string.rb +41 -0
  46. metadata +92 -6
  47. data/test/resources/testproject/testproject.cfg.1 +0 -8
  48. data/test/resources/testproject/testproject.drc +0 -210
@@ -0,0 +1,26 @@
1
+ object TestForm: TTestForm
2
+ Left = 0
3
+ Top = 0
4
+ Caption = 'TestForm'
5
+ ClientHeight = 567
6
+ ClientWidth = 384
7
+ FormFactor.Width = 320
8
+ FormFactor.Height = 480
9
+ FormFactor.Devices = [dkDesktop]
10
+ DesignerMobile = True
11
+ DesignerWidth = 384
12
+ DesignerHeight = 592
13
+ DesignerDeviceName = 'Google Nexus 4'
14
+ DesignerOrientation = 0
15
+ DesignerOSVersion = ''
16
+ object Button1: TButton
17
+ Height = 44.000000000000000000
18
+ Position.X = 24.000000000000000000
19
+ Position.Y = 32.000000000000000000
20
+ TabOrder = 0
21
+ Text = 'HW'
22
+ Trimming = ttCharacter
23
+ Width = 145.000000000000000000
24
+ OnClick = Button1Click
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ unit fmTest;
2
+
3
+ interface
4
+
5
+ uses
6
+ System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7
+ FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;
8
+
9
+ type
10
+ TTestForm = class(TForm)
11
+ Button1: TButton;
12
+ procedure Button1Click(Sender: TObject);
13
+ private
14
+ { Private declarations }
15
+ public
16
+ { Public declarations }
17
+ end;
18
+
19
+ var
20
+ TestForm: TTestForm;
21
+
22
+ implementation
23
+
24
+ {$R *.fmx}
25
+
26
+ procedure TTestForm.Button1Click(Sender: TObject);
27
+ begin
28
+ ShowMessage('Hello, world!');
29
+ end;
30
+
31
+ end.
@@ -0,0 +1 @@
1
+ -=WITH RESOURCES=-
@@ -0,0 +1 @@
1
+ -DRELEASE_CFG
@@ -0,0 +1 @@
1
+ LOCAL_RESOURCES RCDATA local.resources.txt
@@ -30,7 +30,7 @@ namespace :test do
30
30
  desc 'Preparation'
31
31
  task :prepare, :useresources, :options do |t, opts|
32
32
  _task = Rake::Task['test:compile']
33
- dpr = Rake.application.define_task(Rake::Delphi::Project, (_task.shortname + ':delphi').to_sym)
33
+ dpr = Rake.application.define_task(Rake::Delphi::Project, (_task.name + ':delphi').to_sym)
34
34
  dpr[:resources_additional] = 'resources' if opts[:useresources]
35
35
  if ENV['DELPHI_VERSION'].to_i >= 14
36
36
  dpr[:platform] = 'Win32'
@@ -0,0 +1,192 @@
1
+ # vim: set shiftwidth=2 tabstop=2 expandtab:
2
+ # encoding: utf-8
3
+
4
+ require 'rake'
5
+ require 'fileutils'
6
+ require 'test/unit'
7
+ require 'rake/delphi/dccaarmtool'
8
+ require 'rake/helpers/unittest'
9
+ require 'rake/helpers/raketask'
10
+ require 'helpers/consts'
11
+ require 'helpers/verinfo'
12
+ require 'zip/zip'
13
+ require 'apktools/apkxml'
14
+ require 'xmlsimple'
15
+
16
+ module DelphiAndroidTests
17
+
18
+ class TestDelphiAndroid < DelphiTests::TestVerInfo
19
+ public
20
+ def project_path
21
+ PROJECT_PATH
22
+ end
23
+
24
+ def project_name
25
+ PROJECT_APK.pathmap('%n')
26
+ end
27
+
28
+ private
29
+ REQUIRED_FILES = %Q[META-INF/MANIFEST.MF
30
+ META-INF/ANDROIDD.SF
31
+ META-INF/ANDROIDD.RSA
32
+ lib/armeabi/libTestProject.so
33
+ AndroidManifest.xml
34
+ classes.dex
35
+ resources.arsc
36
+ res/drawable-hdpi/ic_launcher.png
37
+ res/drawable-ldpi/ic_launcher.png
38
+ res/drawable-mdpi/ic_launcher.png
39
+ res/drawable-xhdpi/ic_launcher.png
40
+ res/drawable-xxhdpi/ic_launcher.png].split(/\s+/)
41
+
42
+ def _test_apk(apk)
43
+ entries = []
44
+ Zip::ZipFile.open(apk) do |zip|
45
+ zip.each do |entry|
46
+ # test all files in .apk
47
+ assert REQUIRED_FILES.include?(entry.to_s), entry.to_s
48
+ entries << entry.to_s
49
+ end
50
+ end
51
+ REQUIRED_FILES.each do |file|
52
+ # test all required file
53
+ assert entries.include?(file), file
54
+ end
55
+ xml = ApkXml.new(apk)
56
+ manifest = xml.parse_xml('AndroidManifest.xml')
57
+ xml_hash = XmlSimple.xml_in(manifest, :ForceArray => false)
58
+ assert_equal '0x2', xml_hash['android:versionCode'], 'versionCode'
59
+ assert_equal '1.3.2.4', xml_hash['android:versionName'], 'versionName'
60
+ assert_equal 'TestProject', xml_hash['application']['activity']['meta-data']['android:value'], '<application><meta-data android:value>'
61
+ end
62
+
63
+ def _test_compile_and_output(prepare_args, output)
64
+ args = [:altercfg, :usecfg, :defines, :debuginfo, :debug, :includepaths]
65
+ # reinitialize arguments (even absent ones)
66
+ args.each do |arg|
67
+ prepare_args[arg] = prepare_args[arg]
68
+ end
69
+
70
+ bin_dir = File.dirname(apk)
71
+ dcu_dir_rel = '../../../tmp/android/dcu'
72
+ dcu_dir = bin_dir + '/../' + dcu_dir_rel
73
+ FileUtils.mkdir_p(bin_dir)
74
+ FileUtils.mkdir_p(dcu_dir)
75
+ # reenable task for subsequent calls
76
+ prepare_task = ::Rake::Task['test_android:prepare']
77
+ prepare_task.reenable
78
+ # prepare arguments
79
+ useresources = prepare_args[:useresources]
80
+ prepare_args.delete(:useresources)
81
+ prepare_args[:bin] = bin_dir
82
+ prepare_args[:version] = '1.3.2.4'
83
+
84
+ prepare_task.invoke(useresources, prepare_args)
85
+
86
+ # reenable tasks (!!! after invoking 'test_android:prepare')
87
+ task = ::Rake::Task['test_android:compile']
88
+ task.reenable_chain
89
+ task.invoke
90
+
91
+ assert(File.exists?(apk), 'File %s does not exist' % apk)
92
+
93
+ _test_apk(apk)
94
+ end
95
+
96
+ def apk
97
+ return PROJECT_APK % name.gsub(/[():]/, '_')
98
+ end
99
+
100
+ public
101
+ def setup
102
+ fail 'Cannot compile this project with Delphi below XE5' if ENV['DELPHI_VERSION'].to_i < 18
103
+ Rake::Delphi::DccARMTool.reinit
104
+ ENV['DELPHI_DIR'] = nil
105
+ super
106
+ ENV['RAKE_DIR'] = PROJECT_PATH
107
+ File.unlink(apk) if File.exists?(apk)
108
+ res = PROJECT_PATH + '/resources.res'
109
+ File.unlink(res) if File.exists?(res)
110
+ require PROJECT_PATH + '/Rakefile.rb'
111
+ end
112
+
113
+ def test_compile
114
+ _test_compile_and_output({},
115
+ 'testproject works')
116
+ end
117
+
118
+ def test_compile_defines
119
+ _test_compile_and_output({:defines => 'DEBUG'},
120
+ 'DEBUG: testproject works')
121
+ end
122
+
123
+ def test_compile_debug_info
124
+ _test_compile_and_output({:debug => true, :debuginfo => true},
125
+ 'D+: testproject works')
126
+ end
127
+
128
+ def test_compile_with_resources
129
+ _test_compile_and_output({:useresources => true, :defines => 'RESOURCES'},
130
+ 'testproject works-=WITH RESOURCES=-')
131
+ end
132
+
133
+ def test_compile_with_libs
134
+ _test_compile_and_output({:useresources => true, :defines => 'LIBS'},
135
+ 'testproject works-=WITH LIBS=-')
136
+ end
137
+
138
+ def test_compile_with_resources_and_libs
139
+ _test_compile_and_output({:useresources => true, :defines => 'RESOURCES,LIBS'},
140
+ 'testproject works-=WITH RESOURCES=--=WITH LIBS=-')
141
+ end
142
+
143
+ def test_compile_consts
144
+ _test_compile_and_output({:defines => 'ASSIGNABLE_CONSTS', :writeableconst => true},
145
+ 'testproject works-=ASSIGNED CONST=-')
146
+ end
147
+
148
+ def test_compile_alter_cfg
149
+ _test_compile_and_output({:altercfg => 'release.dcc.cfg'},
150
+ 'testproject works-=RELEASE=-')
151
+ end
152
+
153
+ def test_compile_use_config
154
+ _test_compile_and_output({:usecfg => true},
155
+ 'testproject works-=CONFIG=-')
156
+ end
157
+
158
+ def test_compile_use_absent_config
159
+ RakeFileUtils.verbose(Rake::Delphi::Logger.debug?) do
160
+ cfg = PROJECT_PATH.pathmap('%p%s') + PROJECT_APK.pathmap('%n.cfg')
161
+ mv cfg, cfg.pathmap('%X.absent.cfg')
162
+ begin
163
+ _test_compile_and_output({:usecfg => true},
164
+ 'testproject works')
165
+ ensure
166
+ mv cfg.pathmap('%X.absent.cfg'), cfg
167
+ end
168
+ end
169
+ end
170
+
171
+ def test_compile_use_library_path
172
+ # usually Indy components are in Delphi library paths
173
+ _test_compile_and_output({:defines => 'INDY', :uselibrarypath => true},
174
+ 'testproject works-=indy#path=-')
175
+ end
176
+
177
+ def test_compile_with_explicit_libs
178
+ paths = ['./ExplicitLib/']
179
+ _test_compile_and_output({:defines => 'EXPLICIT_LIBS',
180
+ :includepaths => paths},
181
+ 'testproject works-=WITH EXPLICIT LIBS=-')
182
+ end
183
+
184
+ def test_compile_with_explicit_and_implicit_libs
185
+ paths = ['./ExplicitLib/']
186
+ _test_compile_and_output({:defines => 'LIBS,EXPLICIT_LIBS',
187
+ :includepaths => paths},
188
+ 'testproject works-=WITH LIBS=--=WITH EXPLICIT LIBS=-')
189
+ end
190
+ end
191
+
192
+ end
data/test/test-delphi.rb CHANGED
@@ -7,6 +7,7 @@ require 'rake/delphi'
7
7
  require 'rake/delphi/project'
8
8
  require 'rake/delphi/tool'
9
9
  require 'rake/helpers/unittest'
10
+ require 'rake/helpers/raketask'
10
11
  require 'helpers/consts'
11
12
  require 'helpers/verinfo'
12
13
 
@@ -14,15 +15,6 @@ module DelphiTests
14
15
 
15
16
  class TestDelphi < TestVerInfo
16
17
  private
17
- def reenable_tasks(task)
18
- return unless task.class <= Rake::Task
19
- task.reenable
20
- task.prerequisites.each do |ptask|
21
- ptask.reenable if ptask.class < Rake::Task
22
- reenable_tasks(ptask)
23
- end
24
- end
25
-
26
18
  def _test_compile_and_output(prepare_args, output)
27
19
  args = [:altercfg, :usecfg, :defines, :debuginfo, :debug, :includepaths]
28
20
  # reinitialize arguments (even absent ones)
@@ -31,7 +23,7 @@ private
31
23
  end
32
24
 
33
25
  bin_dir = File.dirname(exe)
34
- dcu_dir_rel = '../../tmp/dcu'
26
+ dcu_dir_rel = '../../../../tmp/win32/dcu'
35
27
  dcu_dir = bin_dir + '/../' + dcu_dir_rel
36
28
  FileUtils.mkdir_p(bin_dir)
37
29
  FileUtils.mkdir_p(dcu_dir)
@@ -48,7 +40,7 @@ private
48
40
 
49
41
  # reenable tasks (!!! after invoking 'test:prepare')
50
42
  task = ::Rake::Task['test:compile']
51
- reenable_tasks(task)
43
+ task.reenable_chain
52
44
  task.invoke
53
45
 
54
46
  assert(File.exists?(exe), 'File %s does not exist' % exe)
@@ -18,6 +18,13 @@ class TestEnvVariables < Test::Unit::TestCase
18
18
  assert_equal('c:/delphi directory/Lib', env_vars['BDSLIB'])
19
19
  assert_equal('Platform: BDS platform', env_vars.expand('Platform: $(BDS_PLATFORM)'))
20
20
  assert_equal('Platform: BDS platform case', env_vars.expand('Platform: $(bds_platform_case)'))
21
+
21
22
  assert_equal('Env: $(BDS_NON_EXISTANT)', env_vars.expand('Env: $(BDS_NON_EXISTANT)'))
23
+
24
+ env_vars['BDS_PLATFORM_CASE_2'] = 'BDS Platform Case 2'
25
+ # be sure there is no BDS_Platform_Case_2 defined
26
+ assert_not_equal('BDS Platform Case 2', env_vars['BDS_Platform_Case_2'])
27
+ # also freeze string (ENV vars are frozen strings)
28
+ assert_equal('Platform: BDS Platform Case 2', env_vars.expand('Platform: $(BDS_Platform_Case_2)'.freeze))
22
29
  end
23
30
  end
@@ -28,6 +28,17 @@ public
28
28
  assert_equal '1,2,3,4', Gem::VersionImproved.new('1.2.3.4').comma
29
29
  end
30
30
 
31
+ def test_release_num
32
+ @version = Gem::VersionImproved.new('1.2.3.4')
33
+ assert_equal 3, @version.release_num
34
+
35
+ @version = Gem::VersionImproved.new('1.2.3')
36
+ assert_equal 2, @version.release_num
37
+
38
+ @version = Gem::VersionImproved.new('1.2')
39
+ assert_equal 1, @version.release_num
40
+ end
41
+
31
42
  def test_prev_release
32
43
  @version = Gem::VersionImproved.new('1.2.3.4')
33
44
  assert_equal '1.2.2', @version.prev_release.version
@@ -0,0 +1,81 @@
1
+ # encoding: Windows-1251
2
+ # vim: set shiftwidth=2 tabstop=2 expandtab:
3
+
4
+ require 'rake'
5
+ require 'test/unit'
6
+ require 'rake/delphi'
7
+ require 'rake/delphi/projectinfo'
8
+ require 'rake/delphi/dcc32'
9
+ require 'rake/helpers/unittest'
10
+ require 'helpers/consts'
11
+ require 'helpers/verinfo'
12
+
13
+ module DelphiAndroidTests
14
+
15
+ class TestVersionInfo < DelphiTests::TestVerInfo
16
+ private
17
+ def version
18
+ 'XE5'
19
+ end
20
+
21
+ protected
22
+ def delphi_version
23
+ return '18'
24
+ end
25
+
26
+ def do_getinfo
27
+ @info = Rake::Delphi::XEVersionInfo.new(@rake_task)
28
+ end
29
+
30
+ def project_path
31
+ PROJECT_PATH
32
+ end
33
+
34
+ def project_name
35
+ PROJECT_APK.pathmap('%n')
36
+ end
37
+
38
+ public
39
+ def setup
40
+ super
41
+ @rake_task = Rake::Delphi::Dcc32Task.new('some-task-' + name, Rake.application)
42
+ @rake_task.systempath = project_path + '/TestProject.dpr'
43
+ do_getinfo
44
+ end
45
+
46
+ def test_info
47
+ return unless prepare_ver_info_file?
48
+ assert_equal '4.3.2.1', @info['FileVersion']
49
+ assert_equal 'Rake', @info['CompanyName']
50
+ assert_equal 'Test rake-delphi project %s description' % version, @info['FileDescription']
51
+ assert_equal 'testproject.exe', @info['InternalName']
52
+ assert_equal 'Copyright. ��������', @info['LegalCopyright']
53
+ assert_equal 'Trademark. �������� �����', @info['LegalTrademarks']
54
+ assert_equal 'testproject.exe', @info['OriginalFilename']
55
+ assert_equal 'Test rake-delphi project %s product name' % version, @info['ProductName']
56
+ assert_equal '1.2.3.4', @info['ProductVersion']
57
+ assert_equal 'Test project comment', @info['Comments']
58
+ end
59
+
60
+ def test_deploy_files
61
+ tested_deploymentFiles = []
62
+ tested_deploymentFiles_prefixes = { 36 => 'l', 48 => 'm', 72 => 'h', 96 => 'xh', 144 => 'xxh'}
63
+ [36, 48, 72, 96, 144].each do |n|
64
+ tested_deploymentFiles << '$(BDS)\bin\Artwork\Android\FM_LauncherIcon_%dx%d.png,res\drawable-%sdpi\,1,ic_launcher.png' % [n, n, tested_deploymentFiles_prefixes[n]]
65
+ end
66
+ tested_deploymentFiles << 'project_so,library\lib\armeabi\,1,libTestProject.so'
67
+ tested_deploymentFiles << '$(BDS)\lib\android\debug\classes.dex,classes\,1,classes.dex'
68
+ deploymentfiles = @info.deploymentfiles('Android')
69
+ assert deploymentfiles.kind_of?(Array), 'NOT an Array?!'
70
+ assert_not_equal 0, deploymentfiles.size, 'No files?!'
71
+ deploymentfiles.each do |dfile|
72
+ assert dfile.kind_of?(Hash), 'NOT a Hash?!'
73
+ assert_equal 1, dfile.keys.count, 'More than one value?!'
74
+ assert dfile.keys.first.kind_of?(String) || dfile.keys.first.kind_of?(Symbol), 'Key is NOT a String or Symbol?!'
75
+ assert dfile.values.first.kind_of?(Array), 'Value is NOT an Array?!'
76
+ assert tested_deploymentFiles.include?(dfile.to_a.join(',')), dfile.to_a.join(',')
77
+ end
78
+ end
79
+ end
80
+
81
+ end
@@ -9,17 +9,6 @@ require 'rake/helpers/unittest'
9
9
  require 'helpers/consts'
10
10
  require 'helpers/verinfo'
11
11
 
12
- module Rake
13
- module Delphi
14
- class BDSVersionInfo
15
- # override method
16
- def self.encoding
17
- 'Windows-1251'
18
- end
19
- end
20
- end
21
- end
22
-
23
12
  module DelphiTests
24
13
 
25
14
  class TestBDSVersionInfo < TestVerInfo