From eff5d514b4056b580e35d63477801078d6ce1615 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 16 Jun 2014 10:22:47 +0100 Subject: [PATCH] Create super project class. --- site-tools/boost_super_project.php | 72 ++++++++++++++++++++++++++++++ site-tools/update-doc-list.php | 63 +++----------------------- 2 files changed, 77 insertions(+), 58 deletions(-) create mode 100644 site-tools/boost_super_project.php diff --git a/site-tools/boost_super_project.php b/site-tools/boost_super_project.php new file mode 100644 index 00000000..3eaec724 --- /dev/null +++ b/site-tools/boost_super_project.php @@ -0,0 +1,72 @@ +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}"); + } +} diff --git a/site-tools/update-doc-list.php b/site-tools/update-doc-list.php index 9ca69891..855c7e99 100644 --- a/site-tools/update-doc-list.php +++ b/site-tools/update-doc-list.php @@ -1,6 +1,7 @@ $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();