diff options
| -rwxr-xr-x | scripts/sphinx-pre-install | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/scripts/sphinx-pre-install b/scripts/sphinx-pre-install index f6a5c0bae31e..8c2d1bcf2e02 100755 --- a/scripts/sphinx-pre-install +++ b/scripts/sphinx-pre-install | |||
| @@ -13,7 +13,7 @@ use strict; | |||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. | 14 | # GNU General Public License for more details. |
| 15 | 15 | ||
| 16 | my $virtenv_dir = "sphinx_1.4"; | 16 | my $conf = "Documentation/conf.py"; |
| 17 | my $requirement_file = "Documentation/sphinx/requirements.txt"; | 17 | my $requirement_file = "Documentation/sphinx/requirements.txt"; |
| 18 | 18 | ||
| 19 | # | 19 | # |
| @@ -26,7 +26,9 @@ my $need = 0; | |||
| 26 | my $optional = 0; | 26 | my $optional = 0; |
| 27 | my $need_symlink = 0; | 27 | my $need_symlink = 0; |
| 28 | my $need_sphinx = 0; | 28 | my $need_sphinx = 0; |
| 29 | my $rec_sphinx_upgrade = 0; | ||
| 29 | my $install = ""; | 30 | my $install = ""; |
| 31 | my $virtenv_dir = "sphinx_"; | ||
| 30 | 32 | ||
| 31 | # | 33 | # |
| 32 | # Command line arguments | 34 | # Command line arguments |
| @@ -201,13 +203,15 @@ sub check_missing_tex($) | |||
| 201 | } | 203 | } |
| 202 | } | 204 | } |
| 203 | 205 | ||
| 204 | sub check_sphinx() | 206 | sub get_sphinx_fname() |
| 205 | { | 207 | { |
| 206 | return if findprog("sphinx-build"); | 208 | my $fname = "sphinx-build"; |
| 209 | return $fname if findprog($fname); | ||
| 207 | 210 | ||
| 208 | if (findprog("sphinx-build-3")) { | 211 | $fname = "sphinx-build-3"; |
| 212 | if (findprog($fname)) { | ||
| 209 | $need_symlink = 1; | 213 | $need_symlink = 1; |
| 210 | return; | 214 | return $fname; |
| 211 | } | 215 | } |
| 212 | 216 | ||
| 213 | if ($virtualenv) { | 217 | if ($virtualenv) { |
| @@ -219,6 +223,73 @@ sub check_sphinx() | |||
| 219 | } else { | 223 | } else { |
| 220 | add_package("python-sphinx", 0); | 224 | add_package("python-sphinx", 0); |
| 221 | } | 225 | } |
| 226 | |||
| 227 | return ""; | ||
| 228 | } | ||
| 229 | |||
| 230 | sub check_sphinx() | ||
| 231 | { | ||
| 232 | my $min_version; | ||
| 233 | my $rec_version; | ||
| 234 | my $cur_version; | ||
| 235 | |||
| 236 | open IN, $conf or die "Can't open $conf"; | ||
| 237 | while (<IN>) { | ||
| 238 | if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) { | ||
| 239 | $min_version=$1; | ||
| 240 | last; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | close IN; | ||
| 244 | |||
| 245 | die "Can't get needs_sphinx version from $conf" if (!$min_version); | ||
| 246 | |||
| 247 | open IN, $requirement_file or die "Can't open $requirement_file"; | ||
| 248 | while (<IN>) { | ||
| 249 | if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) { | ||
| 250 | $rec_version=$1; | ||
| 251 | last; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | close IN; | ||
| 255 | |||
| 256 | die "Can't get recommended sphinx version from $requirement_file" if (!$min_version); | ||
| 257 | |||
| 258 | $virtenv_dir .= $rec_version; | ||
| 259 | |||
| 260 | my $sphinx = get_sphinx_fname(); | ||
| 261 | return if ($sphinx eq ""); | ||
| 262 | |||
| 263 | open IN, "$sphinx --version 2>&1 |" or die "$sphinx returned an error"; | ||
| 264 | while (<IN>) { | ||
| 265 | if (m/^\s*sphinx-build\s+([\d\.]+)$/) { | ||
| 266 | $cur_version=$1; | ||
| 267 | last; | ||
| 268 | } | ||
| 269 | # Sphinx 1.2.x uses a different format | ||
| 270 | if (m/^\s*Sphinx.*\s+([\d\.]+)$/) { | ||
| 271 | $cur_version=$1; | ||
| 272 | last; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | close IN; | ||
| 276 | |||
| 277 | die "$sphinx didn't return its version" if (!$cur_version); | ||
| 278 | |||
| 279 | printf "Sphinx version %s (minimal: %s, recommended >= %s)\n", | ||
| 280 | $cur_version, $min_version, $rec_version; | ||
| 281 | |||
| 282 | if ($cur_version lt $min_version) { | ||
| 283 | print "Warning: Sphinx version should be >= $min_version\n\n"; | ||
| 284 | $need_sphinx = 1; | ||
| 285 | return; | ||
| 286 | } | ||
| 287 | |||
| 288 | if ($cur_version lt $rec_version) { | ||
| 289 | print "Warning: It is recommended at least Sphinx version $rec_version.\n"; | ||
| 290 | print " To upgrade, use:\n\n"; | ||
| 291 | $rec_sphinx_upgrade = 1; | ||
| 292 | } | ||
| 222 | } | 293 | } |
| 223 | 294 | ||
| 224 | # | 295 | # |
| @@ -540,7 +611,7 @@ sub check_needs() | |||
| 540 | printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n", | 611 | printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n", |
| 541 | which("sphinx-build-3"); | 612 | which("sphinx-build-3"); |
| 542 | } | 613 | } |
| 543 | if ($need_sphinx) { | 614 | if ($need_sphinx || $rec_sphinx_upgrade) { |
| 544 | my $activate = "$virtenv_dir/bin/activate"; | 615 | my $activate = "$virtenv_dir/bin/activate"; |
| 545 | if (-e "$ENV{'PWD'}/$activate") { | 616 | if (-e "$ENV{'PWD'}/$activate") { |
| 546 | printf "\nNeed to activate virtualenv with:\n"; | 617 | printf "\nNeed to activate virtualenv with:\n"; |
| @@ -554,7 +625,8 @@ sub check_needs() | |||
| 554 | printf "\t$virtualenv $virtenv_dir\n"; | 625 | printf "\t$virtualenv $virtenv_dir\n"; |
| 555 | printf "\t. $activate\n"; | 626 | printf "\t. $activate\n"; |
| 556 | printf "\tpip install -r $requirement_file\n"; | 627 | printf "\tpip install -r $requirement_file\n"; |
| 557 | $need++; | 628 | |
| 629 | $need++ if (!$rec_sphinx_upgrade); | ||
| 558 | } | 630 | } |
| 559 | } | 631 | } |
| 560 | printf "\n"; | 632 | printf "\n"; |
