Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,288 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#################################################################################################################################### | ||
# Auto-Generate Option Definition for Parsing with getopt_long(). | ||
#################################################################################################################################### | ||
package pgBackRestBuild::Config::BuildParse; | ||
|
||
use strict; | ||
use warnings FATAL => qw(all); | ||
use Carp qw(confess); | ||
use English '-no_match_vars'; | ||
|
||
use Cwd qw(abs_path); | ||
use Exporter qw(import); | ||
our @EXPORT = qw(); | ||
use File::Basename qw(dirname); | ||
use Storable qw(dclone); | ||
|
||
use pgBackRest::Common::Log; | ||
use pgBackRest::Common::String; | ||
use pgBackRest::Version; | ||
|
||
use pgBackRestBuild::Build::Common; | ||
use pgBackRestBuild::Config::Build; | ||
use pgBackRestBuild::Config::Data; | ||
|
||
#################################################################################################################################### | ||
# Constants | ||
#################################################################################################################################### | ||
use constant BLDLCL_FILE_DEFINE => 'parse'; | ||
|
||
use constant BLDLCL_DATA_OPTION => '01-dataOption'; | ||
|
||
#################################################################################################################################### | ||
# Definitions for constants and data to build | ||
#################################################################################################################################### | ||
my $strSummary = 'Option Parse Definition'; | ||
|
||
my $rhBuild = | ||
{ | ||
&BLD_FILE => | ||
{ | ||
&BLDLCL_FILE_DEFINE => | ||
{ | ||
&BLD_SUMMARY => $strSummary, | ||
|
||
&BLD_DATA => | ||
{ | ||
&BLDLCL_DATA_OPTION => | ||
{ | ||
&BLD_SUMMARY => 'Option parse data', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
#################################################################################################################################### | ||
# Build configuration constants and data | ||
#################################################################################################################################### | ||
sub buildConfigParse | ||
{ | ||
# Build option parse list | ||
#------------------------------------------------------------------------------------------------------------------------------- | ||
my $rhConfigDefine = cfgDefine(); | ||
|
||
my $strBuildSource = | ||
"static const struct option optionList[] =\n" . | ||
"{\n"; | ||
|
||
foreach my $strOption (sort(keys(%{$rhConfigDefine}))) | ||
{ | ||
my $rhOption = $rhConfigDefine->{$strOption}; | ||
my $strOptionEnum = buildConfigOptionEnum($strOption); | ||
my $strOptionArg = ($rhOption->{&CFGDEF_TYPE} ne CFGDEF_TYPE_BOOLEAN ? " .has_arg = required_argument,\n" : ''); | ||
my $strOptionPrefix = $rhConfigDefine->{$strOption}{&CFGDEF_PREFIX}; | ||
|
||
for (my $iOptionIdx = 0; $iOptionIdx <= $rhOption->{&CFGDEF_INDEX_TOTAL}; $iOptionIdx++) | ||
{ | ||
# Don't and option indexes if it is not indexeds | ||
next if ($iOptionIdx == 1 && $rhOption->{&CFGDEF_INDEX_TOTAL} == 1); | ||
|
||
# Generate option name | ||
my $strOptionName = $iOptionIdx > 0 ? | ||
"${strOptionPrefix}${iOptionIdx}-" . substr($strOption, length($strOptionPrefix) + 1) : $strOption; | ||
|
||
# Generate option value used for parsing (offset is added so options don't conflict with getopt_long return values) | ||
my $strOptionVal = 'PARSE_OPTION_OFFSET + ' . $strOptionEnum . ($iOptionIdx > 1 ? " + " . ($iOptionIdx - 1) : ''); | ||
|
||
# Add option | ||
$strBuildSource .= | ||
" {\n" . | ||
" .name = \"${strOptionName}\",\n" . | ||
$strOptionArg . | ||
" .val = ${strOptionVal},\n" . | ||
" },\n"; | ||
|
||
# Add negation when defined | ||
if ($rhOption->{&CFGDEF_NEGATE}) | ||
{ | ||
$strBuildSource .= | ||
" {\n" . | ||
" .name = \"no-${strOptionName}\",\n" . | ||
" .val = ${strOptionVal},\n" . | ||
" },\n"; | ||
} | ||
} | ||
} | ||
|
||
# Perl options passed to the C binary should be ignored (unless calling Perl which is done elsewhere) | ||
$strBuildSource .= | ||
" // Perl option is ignored by normal config parsing\n" . | ||
" {\n" . | ||
" .name = \"perl-option\",\n" . | ||
" .has_arg = required_argument,\n" . | ||
" .val = 0,\n" . | ||
" },\n"; | ||
|
||
# The option list needs to be terminated or getopt_long will just keep on reading | ||
$strBuildSource .= | ||
" // Terminate option list\n" . | ||
" {\n" . | ||
" .name = NULL\n" . | ||
" }\n" . | ||
"};\n"; | ||
|
||
$rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_DATA}{&BLDLCL_DATA_OPTION}{&BLD_SOURCE} = $strBuildSource; | ||
|
||
return $rhBuild; | ||
} | ||
|
||
push @EXPORT, qw(buildConfigParse); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.