Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

package_builder_old.pm 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. #!perl
  2. use strict;
  3. use warnings;
  4. ###############################################################################
  5. #
  6. # package_builder.pm
  7. #
  8. # Perl module which puts together all the resources needed for the windows
  9. # installer package, then builds said package
  10. #
  11. # Author: julienp@opera.com
  12. #
  13. ###############################################################################
  14. package package_builder_old;
  15. # Include modules
  16. use File::Basename;
  17. use File::Copy;
  18. use File::Path;
  19. use File::Spec;
  20. use Cwd;
  21. use lib qw(../../../common/package);
  22. use Shipping;
  23. use feature_scanner;
  24. use skin_builder;
  25. # ShippingCallback object which controls how to copy the files
  26. {
  27. package ShippingCallback;
  28. # Call-back for Shipping.pm
  29. sub new ($$) {
  30. my $class = shift;
  31. my $self = {};
  32. # This needs to be an absolute path so that the zipping will work
  33. $self->{dest_root_dir} = File::Spec->rel2abs(shift);
  34. $self->{files_list} = shift;
  35. $self->{build_output} = shift;
  36. bless $self, $class;
  37. return $self;
  38. }
  39. sub shipFile ($$$$) {
  40. ( my $self, my $name, my $dest, my $each ) = @_;
  41. $name =~ s/\//\\/g; # If the path contains unix /-es, replace with windows \-es.
  42. $name =~ s/\[CONFIGURATION\]/$self->{build_output}/g;
  43. $dest =~ s/\//\\/g; # If the path contains unix /-es, replace with windows \-es.
  44. # This is hack of the century and should be removed, but legacy from the old system!!!!
  45. $dest =~ s/^Opera[\\\/]//; # Remove the "Opera" folder it just represents the INSTALLDIR.
  46. my $s = $name;
  47. my $d = File::Spec->catfile($self->{dest_root_dir}, $dest);
  48. # Create the dest directory if it doesn't exist
  49. my $dest_dir = File::Basename::dirname($d);
  50. if (!(-e $dest_dir))
  51. {
  52. File::Path::mkpath($dest_dir);
  53. }
  54. # print "Copy: ".$s." : ".$d."\n";
  55. # Copy file $s, $d
  56. if (File::Copy::copy($s, $d))
  57. {
  58. my $handler = $self->{files_list};
  59. print $handler $dest."\n";
  60. }
  61. else
  62. {
  63. print File::Spec->rel2abs(__FILE__) . "(" . __LINE__ . "): warning : Failed copying $s to $d. $!\n";
  64. }
  65. }
  66. sub zipFile ($$$$) {
  67. ( my $self, my $path, my $dest, my $each ) = @_;
  68. $path =~ s/\//\\/g; # If the path contains unix /-es, replace with windows \-es.
  69. $dest =~ s/\//\\/g; # If the path contains unix /-es, replace with windows \-es.
  70. # This is hack of the century and should be removed, but legacy from the old system!!!!
  71. $dest =~ s/^Opera[\\\/]//; # Remove the "Opera" folder it just represents the INSTALLDIR.
  72. my $s = $path;
  73. my $d = File::Spec->catfile($self->{dest_root_dir}, $dest);
  74. # Create the dest directory if it doesn't exist
  75. my $dest_dir = File::Basename::dirname($d);
  76. #print $dest_dir."\n";
  77. if (!(-e $dest_dir))
  78. {
  79. File::Path::mkpath($dest_dir);
  80. }
  81. print "ZipFile: ".$s." : ".$d."\n";
  82. # Save the current directory so we can go back at the end!
  83. my $cwd = Cwd::getcwd;
  84. # We need to change into the folder so that the zip file has the
  85. # correct paths internally
  86. if (-e $s)
  87. {
  88. chdir ($s);
  89. unlink($d);
  90. system("7z a -tzip -y \"$d\" . -xr!CVS -xr!thumbs.db -xr!7z.log > 7z.log");
  91. # Go back to the same directory we earlier
  92. chdir($cwd);
  93. my $handler = $self->{files_list};
  94. print $handler $dest."\n";
  95. }
  96. }
  97. }
  98. sub new
  99. {
  100. my $class = shift;
  101. my $self = {};
  102. $self->{_build_nr} = shift;
  103. $self->{_version} = shift;
  104. $self->{_build_output} = shift;
  105. $self->{_languages} = shift;
  106. $self->{_lang_options} = shift;
  107. $self->{_package_name} = shift;
  108. $self->{_autoupdate_package_name} = shift;
  109. $self->{_source_dir} = shift;
  110. $self->{_target_dir} = shift;
  111. $self->{_temp_dir} = shift;
  112. $self->{_packaging_dir} = shift;
  113. $self->{_browser_js_src} = shift;
  114. $self->{_public_domain_src} = shift;
  115. $self->{_sign} = shift;
  116. $self->{_files_list} = File::Spec->catfile($self->{_target_dir}, "files_list");
  117. $self->{_installer_archive} = File::Spec->catfile($self->{_target_dir}, File::Spec->updir(), "Opera.7z");
  118. $self->{_installer_package} = File::Spec->catfile($self->{_target_dir}, File::Spec->updir(), $self->{_package_name}) if (defined($self->{_package_name}));
  119. $self->{_autoupdate_package} = File::Spec->catfile($self->{_target_dir}, File::Spec->updir(), $self->{_autoupdate_package_name}) if (defined($self->{_autoupdate_package_name}));
  120. $self->{_public_domain_dst} = File::Spec->catfile($self->{_target_dir}, "defaults", "public_domains.dat");
  121. $self->{_i18ndata_dir} = File::Spec->catdir($self->{_source_dir}, "data", "i18ndata");
  122. $self->{_i18ndata_tables_dir} = File::Spec->catdir($self->{_i18ndata_dir}, "tables");
  123. $self->{_local_encoding_bin} = File::Spec->catfile($self->{_i18ndata_tables_dir}, "encoding.bin");
  124. $self->{_package_encoding_bin} = File::Spec->catfile($self->{_target_dir}, "encoding.bin");
  125. $self->{_setup_dir} = File::Spec->catdir($self->{_source_dir}, "adjunct", "quick", "setup");
  126. $self->{_common_dir} = File::Spec->catdir($self->{_source_dir}, "platforms", "ubscommon");
  127. $self->{_temp_shipping_dir} = File::Spec->catdir($self->{_temp_dir}, "shipping_build");
  128. $self->{_package_xml} = File::Spec->catfile($self->{_source_dir}, "adjunct", "quick", "setup", "package.xml");
  129. $self->{_binaries_package_xml} = File::Spec->catfile($self->{_source_dir}, "platforms", "windows", "packaging", "binaries_package_2010.xml");
  130. $self->{_platform_dirs} = File::Spec->catfile($self->{_source_dir}, "platforms", "windows", "packaging", "windirs.xml");
  131. $self->{_custom_features} = File::Spec->catfile($self->{_source_dir}, "adjunct", "quick", "custombuild-features.h");
  132. $self->{_platform_features} = File::Spec->catfile($self->{_source_dir}, "platforms", "windows", "features.h");
  133. $self->{_quick_features} = File::Spec->catfile($self->{_source_dir}, "adjunct", "quick", "quick-features.h");
  134. $self->{_makelang_script} = File::Spec->catfile($self->{_source_dir}, "data", "strings", "scripts", "makelang.pl");
  135. $self->{_build_strings} = File::Spec->catfile($self->{_source_dir}, "data", "strings", "build.strings");
  136. $self->{_english_db} = File::Spec->catfile($self->{_source_dir}, "data", "strings", "english.db");
  137. $self->{_local_english_db} = File::Spec->catfile($self->{_source_dir}, "adjunct", "quick", "english_local.db");
  138. $self->{_package_lang_file} = File::Spec->catfile($self->{_target_dir}, "locale", "en", "en.lng");
  139. $self->{_sfxmodule} = File::Spec->catfile($self->{_packaging_dir}, "packaging", "tools", "7zSfx", "7zsd.sfx");
  140. $self->{_sfxconfig} = File::Spec->catfile($self->{_packaging_dir}, "packaging", "tools", "7zSfx", "config.txt");
  141. $self->{_sfxconfig_autoupdate} = File::Spec->catfile($self->{_packaging_dir}, "packaging", "tools", "7zSfx", "config_autoupdate.txt");
  142. $self->{_signcode} = File::Spec->catfile($self->{_packaging_dir}, "packaging", "tools", "signcode.exe");
  143. bless $self, $class;
  144. return $self;
  145. }
  146. sub Build
  147. {
  148. my $self = shift;
  149. # Build the files/folders we use all the time
  150. # Save the current directory so we can go back at the end!
  151. my $cwd = getcwd;
  152. # Check if the destination dir exists, if not create it
  153. if (!(-e $self->{_target_dir}))
  154. {
  155. print "Creates: $self->{_target_dir}\n";
  156. File::Path::mkpath($self->{_target_dir});
  157. }
  158. else
  159. {
  160. print "Will not create: $self->{_target_dir}\n";
  161. }
  162. open FILESLIST, '>', $self->{_files_list};
  163. # Create the default target set for packaging
  164. my @shipping_targets = ("windows", "embedded", "voice");
  165. # List of file to check and in the order of preference
  166. my @features_files = ($self->{_custom_features}, $self->{_platform_features}, $self->{_quick_features});
  167. # Debug
  168. #foreach my $features_file (@features_files)
  169. #{
  170. # print "Files: ".$features_file."\n";
  171. #}
  172. # Create the feature scanner object
  173. my $fs = feature_scanner->new(@features_files);
  174. # Add the release/debug target
  175. if ($self->{_build_output} =~ /debug/i)
  176. {
  177. push(@shipping_targets, "debug");
  178. }
  179. else
  180. {
  181. push(@shipping_targets, "release");
  182. }
  183. # Add any targets from the features
  184. push(@shipping_targets, $fs->GetPackagingTargets(@features_files));
  185. # Debug
  186. #foreach my $shipping_target (@shipping_targets)
  187. #{
  188. # print $shipping_target."\n";
  189. #}
  190. # Setup the shipping object
  191. my $ship = new Shipping($self->{_platform_dirs}, $self->{_source_dir}, $self->{_temp_shipping_dir}, $fs, undef, @shipping_targets);
  192. print $self->{_i18ndata_dir}."\n";
  193. # Is there a i18ndata checkout so we can create the chartable?
  194. if (-e $self->{_i18ndata_dir})
  195. {
  196. # Change to the tables folder
  197. chdir($self->{_i18ndata_tables_dir});
  198. # Generate the chartable
  199. system("python make.py tables-windows8.txt");
  200. # Generate the encodings.bin
  201. system("perl utilities\\gettablelist.pl -e .");
  202. # Go back to the same directory we earlier
  203. chdir($cwd);
  204. # Copy the chartable into the package
  205. if (-e $self->{_local_encoding_bin})
  206. {
  207. copy($self->{_local_encoding_bin}, $self->{_package_encoding_bin}) or print File::Spec->rel2abs(__FILE__) . "(" . __LINE__ . "): warning : Failed copying $self->{_local_encoding_bin} to $self->{_package_encoding_bin}. $!\n";
  208. print FILESLIST File::Spec->abs2rel($self->{_package_encoding_bin}, $self->{_target_dir})."\n";
  209. }
  210. }
  211. # Copy executables using the shipping object and the package.xml
  212. if (!$ship->parseManifest($self->{_binaries_package_xml}, new ShippingCallback($self->{_target_dir}, *FILESLIST, $self->{_build_output})))
  213. {
  214. return 0;
  215. }
  216. # Copy everything using the shipping object and the package.xml
  217. if (!$ship->parseManifest($self->{_package_xml}, new ShippingCallback($self->{_target_dir}, *FILESLIST, $self->{_build_output})))
  218. {
  219. return 0;
  220. }
  221. copy($self->{_public_domain_src}, $self->{_public_domain_dst});
  222. chdir($self->{_temp_dir});
  223. # Generating the en.lng file
  224. $self->BuildLngFile("en", $self->{_package_lang_file});
  225. foreach my $lang (@{$self->{_languages}})
  226. {
  227. $self->AddLanguageFilesFor($lang);
  228. }
  229. close FILESLIST;
  230. chdir ($self->{_target_dir});
  231. unlink($self->{_installer_archive});
  232. my $signcode_command = "\"".$self->{_signcode}. "\" -spc \"C:\\opera2010.spc\" -v \"C:\\opera2010.pvk\" -n \"Opera web browser\" -i \"http://www.opera.com\" -a MD5 -t \"http://timestamp.verisign.com/scripts/timstamp.dll\" ";
  233. if (defined ($self->{_installer_package}) || defined ($self->{_autoupdate_package_name}))
  234. {
  235. print "Zipping the Opera Installer:\n";
  236. system("7z a -t7z -mx9 -y \"$self->{_installer_archive}\" . -xr!profile -xr!thumbs.db -xr!debug_log.txt -xr!debug.txt -xr!7z.log > 7z.log");
  237. }
  238. if (defined ($self->{_installer_package}))
  239. {
  240. print "Copying the Opera Installer to \"$self->{_installer_package}\"\n";
  241. system("copy /b \"$self->{_sfxmodule}\" + \"$self->{_sfxconfig}\" + \"$self->{_installer_archive}\" \"$self->{_installer_package}\"");
  242. if ($self->{_sign})
  243. {
  244. system("$signcode_command \"$self->{_installer_package}\"");
  245. }
  246. }
  247. if (defined ($self->{_autoupdate_package_name}))
  248. {
  249. print "Copying the Opera Installer to \"$self->{_autoupdate_package}\"\n";
  250. system("copy /b \"$self->{_sfxmodule}\" + \"$self->{_sfxconfig_autoupdate}\" + \"$self->{_installer_archive}\" \"$self->{_autoupdate_package}\"");
  251. if ($self->{_sign})
  252. {
  253. system("$signcode_command \"$self->{_autoupdate_package}\"");
  254. }
  255. }
  256. chdir($cwd);
  257. return 1;
  258. }
  259. sub BuildLngFile
  260. {
  261. my $self = shift;
  262. my $lng_id = shift;
  263. my $lng_file = shift;
  264. # Build lng file from po (need to have the location of the data-directory, opera version and buildno.
  265. #####################################################################################################
  266. return 0 if (!(-e $self->{_makelang_script}) || !(-e $self->{_english_db}) || !(-e $self->{_local_english_db}) || !(-e $self->{_build_strings}));
  267. my $makelang_command = "perl \"$self->{_makelang_script}\" -c 9 -q -u -E -p Win,$self->{_version},$self->{_build_nr} -o \"$lng_file\" -b \"$self->{_build_strings}\" $self->{_lang_options}";
  268. if ($lng_id ne "en") # po file only needed when building something other than english.
  269. {
  270. my $po_file = File::Spec->catfile($self->{_source_dir}, "data", "translations", "$lng_id", "$lng_id.po");
  271. $makelang_command .= " -t \"$po_file\"";
  272. return 0 if ( !(-e $po_file)); # We need the po file, but not if we are making english.
  273. if ((-e $lng_file) && (stat($lng_file))[9] > (stat($po_file))[9] && (stat($lng_file))[9] > (stat($self->{_english_db}))[9] && (stat($lng_file))[9] > (stat($self->{_local_english_db}))[9])
  274. {
  275. print FILESLIST File::Spec->abs2rel($lng_file, $self->{_target_dir})."\n";
  276. return 1;
  277. }
  278. }
  279. else
  280. {
  281. if ((-e $lng_file) && (stat($lng_file))[9] > (stat($self->{_english_db}))[9] && (stat($lng_file))[9] > (stat($self->{_local_english_db}))[9])
  282. {
  283. print FILESLIST File::Spec->abs2rel($lng_file, $self->{_target_dir})."\n";
  284. return 1;
  285. }
  286. }
  287. # Add the english.db and english_local.db databases
  288. $makelang_command .= " \"$self->{_english_db}\" \"$self->{_local_english_db}\"";
  289. my $result = `$makelang_command`; # Run the makelang command.
  290. if ($? != 0) # Pick up any errors.
  291. {
  292. return 0;
  293. }
  294. print FILESLIST File::Spec->abs2rel($lng_file, $self->{_target_dir})."\n";
  295. return 1;
  296. }
  297. sub AddLanguageFilesFor
  298. {
  299. my $self = shift;
  300. my $language = shift;
  301. # English localization files should *NOT* be added, the english.lng will be added separately.
  302. return 1 if ($language eq "en");
  303. my $locales_dir = File::Spec->catdir($self->{_target_dir}, "locale", $language);
  304. File::Path::mkpath($locales_dir);
  305. my $transl_dir = File::Spec->catdir($self->{_source_dir}, "data", "translations", $language);
  306. my $package_file; my $source_file;
  307. # Find and copy the bookmarks file.
  308. $package_file = File::Spec->catfile($locales_dir, "bookmarks.adr");
  309. $source_file = File::Spec->catfile($transl_dir, "default.adr");
  310. copy($source_file, $package_file) if (-e $source_file) and print FILESLIST File::Spec->abs2rel($package_file, $self->{_target_dir})."\n";
  311. # Find and copy search.ini file.
  312. $package_file = File::Spec->catfile($locales_dir, "search.ini");
  313. $source_file = File::Spec->catfile($transl_dir, "search.ini");
  314. copy($source_file, $package_file) if (-e $source_file) and print FILESLIST File::Spec->abs2rel($package_file, $self->{_target_dir})."\n";
  315. # Find and copy the speeddials file.
  316. $package_file = File::Spec->catfile($locales_dir, "standard_speeddial.ini");
  317. $source_file = File::Spec->catfile($transl_dir, "speeddial_default.ini");
  318. copy($source_file, $package_file) if (-e $source_file) and print FILESLIST File::Spec->abs2rel($package_file, $self->{_target_dir})."\n";
  319. # Find and copy the turbosettings file.
  320. $package_file = File::Spec->catfile($locales_dir, "turbosettings.xml");
  321. $source_file = File::Spec->catfile($transl_dir, "turbosettings.xml");
  322. copy($source_file, $package_file) if (-e $source_file) and print FILESLIST File::Spec->abs2rel($package_file, $self->{_target_dir})."\n";
  323. # Find and copy license file (if it exists)
  324. $package_file = File::Spec->catfile($locales_dir, "license.txt");
  325. $source_file = File::Spec->catfile($transl_dir, "license.txt");
  326. copy($source_file, $package_file) if (-e $source_file) and print FILESLIST File::Spec->abs2rel($package_file, $self->{_target_dir})."\n";
  327. # Need to generate the lng file for the language.
  328. $package_file = File::Spec->catfile($locales_dir, "$language.lng");
  329. $self->BuildLngFile($language, $package_file);
  330. if ($language =~ m/^zh-/i)
  331. {
  332. $package_file = File::Spec->catfile($locales_dir, "browser.js");
  333. copy($self->{_browser_js_src}, $package_file) if (-e $self->{_browser_js_src}) and print FILESLIST File::Spec->abs2rel($package_file, $self->{_target_dir})."\n";
  334. }
  335. return 1;
  336. }
  337. return 1;