1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Unify code builder binaries into a single binary.

Creating new binaries was convenient at first but has now become a maintenance issue.

Solve this by combining that into a single binary that takes an additional parameter to indicate which code should be built.

Also clean up path handling to make it easier to build code from the command line.
This commit is contained in:
David Steele
2022-07-20 17:45:39 -04:00
parent 7eb5d67985
commit c625f05a13
23 changed files with 100 additions and 329 deletions

2
src/.gitignore vendored
View File

@ -7,4 +7,4 @@ autom4te.cache
/build.auto.h
/pgbackrest
/postgres/interface.auto.c.inc
/build-*
/build-code

View File

@ -5,7 +5,7 @@
####################################################################################################################################
# List of required source files. main.c should always be listed last and the rest in alpha order.
####################################################################################################################################
SRCS_BUILD = \
SRCS_COMMON = \
common/compress/bz2/common.c \
common/compress/bz2/compress.c \
common/debug.c \
@ -201,79 +201,39 @@ BUILDDIR=.build
####################################################################################################################################
# Compile and link pgbackrest
####################################################################################################################################
OBJS_PGBACKREST = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS_BUILD) $(SRCS_PGBACKREST) $(SRCS) main.c)
OBJS_PGBACKREST = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS_COMMON) $(SRCS) main.c)
pgbackrest: $(OBJS_PGBACKREST)
$(CC) -o pgbackrest $(OBJS_PGBACKREST) $(LDFLAGS) $(LIBS)
####################################################################################################################################
# Compile and link config generator
# Compile and link code builder
####################################################################################################################################
SRCS_BUILD_CONFIG = \
SRCS_BUILD_CODE = \
build/common/render.c \
build/common/yaml.c \
build/config/main.c \
build/config/parse.c \
build/config/render.c
OBJS_BUILD_CONFIG = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS_BUILD) $(SRCS_BUILD_CONFIG))
build-config: $(OBJS_BUILD_CONFIG) build/config/config.yaml config/config.auto.h config/parse.auto.c.inc
$(CC) -o build-config $(OBJS_BUILD_CONFIG) $(LDFLAGS) $(LIBS) $(LIBS_BUILD)
./build-config $(VPATH)
####################################################################################################################################
# Compile and link error generator
####################################################################################################################################
SRCS_BUILD_ERROR = \
build/common/render.c \
build/common/yaml.c \
build/error/main.c \
build/config/render.c \
build/error/parse.c \
build/error/render.c
OBJS_BUILD_ERROR = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS_BUILD) $(SRCS_BUILD_ERROR))
build-error: $(OBJS_BUILD_ERROR) build/error/error.yaml
$(CC) -o build-error $(OBJS_BUILD_ERROR) $(LDFLAGS) $(LIBS) $(LIBS_BUILD)
./build-error $(VPATH)
####################################################################################################################################
# Compile and link help generator
####################################################################################################################################
SRCS_BUILD_HELP = \
build/common/render.c \
build/common/yaml.c \
build/config/parse.c \
build/error/render.c \
build/help/parse.c \
build/help/render.c \
build/help/main.c
OBJS_BUILD_HELP = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS_BUILD) $(SRCS_BUILD_HELP))
build-help: $(OBJS_BUILD_HELP) build/config/config.yaml build/help/help.xml
$(CC) -o build-help $(OBJS_BUILD_HELP) $(LDFLAGS) $(LIBS) $(LIBS_BUILD)
command/help/help.auto.c.inc: build-help
./build-help $(VPATH)
####################################################################################################################################
# Compile and link postgres interface generator
####################################################################################################################################
SRCS_BUILD_POSTGRES = \
build/common/render.c \
build/common/yaml.c \
build/postgres/parse.c \
build/postgres/render.c \
build/postgres/main.c
build/main.c
OBJS_BUILD_POSTGRES = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS_BUILD) $(SRCS_BUILD_POSTGRES))
OBJS_BUILD_CODE = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS_COMMON) $(SRCS_BUILD_CODE))
build-postgres: $(OBJS_BUILD_POSTGRES) build/postgres/postgres.yaml
$(CC) -o build-postgres $(OBJS_BUILD_POSTGRES) $(LDFLAGS) $(LIBS) $(LIBS_BUILD)
build-code: $(OBJS_BUILD_CODE) build/postgres/postgres.yaml build/config/config.yaml build/help/help.xml
$(CC) -o build-code $(OBJS_BUILD_CODE) $(LDFLAGS) $(LIBS) $(LIBS_BUILD)
postgres/interface.auto.c.inc: build-postgres
./build-postgres $(VPATH)
# Build help.auto.c.inc
command/help/help.auto.c.inc: build-code
./build-code help $(VPATH)
# Build interface.auto.c.inc
postgres/interface.auto.c.inc: build-code
./build-code postgres $(VPATH)
####################################################################################################################################
# Installation. DESTDIR can be used to modify the install location.
@ -296,7 +256,7 @@ uninstall:
# Clean build files and executable created by make
clean:
rm -rf $(BUILDDIR)
rm -f pgbackrest build-config build-error build-help build-postgres command/help/help.auto.c.inc postgres/interface.auto.c.inc
rm -f pgbackrest build-code command/help/help.auto.c.inc postgres/interface.auto.c.inc
.PHONY = clean-all

