10 private $output_dir =
'.';
11 private $opts = array();
13 private $targets_path =
'';
14 private $xulruntimes_path =
'';
15 private $xulapp_path =
'';
16 private $xulapp_appini =
'';
20 public function __construct($output_dir =
'.', $opts = array()) {
21 $this->output_dir = $output_dir;
27 private function _initPath() {
28 include_once(
'WHAT/Lib.Prefix.php');
32 $this->
targets_path = sprintf(
'%s/%s', $pubdir, self::targets_path);
34 $this->
xulapp_path = sprintf(
'%s/%s', $pubdir, self::xulapp_path);
35 $this->
xulapp_appini = sprintf(
'%s/%s', $pubdir, self::xulapp_appini);
41 public function build($buildid, $os, $arch, $prefix, $outputFile, $mar_basename=
'') {
42 include_once(
'WHAT/Lib.Common.php');
46 if( strpos($os,
'/') !==
false ) {
47 $this->error = sprintf(
"Malformed OS '%s' (cannot contain '/').", $os);
50 if( strpos($arch,
'/') !==
false ) {
51 $this->error = sprintf(
"Marlformed architecture '%s' (cannot contain '/').", $arch);
55 $target_dir = sprintf(
"%s/%s/%s", $this->
targets_path, $os, $arch);
56 if( ! is_dir($target_dir) ) {
57 $this->error = sprintf(
"Target directory '%s' is not a valid directory.", $target_dir);
60 $build_script = sprintf(
'%s/build.sh', $target_dir);
61 if( ! is_file($build_script) ) {
62 $this->error = sprintf(
"Build script '%s' is not a valid file.", $build_script);
65 if( ! is_executable($build_script) ) {
66 $this->error = sprintf(
"Build script '%s' is not executable.", $build_script);
70 if( ! is_dir($this->output_dir) ) {
71 $this->error = sprintf(
"Output dir '%s' does not exists.", $this->output_dir);
74 if( ! is_writable($this->output_dir) ) {
75 $this->error = sprintf(
"Output dir '%s' is not writable.", $this->output_dir);
79 $tmpfile = tempnam(getTmpDir(), __CLASS__);
80 if( $tmpfile ===
false ) {
81 $this->error = sprintf(
"Could not create temporary file.");
85 $prefix = $this->
expandFilename($prefix, array(
'OS' => $os,
'ARCH' => $arch));
86 $outputFile = sprintf(
'%s/%s', $this->output_dir, $this->
expandFilename($outputFile, array(
'OS' => $os,
'ARCH' => $arch)));
88 $envBackup = $this->getEnv(array(
95 'OFFLINE_SERVER_VERSION',
96 'DCPOFFLINE_URL_BROWSER',
97 'DCPOFFLINE_URL_DATA',
98 'DCPOFFLINE_URL_UPDATE')
101 $env[
'wpub'] = $pubdir;
102 if( isset($this->opts[
'CUSTOMIZE_DIR']) ) {
103 $env[
'CUSTOMIZE_DIR'] = $this->opts[
'CUSTOMIZE_DIR'];
106 $env[
'APP_BUILDID'] = $buildid;
107 $env[
'CLIENTS_DIR'] = $this->output_dir;
108 $env[
'APP_UPDATE_ENABLED'] = getParam(
'OFFLINE_CLIENT_UPDATE_ENABLED');
110 $env[
'DCPOFFLINE_URL_BROWSER'] = getParam(
'DCPOFFLINE_URL_BROWSER');
111 $env[
'DCPOFFLINE_URL_DATA'] = getParam(
'DCPOFFLINE_URL_DATA');
112 $env[
'DCPOFFLINE_URL_UPDATE'] = getParam(
'DCPOFFLINE_URL_UPDATE');
115 $cmd = sprintf(
'%s %s %s %s > %s 2>&1', escapeshellarg($build_script), escapeshellarg($prefix), escapeshellarg($outputFile), escapeshellarg($mar_basename), escapeshellarg($tmpfile));
116 $out = system($cmd, $ret);
118 $this->error = sprintf(
"Error building client for {os='%s', arch='%s', prefix='%s', outputFile='%s', basename='%s'}: %s", $os, $arch, $prefix, $outputFile, $mar_basename, file_get_contents($tmpfile));
121 $this->setEnv($envBackup);
124 return ($ret === 0) ?
true :
false;
127 private function getEnv($varList = array()) {
129 foreach( $varList as $var ) {
130 $env []= array($var => getenv($var));
135 private function setEnv($env = array()) {
136 foreach( $env as $var => $value ) {
137 if( $value ===
false ) {
140 putenv(sprintf(
'%s=%s', $var, $value));
146 if( $buildid ==
'' ) {
147 $buildid = strftime(
"%Y%m%d%H%M%S");
155 3 => $spec[
'prefix'],
157 5 => $spec[
'mar_basename']
160 $ret = call_user_func_array(array($this,
'build'), $argv);
161 if( $ret ===
false ) {
162 $this->error = sprintf(
"Error building {os:'%s', arch:'%s'}: %s", $spec[
'os'], $spec[
'arch'], $this->error);
170 include_once(
'WHAT/Lib.Prefix.php');
176 'title' =>
'Linux (i686)',
179 'icon' =>
'icon-linux.png',
180 'prefix' =>
'dynacase-offline-%VERSION%',
181 'file' =>
'dynacase-offline-linux-i686.tar.gz',
182 'mar_basename' =>
'dynacase-offline-linux-i686'
185 'title' =>
'Linux (x86_64)',
188 'icon' =>
'icon-linux.png',
189 'prefix' =>
'dynacase-offline-%VERSION%',
190 'file' =>
'dynacase-offline-linux-x86_64.tar.gz',
191 'mar_basename' =>
'dynacase-offline-linux-x86_64'
194 'title' =>
'Mac OS X (universal)',
196 'arch' =>
'universal',
197 'icon' =>
'icon-mac.png',
198 'prefix' =>
'dynacase-offline-%VERSION%',
199 'file' =>
'dynacase-offline-mac-universal.zip',
200 'mar_basename' =>
'dynacase-offline-mac-universal'
203 'title' =>
'Windows XP/Vista/7 (EXE 32 bits)',
206 'icon' =>
'icon-win.png',
207 'prefix' =>
'dynacase-offline-%VERSION%',
208 'file' =>
'dynacase-offline-win-32.exe',
209 'mar_basename' =>
'dynacase-offline-win-32'
212 'title' =>
'Windows XP/Vista/7 (Zip 32 bits)',
215 'icon' =>
'icon-win.png',
216 'prefix' =>
'dynacase-offline-%VERSION%',
217 'file' =>
'dynacase-offline-win-32.zip',
218 'mar_basename' =>
'dynacase-offline-win-32'
222 $local_osArchList = sprintf(
'%s/OFFLINE/local_osArchList.php', $pubdir);
223 if( file_exists($local_osArchList) ) {
224 include_once($local_osArchList);
233 foreach( $keymap as $k => $v ) {
234 $filename = str_replace(sprintf(
'%%%s%%', $k), $v, $filename);
240 public static function test() {
243 $buildid = strftime(
"%Y%m%d%H%M%S");
245 foreach( $ocb->getOsArchList() as $spec ) {
251 3 => $spec[
'prefix'],
253 5 => $spec[
'mar_basename']
256 print sprintf(
"Building %s/%s... ", $argv[0], $argv[1]);
257 $ret = call_user_func_array(array($ocb,
'build'), $argv);
258 if( $ret ===
false ) {
260 print sprintf(
"%s\n", $ocb->error);
270 if( ! is_array($conf) ) {
274 case 'Version.Customize':
276 if( isset($conf[
'App'][
'Version']) ) {
277 return sprintf(
"%s.%d", $conf[
'App'][
'Version'], $customizeRelease);
281 if( isset($conf[
'App'][$info]) ) {
282 return $conf[
'App'][$info];
289 $customizeRelease = 0;
291 return $customizeRelease;
293 if( preg_match(
'/^\s*(?<release>\d+)/', file_get_contents($this->
customize_release), $m) ) {
294 $customizeRelease = $m[
'release'];
296 return $customizeRelease;
305 include_once(
'WHAT/Class.Application.php');
306 $app =
new Application();
307 $app->Set(
'OFFLINE', $core);
308 $version = $app->getParam(
'VERSION');
getOfflineServerVersion()
expandFilename($filename, $keymap=array())
__construct($output_dir= '.', $opts=array())
build($buildid, $os, $arch, $prefix, $outputFile, $mar_basename='')
getOfflineInfo($info='Version')