1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 08:12:40 +01:00

Remove duplication of XHPAST version in PHP and C code

Summary:
Depends on D21063. Ref T13492. Currently, XHPAST defines a version in both PHP code and C code, and they must be kept in sync.

Switch to a single definition in PHP, then carry it through the build pipeline into C.

Test Plan: Did a clean rebuild of XHPAST, saw a version number carried in from PHP. Ran "xhpast --version".

Maniphest Tasks: T13492

Differential Revision: https://secure.phabricator.com/D21064
This commit is contained in:
epriestley 2020-04-07 11:54:21 -07:00
parent 763ac445dc
commit 6d15c6ea48
4 changed files with 30 additions and 11 deletions

View file

@ -1,6 +1,7 @@
BISONFLAGS = --verbose --name-prefix xhpast
CPPFLAGS = -fPIC -Wall
FLEXFLAGS = -CFr
XHPAST_VERSION := $(shell ./bin/xhpast-generate-version.php)
ifdef DEBUG
BISONFLAGS += --debug
@ -64,7 +65,7 @@ endif
%.o: %.cpp
$(CXX) -c $(CPPFLAGS) -o $@ $<
node_names.hpp parser_nodes.php: generate_nodes.php
node_names.hpp parser_nodes.php: bin/xhpast-generate-nodes.php
php -f $<
parser.yacc.o: scanner.lex.hpp
@ -74,4 +75,4 @@ libxhpast.a: scanner.lex.o parser.yacc.o
$(AR) -crs $@ $^
xhpast: xhpast.cpp libxhpast.a
$(CXX) $(CPPFLAGS) -o $@ $^
$(CXX) $(CPPFLAGS) -D XHPAST_VERSION='"$(XHPAST_VERSION)"' -o $@ $^

View file

@ -1,9 +1,16 @@
#!/usr/bin/env php
<?php
require_once dirname(__FILE__).'/../../scripts/__init_script__.php';
$arcanist_root = dirname(dirname(dirname(dirname(__FILE__))));
require_once $arcanist_root.'/support/init/init-script.php';
$xhpast_root = dirname(dirname(__FILE__));
$hpp_outpath = $xhpast_root.'/node_names.hpp';
$php_outpath = $xhpast_root.'/parser_nodes.php';
$offset = 9000;
$nodes = array(
'n_PROGRAM',
'n_SYMBOL_NAME',
@ -132,9 +139,9 @@ $hpp = '';
foreach ($nodes as $node => $value) {
$hpp .= "#define {$node} {$value}\n";
}
Filesystem::writeFile(
Filesystem::resolvePath('node_names.hpp', dirname(__FILE__)),
$hpp);
Filesystem::writeFile($hpp_outpath, $hpp);
echo pht('Wrote C++ definition.')."\n";
$at = '@';
@ -158,7 +165,7 @@ $php .= <<<EOPHP
}
EOPHP;
Filesystem::writeFile(
Filesystem::resolvePath('parser_nodes.php', dirname(__FILE__)),
$php);
Filesystem::writeFile($php_outpath, $php);
echo pht('Wrote PHP definition.')."\n";

View file

@ -0,0 +1,8 @@
#!/usr/bin/env php
<?php
$arcanist_root = dirname(dirname(dirname(dirname(__FILE__))));
require_once $arcanist_root.'/support/init/init-script.php';
echo PhutilXHPASTBinary::EXPECTED_VERSION;
echo "\n";

View file

@ -9,10 +9,13 @@ int xhpastparse(void*, xhpast::Node **);
int xhpast_process(std::string &in);
void print_node(xhpast::Node *node);
#ifndef XHPAST_VERSION
#error Define XHPAST_VERSION when building XHPAST.
#endif
int main(int argc, char* argv[]) {
if (argc != 1) {
// Coupling: modify also src/parser/xhpast/bin/PhutilXHPASTBinary.php
cout << "7.1.4\n";
cout << XHPAST_VERSION << "\n";
return 0;
}