View File

@ -46,7 +46,7 @@ bldHeader(const char *const module, const char *const description)
COMMENT_BLOCK_BEGIN "\n"
"%s\n"
"\n"
"Automatically generated by 'make build-%s' -- do not modify directly.\n"
"Automatically generated by 'build-code %s' -- do not modify directly.\n"
COMMENT_BLOCK_END "\n",
description, module);
}

View File

@ -1,63 +0,0 @@
/***********************************************************************************************************************************
Auto-Generate Command and Option Configuration Enums, Constants and Data
***********************************************************************************************************************************/
#include "build.auto.h"
#include <unistd.h>
#include "common/log.h"
#include "storage/posix/storage.h"
#include "build/config/parse.h"
#include "build/config/render.h"
int
main(int argListSize, const char *argList[])
{
// Check parameters
CHECK(ParamInvalidError, argListSize <= 3, "only two parameters allowed");
// Initialize logging
logInit(logLevelWarn, logLevelError, logLevelOff, false, 0, 1, false);
// Get current working dir
char currentWorkDir[1024];
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
// If the repo path was specified
const String *pathRepo = strPath(STR(currentWorkDir));
String *const pathOut = strCatZ(strNew(), currentWorkDir);
if (argListSize >= 2)
{
const String *const pathArg = STR(argList[1]);
if (strBeginsWith(pathArg, FSLASH_STR))
pathRepo = strPath(pathArg);
else
{
pathRepo = strPathAbsolute(pathArg, STR(currentWorkDir));
strCatZ(pathOut, "/src");
}
}
// If the build path was specified
const String *pathBuild = pathRepo;
if (argListSize >= 3)
{
const String *const pathArg = STR(argList[2]);
if (strBeginsWith(pathArg, FSLASH_STR))
pathBuild = strPath(pathArg);
else
pathBuild = strPathAbsolute(pathArg, STR(currentWorkDir));
}
// Render config
const Storage *const storageRepo = storagePosixNewP(pathRepo);
const Storage *const storageBuild = storagePosixNewP(pathBuild, .write = true);
bldCfgRender(storageBuild, bldCfgParse(storageRepo), true);
return 0;
}

View File

@ -1,44 +0,0 @@
/***********************************************************************************************************************************
Auto-Generate Errors
***********************************************************************************************************************************/
#include "build.auto.h"
#include <unistd.h>
#include "common/log.h"
#include "storage/posix/storage.h"
#include "build/error/parse.h"
#include "build/error/render.h"
int
main(int argListSize, const char *argList[])
{
// Check parameters
CHECK(ParamInvalidError, argListSize <= 2, "only one parameter allowed");
// Initialize logging
logInit(logLevelWarn, logLevelError, logLevelOff, false, 0, 1, false);
// If the path was specified
const String *pathRepo;
if (argListSize >= 2)
{
pathRepo = strPath(STR(argList[1]));
}
// Else use current working directory
else
{
char currentWorkDir[1024];
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
pathRepo = strPath(STR(currentWorkDir));
}
// Render error
const Storage *const storageRepo = storagePosixNewP(pathRepo, .write = true);
bldErrRender(storageRepo, bldErrParse(storageRepo));
return 0;
}

View File

@ -325,7 +325,7 @@ bldHlpRenderHelpAutoC(const Storage *const storageRepo, const BldCfg bldCfg, con
strCatZ(help, "\n};\n");
// Write to storage
bldPut(storageRepo, "command/help/help.auto.c.inc", BUFSTR(help));
bldPut(storageRepo, "src/command/help/help.auto.c.inc", BUFSTR(help));
}
/**********************************************************************************************************************************/

