From b0c69d0aed5736bb6793c84505d23fa9820ccb66 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Thu, 12 Feb 2015 15:17:19 -0300
Subject: [PATCH 36/37] deparse: pg_regress support generate_files_only

---
 src/test/regress/GNUmakefile  |  6 ++++++
 src/test/regress/pg_regress.c | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index 110eb80..9eafcd8 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -127,6 +127,12 @@ tablespace-setup:
 	rm -rf ./testtablespace
 	mkdir ./testtablespace
 
+# DDL-deparse setup
+
+.PHONY: generate-files
+generate-files:
+	$(top_builddir)/src/test/regress/pg_regress --generate-files-only --inputdir=$(srcdir)/input
+
 
 ##
 ## Run tests
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 31ea350..d81e772 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -107,6 +107,7 @@ static char *user = NULL;
 static _stringlist *extraroles = NULL;
 static _stringlist *extra_install = NULL;
 static char *config_auth_datadir = NULL;
+static bool generate_files_only = false;
 
 /* internal variables */
 static const char *progname;
@@ -2210,6 +2211,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
 		{"extra-install", required_argument, NULL, 23},
 		{"config-auth", required_argument, NULL, 24},
 		{"dbname-deparse", required_argument, NULL, 25},
+		{"generate-files-only", no_argument, NULL, 26},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -2338,6 +2340,9 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
 			case 25:
 				strncpy(deparse_test_db, optarg, sizeof(deparse_test_db));
 				break;
+			case 26:
+				generate_files_only = true;
+				break;
 			default:
 				/* getopt_long already emitted a complaint */
 				fprintf(stderr, _("\nTry \"%s -h\" for more information.\n"),
@@ -2378,6 +2383,12 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
 	outputdir = make_absolute_path(outputdir);
 	dlpath = make_absolute_path(dlpath);
 
+	if (generate_files_only)
+	{
+		convert_sourcefiles();
+		exit(0);
+	}
+
 	/*
 	 * Initialization
 	 */
-- 
2.1.4

