2
0
mirror of https://github.com/boostorg/website.git synced 2026-01-29 20:12:14 +00:00

Create super project class.

This commit is contained in:
Daniel James
2014-06-16 10:22:47 +01:00
parent 9c79ac8330
commit eff5d514b4
2 changed files with 77 additions and 58 deletions

View File

@@ -0,0 +1,72 @@
<?php
class BoostSuperProject {
/** Directory containing the super project */
var $location;
/** The git branch to use. False to use filesystem. */
var $git_branch;
function __construct($location, $git_branch = false) {
$this->location = $location;
$this->git_branch = $git_branch;
}
public function parse_config_file($path) {
if ($this->git_branch) {
if (git_version() >= array(1,8,4,0)) {
$blob = $this->run_git("ls-tree {$this->git_branch} \"{$path}\"");
$blob = preg_split("@[\t ]@", $blob[0])[2];
return $this->run_git("config -l --blob {$blob}");
}
else {
$temp_file = tempnam(sys_get_temp_dir(), 'boost-git-');
file_put_contents($temp_file, implode("\n",
$this->run_git("show \"{$this->git_branch}:{$path}\"")));
$result = $this->run_git("config -l -f \"{$temp_file}\"");
unlink($temp_file);
return $result;
}
}
else {
return $this->run_git("config -l -f \"{$path}\"");
}
}
public function run_git($command) {
return run_process("git -C \"{$this->location}\" {$command}");
}
}
function git_version() {
$output = run_process("git --version");
$match = null;
if (count($output) == 1
&& preg_match('@^git version ([0-9.]+)$@', $output[0], $match))
{
return array_pad(explode('.', $match[1]), 4, 0);
}
else {
return array(0,0,0,0);
}
}
function run_process($command) {
exec($command, $output, $return_var);
if ($return_var != 0) {
throw new ProcessError($return_var);
}
return $output;
}
class ProcessError extends RuntimeException {
public $error_code;
function __construct($error_code) {
$this->error_code = $error_code;
parent::__construct("Process failed with status: {$error_code}");
}
}

View File

@@ -1,6 +1,7 @@
<?php
require_once(dirname(__FILE__) . '/../common/code/boost_libraries.php');
require_once(dirname(__FILE__) . '/boost_super_project.php');
function main() {
$args = $_SERVER['argv'];
@@ -74,10 +75,10 @@ function update_from_git($libs, $location, $branch) {
echo "Updating from {$branch}\n";
$git_command = "cd '${location}' && git";
$super_project = new BoostSuperProject($location, $branch);
$modules = Array();
foreach(git_config_from_repo($git_command, $branch, ".gitmodules")
as $line_number => $line)
foreach($super_project->parse_config_file(".gitmodules") as $line_number => $line)
{
if (!$line) continue;
@@ -94,7 +95,8 @@ function update_from_git($libs, $location, $branch) {
$modules_by_path[$details['path']] = $name;
}
foreach(run_process("{$git_command} ls-tree {$branch} ".implode(' ', array_keys($modules_by_path)))
foreach($super_project->run_git(
"ls-tree {$branch} ".implode(' ', array_keys($modules_by_path)))
as $line_number => $line)
{
if (!$line) continue;
@@ -169,42 +171,6 @@ function load_from_text($text, $filename, $branch) {
return $new_libs;
}
function git_config_from_repo($git_command, $branch, $path) {
$temp_file = null;
if (git_version($git_command) >= array(1,8,4,0))
{
$blob = run_process("{$git_command} ls-tree {$branch} .gitmodules "
."| cut -f 1 | cut -f 3 -d ' '");
$file_param = "--blob {$blob[0]}";
}
else
{
$temp_file = tempnam(sys_get_temp_dir(), 'boost-git-');
run_process("{$git_command} show {$branch}:{$path} ".
"> {$temp_file}");
$file_param = "-f {$temp_file}";
}
$result = run_process("{$git_command} config -l {$file_param}");
if ($temp_file) unlink($temp_file);
return $result;
}
function git_version($git_command) {
$output = run_process("{$git_command} --version");
$match = null;
if (count($output) == 1
&& preg_match('@^git version ([0-9.]+)$@', $output[0], $match))
{
return array_pad(explode('.', $output[0]), 4, 0);
}
else {
return array(0,0,0,0);
}
}
function get_bool_from_array($array) {
if (count($array) != 1) throw new RuntimeException("get_bool_from_array: invalid array");
switch ($array[0]) {
@@ -214,23 +180,4 @@ function get_bool_from_array($array) {
}
}
class ProcessError extends RuntimeException {
public $error_code;
function __construct($error_code) {
$this->error_code = $error_code;
parent::__construct("Process failed with status: {$error_code}");
}
}
function run_process($command) {
exec($command, $output, $return_var);
if ($return_var != 0) {
throw new ProcessError($return_var);
}
return $output;
}
main();