View File

@ -1,5 +1,5 @@
/***********************************************************************************************************************************
Auto-Generate Help
Code Builder
***********************************************************************************************************************************/
#include "build.auto.h"
@ -9,14 +9,19 @@ Auto-Generate Help
#include "storage/posix/storage.h"
#include "build/config/parse.h"
#include "build/config/render.h"
#include "build/error/parse.h"
#include "build/error/render.h"
#include "build/help/parse.h"
#include "build/help/render.h"
#include "build/postgres/parse.h"
#include "build/postgres/render.h"
int
main(int argListSize, const char *argList[])
main(const int argListSize, const char *const argList[])
{
// Check parameters
CHECK(ParamInvalidError, argListSize <= 3, "only two parameters allowed");
CHECK(ParamInvalidError, argListSize >= 2 && argListSize <= 4, "only one to three parameters allowed");
// Initialize logging
logInit(logLevelWarn, logLevelError, logLevelOff, false, 0, 1, false);
@ -27,37 +32,53 @@ main(int argListSize, const char *argList[])
// Get repo path (cwd if it was not passed)
const String *pathRepo = strPath(STR(currentWorkDir));
String *pathBuild = strCatZ(strNew(), currentWorkDir);
String *pathBuild = strCat(strNew(), pathRepo);
if (argListSize >= 2)
{
const String *const pathArg = STR(argList[1]);
if (strBeginsWith(pathArg, FSLASH_STR))
pathRepo = strPath(pathArg);
else
{
pathRepo = strPathAbsolute(pathArg, STR(currentWorkDir));
strCatZ(pathBuild, "/src");
}
}
// If the build path was specified
if (argListSize >= 3)
{
const String *const pathArg = STR(argList[2]);
if (strBeginsWith(pathArg, FSLASH_STR))
pathBuild = strPath(pathArg);
pathRepo = strPath(pathArg);
else
pathRepo = strPathAbsolute(pathArg, STR(currentWorkDir));
pathBuild = strDup(pathRepo);
}
// If the build path was specified
if (argListSize >= 4)
{
const String *const pathArg = STR(argList[3]);
if (strBeginsWith(pathArg, FSLASH_STR))
pathBuild = strDup(pathArg);
else
pathBuild = strPathAbsolute(pathArg, STR(currentWorkDir));
}
// Render help
// Repo and build storage
const Storage *const storageRepo = storagePosixNewP(pathRepo);
const Storage *const storageBuild = storagePosixNewP(pathBuild, .write = true);
// Config
if (strEqZ(STRDEF("config"), argList[1]))
bldCfgRender(storageBuild, bldCfgParse(storageRepo), true);
// Error
if (strEqZ(STRDEF("error"), argList[1]))
bldErrRender(storageRepo, bldErrParse(storageRepo));
// Help
if (strEqZ(STRDEF("help"), argList[1]))
{
const BldCfg bldCfg = bldCfgParse(storageRepo);
bldHlpRender(storageBuild, bldCfg, bldHlpParse(storageRepo, bldCfg));
}
// PostgreSQL
if (strEqZ(STRDEF("postgres"), argList[1]))
bldPgRender(storageBuild, bldPgParse(storageRepo));
return 0;
}

View File

@ -1,50 +0,0 @@
/***********************************************************************************************************************************
Auto-Generate PostgreSQL Interface
***********************************************************************************************************************************/
#include "build.auto.h"
#include <unistd.h>
#include "common/log.h"
#include "storage/posix/storage.h"
#include "build/postgres/parse.h"
#include "build/postgres/render.h"
int
main(int argListSize, const char *argList[])
{
// Check parameters
CHECK(ParamInvalidError, argListSize <= 2, "only one parameter allowed");
// Initialize logging
logInit(logLevelWarn, logLevelError, logLevelOff, false, 0, 1, false);
// Get current working directory
char currentWorkDir[1024];
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
// Get repo path (cwd if it was not passed)
const String *pathRepo = strPath(STR(currentWorkDir));
String *const pathOut = strCatZ(strNew(), currentWorkDir);
if (argListSize >= 2)
{
const String *const pathArg = STR(argList[1]);
if (strBeginsWith(pathArg, FSLASH_STR))
pathRepo = strPath(pathArg);
else
{
pathRepo = strPathAbsolute(pathArg, STR(currentWorkDir));
strCatZ(pathOut, "/src");
}
}
// Render postgres
const Storage *const storageRepo = storagePosixNewP(pathRepo);
const Storage *const storageBuild = storagePosixNewP(pathOut, .write = true);
bldPgRender(storageBuild, bldPgParse(storageRepo));
return 0;
}

