From 6d15c6ea48691279b4d9898f4391780f9e8db1b9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 7 Apr 2020 11:54:21 -0700 Subject: [PATCH] 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 --- support/xhpast/Makefile | 5 +++-- .../xhpast-generate-nodes.php} | 21 ++++++++++++------- .../xhpast/bin/xhpast-generate-version.php | 8 +++++++ support/xhpast/xhpast.cpp | 7 +++++-- 4 files changed, 30 insertions(+), 11 deletions(-) rename support/xhpast/{generate_nodes.php => bin/xhpast-generate-nodes.php} (89%) create mode 100755 support/xhpast/bin/xhpast-generate-version.php diff --git a/support/xhpast/Makefile b/support/xhpast/Makefile index 3123cf1f..3686de3e 100644 --- a/support/xhpast/Makefile +++ b/support/xhpast/Makefile @@ -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 $@ $^ diff --git a/support/xhpast/generate_nodes.php b/support/xhpast/bin/xhpast-generate-nodes.php similarity index 89% rename from support/xhpast/generate_nodes.php rename to support/xhpast/bin/xhpast-generate-nodes.php index 22ea26cb..baf43687 100755 --- a/support/xhpast/generate_nodes.php +++ b/support/xhpast/bin/xhpast-generate-nodes.php @@ -1,9 +1,16 @@ #!/usr/bin/env php $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 .= <<