View File

@ -131,7 +131,7 @@ bldPgRenderInterfaceAutoC(const Storage *const storageRepo, const BldPg bldPg)
pg,
"};\n");
bldPut(storageRepo, "postgres/interface.auto.c.inc", BUFSTR(pg));
bldPut(storageRepo, "src/postgres/interface.auto.c.inc", BUFSTR(pg));
}
/**********************************************************************************************************************************/

View File

@ -9,7 +9,8 @@ help_auto_c_inc = custom_target(
'../../build/help/help.xml',
],
command : [
build_help,
'@CURRENT_SOURCE_DIR@/../../..'
build_code,
'help',
'@CURRENT_SOURCE_DIR@/../../..',
],
)

View File

@ -1,7 +1,7 @@
/***********************************************************************************************************************************
Error Type Definition
Automatically generated by 'make build-error' -- do not modify directly.
Automatically generated by 'build-code error' -- do not modify directly.
***********************************************************************************************************************************/
/***********************************************************************************************************************************

View File

@ -1,7 +1,7 @@
/***********************************************************************************************************************************
Error Type Definition
Automatically generated by 'make build-error' -- do not modify directly.
Automatically generated by 'build-code error' -- do not modify directly.
***********************************************************************************************************************************/
#ifndef COMMON_ERROR_AUTO_H
#define COMMON_ERROR_AUTO_H

View File

@ -1,7 +1,7 @@
/***********************************************************************************************************************************
Command and Option Configuration
Automatically generated by 'make build-config' -- do not modify directly.
Automatically generated by 'build-code config' -- do not modify directly.
***********************************************************************************************************************************/
#ifndef CONFIG_CONFIG_AUTO_H
#define CONFIG_CONFIG_AUTO_H

View File

@ -1,7 +1,7 @@
/***********************************************************************************************************************************
Config Parse Rules
Automatically generated by 'make build-config' -- do not modify directly.
Automatically generated by 'build-code config' -- do not modify directly.
***********************************************************************************************************************************/
/***********************************************************************************************************************************

View File

@ -51,66 +51,29 @@ src_common = files(
)
####################################################################################################################################
# Build config target
# Build code target
####################################################################################################################################
src_build_config = [
src_build_code = [
'build/common/render.c',
'build/common/yaml.c',
'build/config/main.c',
'build/config/parse.c',
'build/config/render.c',
]
build_config = executable(
'build-config',
src_common,
src_build_config,
dependencies : [
lib_yaml
],
build_by_default: false,
)
####################################################################################################################################
# Build error target
####################################################################################################################################
src_build_error = [
'build/common/render.c',
'build/common/yaml.c',
'build/error/main.c',
'build/error/parse.c',
'build/error/render.c',
]
build_error = executable(
'build-error',
src_common,
src_build_error,
dependencies : [
lib_yaml
],
build_by_default: false,
)
####################################################################################################################################
# Build help target
####################################################################################################################################
src_build_help = [
'build/common/render.c',
'build/common/yaml.c',
'build/config/parse.c',
'build/help/main.c',
'build/help/parse.c',
'build/help/render.c',
'build/postgres/parse.c',
'build/postgres/render.c',
'build/main.c',
'common/compress/bz2/common.c',
'common/compress/bz2/compress.c',
'common/type/xml.c',
]
build_help = executable(
'build-help',
build_code = executable(
'build-code',
src_common,
src_build_help,
src_build_code,
dependencies: [
lib_bz2,
lib_xml,
@ -118,30 +81,10 @@ build_help = executable(
],
)
# build help.auto.c.inc
# Build help.auto.c.inc
subdir('command/help')
####################################################################################################################################
# Build postgres target
####################################################################################################################################
src_build_postgres = [
'build/common/render.c',
'build/common/yaml.c',
'build/postgres/main.c',
'build/postgres/parse.c',
'build/postgres/render.c',
]
build_postgres = executable(
'build-postgres',
src_common,
src_build_postgres,
dependencies : [
lib_yaml
],
)
# build interface.auto.c.inc
# Build interface.auto.c.inc
subdir('postgres')
####################################################################################################################################

View File

@ -8,7 +8,8 @@ interface_auto_c_inc = custom_target(
'../build/postgres/postgres.yaml',
],
command : [
build_postgres,
'@CURRENT_SOURCE_DIR@/../..'
build_code,
'postgres',
'@CURRENT_SOURCE_DIR@/../..',
],
)

View File

@ -9,7 +9,8 @@ test_help_auto_c_inc = custom_target(
'../../build/help/help.xml',
],
command: [
build_help,
build_code,
'help',
'@CURRENT_SOURCE_DIR@/../../..',
'@BUILD_ROOT@/test/src',
],

View File

@ -8,7 +8,8 @@ test_parse_auto_c_inc = custom_target(
'../build/config/config.yaml',
],
command : [
build_config,
build_code,
'config',
'@CURRENT_SOURCE_DIR@/../..',
'@BUILD_ROOT@/test',
],

View File

@ -452,7 +452,7 @@ testRun(void)
COMMENT_BLOCK_BEGIN "\n"
"Command and Option Configuration\n"
"\n"
"Automatically generated by 'make build-config' -- do not modify directly.\n"
"Automatically generated by 'build-code config' -- do not modify directly.\n"
COMMENT_BLOCK_END "\n"
"#ifndef CONFIG_CONFIG_AUTO_H\n"
"#define CONFIG_CONFIG_AUTO_H\n"
@ -569,7 +569,7 @@ testRun(void)
COMMENT_BLOCK_BEGIN "\n"
"Config Parse Rules\n"
"\n"
"Automatically generated by 'make build-config' -- do not modify directly.\n"
"Automatically generated by 'build-code config' -- do not modify directly.\n"
COMMENT_BLOCK_END "\n"
"\n"
COMMENT_BLOCK_BEGIN "\n"

View File

@ -61,7 +61,7 @@ testRun(void)
COMMENT_BLOCK_BEGIN "\n"
"Error Type Definition\n"
"\n"
"Automatically generated by 'make build-error' -- do not modify directly.\n"
"Automatically generated by 'build-code error' -- do not modify directly.\n"
COMMENT_BLOCK_END "\n"
"#ifndef COMMON_ERROR_AUTO_H\n"
"#define COMMON_ERROR_AUTO_H\n"
@ -84,7 +84,7 @@ testRun(void)
COMMENT_BLOCK_BEGIN "\n"
"Error Type Definition\n"
"\n"
"Automatically generated by 'make build-error' -- do not modify directly.\n"
"Automatically generated by 'build-code error' -- do not modify directly.\n"
COMMENT_BLOCK_END "\n"
"\n"
COMMENT_BLOCK_BEGIN "\n"

View File

@ -402,7 +402,7 @@ testRun(void)
TEST_TITLE("check help file");
TEST_RESULT_VOID(bldHlpRender(storageTest, bldCfg, bldHlpParse(storageTest, bldCfg)), "write file");
TEST_STORAGE_EXISTS(storageTest, "command/help/help.auto.c.inc");
TEST_STORAGE_EXISTS(storageTest, "src/command/help/help.auto.c.inc");
}
FUNCTION_HARNESS_RETURN_VOID();

View File

@ -87,11 +87,11 @@ testRun(void)
TEST_STORAGE_GET(
storageTest,
"postgres/interface.auto.c.inc",
"src/postgres/interface.auto.c.inc",
COMMENT_BLOCK_BEGIN "\n"
"PostgreSQL Interface\n"
"\n"
"Automatically generated by 'make build-postgres' -- do not modify directly.\n"
"Automatically generated by 'build-code postgres' -- do not modify directly.\n"
COMMENT_BLOCK_END "\n"
"\n"
COMMENT_BLOCK_BEGIN "\n"

View File

@ -536,10 +536,10 @@ eval
# Build code
executeTest(
"ninja -C ${strBuildPath}" . ($bMinGen ? '' : ' src/build-config src/build-error') . ' src/build-postgres' .
($bMinGen ? '' : " && ${strBuildPath}/src/build-config ${strBackRestBase}/src") .
($bMinGen ? '' : " && ${strBuildPath}/src/build-error ${strBackRestBase}/src") .
" && cd $strRepoCachePath/src && ${strBuildPath}/src/build-postgres");
"ninja -C ${strBuildPath} src/build-code" .
($bMinGen ? '' : " && ${strBuildPath}/src/build-code config ${strBackRestBase}/src") .
($bMinGen ? '' : " && ${strBuildPath}/src/build-code error ${strBackRestBase}/src") .
" && cd $strRepoCachePath/src && ${strBuildPath}/src/build-code postgres");
if ($bGenOnly)
{