Git commit 5602388099291523942b475b51a2f6a2334012af by Andrew Shark.
Committed on 26/01/2024 at 05:17.
Pushed by ashark into branch 'master'.

Fix git-repository-base option

Before this commit, only the last occurrence of this option was applied to the 
build context.

Now we actually can use it several times in the global section, as it was 
intended.

- The actual reading of 'git-repository-base' was done when constructing 
OptionBase from the global section of the config.
- The merging options from the constructed OptionsBase object into the 
BuildContext was done in setOption of BuildContext, but because it was not 
properly handled in OptionsBase, only the last value was appeared in 
BuildContext's handling.
- Now it is handled in the OptionsBase also when merging (we expect that the 
type of value is a hash then).
- Remove incorrect placement of 'git-repository-base' to the checking of 
module-set option in the Module, so our BuildContex::setOption can call its 
parent class Module::setOption, which then can pass this option handling to its 
parent class OptionsBase::setOption.

Also:
- Move endWord suggestion next to the printed message. The actual endWord does 
not matter when parsing, so it makes code a bit more readable when 
understanding how it parses
- Edit comment so it better explains why we remove some options that we read 
from the config
- Move the config description in docbook to the correct scope

M  +60   -59   doc/conf-options-table.docbook
M  +6    -5    modules/ksb/Application.pm
M  +1    -18   modules/ksb/BuildContext.pm
M  +1    -1    modules/ksb/Module.pm
M  +28   -0    modules/ksb/OptionsBase.pm

https://invent.kde.org/sdk/kdesrc-build/-/commit/5602388099291523942b475b51a2f6a2334012af

diff --git a/doc/conf-options-table.docbook b/doc/conf-options-table.docbook
index 0573f12d..8722b1ae 100644
--- a/doc/conf-options-table.docbook
+++ b/doc/conf-options-table.docbook
@@ -108,6 +108,66 @@ protocol is most efficient.</para>
 </entry>
 </row>
 
+<row id="conf-git-repository-base">
+<entry><link 
linkend="conf-git-repository-base">git-repository-base</link></entry>
+<entry>
+<simplelist type='horiz' columns='2'>
+<member>Type</member><member>String</member>
+<member>Available since</member><member>1.12.1</member>
+</simplelist>
+<para>This option is used to create a short
+name to reference a specific Git repository base URL in later <link
+linkend="module-sets">module set</link> declarations, which is useful for
+quickly declaring many Git modules to build.</para>
+
+<para>You must specify two things (separated by a space): The name to assign
+to the base URL, and the actual base URL itself. For example:</para>
+
+<para>
+<programlisting>
+global
+    # other options
+    # This is the common path to all anonymous Git server modules.
+    git-repository-base <replaceable>kde-git</replaceable> 
<replaceable>kde:</replaceable>
+end global
+
+# Module declarations
+
+module-set
+    # Now you can use the alias you defined earlier, but 
<emphasis>only</emphasis> in a module-set.
+    repository <replaceable>kde-git</replaceable>
+    <link linkend="conf-use-modules">use-modules</link> 
<replaceable>module1.git</replaceable> <replaceable>module2.git</replaceable>
+end module-set
+</programlisting>
+</para>
+
+<para>The module-set's <literal>use-modules</literal> option created two 
modules
+internally, with &kdesrc-build; behaving as if it had read:</para>
+
+<programlisting>
+module module1
+    repository kde:<replaceable>module1.git</replaceable>
+end module
+
+module module2
+    repository kde:<replaceable>module2.git</replaceable>
+end module
+</programlisting>
+
+<para>The <literal>kde:</literal> &git; repository prefix used above is a
+shortcut which will be setup by &kdesrc-build; automatically. See the TechBase
+<ulink
+url="https://techbase.kde.org/Development/Git/Configuration#URL_Renaming";>URL
+Renaming</ulink> article for more information. Note that unlike most other
+options, this option can be specified multiple times in order to create as
+many aliases as necessary.</para>
+
+<tip><para>It is not required to use this option to take advantage of 
module-set,
+this option exists to make it easy to use the same repository across many
+different module sets.</para></tip>
+</entry>
+</row>
+
 <row id="conf-install-environment-driver">
 <entry><link 
linkend="conf-install-environment-driver">install-environment-driver</link></entry>
 <entry>
@@ -1267,65 +1327,6 @@ installations. However this only works on build systems 
that support
 </thead>
 <tbody>
 
-<row id="conf-git-repository-base">
-<entry><link 
linkend="conf-git-repository-base">git-repository-base</link></entry>
-<entry>
-<simplelist type='horiz' columns='2'>
-<member>Type</member><member>String</member>
-<member>Available since</member><member>1.12.1</member>
-</simplelist>
-<para>This option is used to create a short
-name to reference a specific Git repository base URL in later <link
-linkend="module-sets">module set</link> declarations, which is useful for
-quickly declaring many Git modules to build.</para>
-
-<para>You must specify two things (separated by a space): The name to assign
-to the base URL, and the actual base URL itself. For example:</para>
-
-<para>
-<programlisting>
-global
-    # other options
-    # This is the common path to all anonymous Git server modules.
-    git-repository-base <replaceable>kde-git</replaceable> 
<replaceable>kde:</replaceable>
-end global
-
-# Module declarations
-
-module-set
-    # Now you can use the alias you defined earlier, but 
<emphasis>only</emphasis> in a module-set.
-    repository <replaceable>kde-git</replaceable>
-    <link linkend="conf-use-modules">use-modules</link> 
<replaceable>module1.git</replaceable> <replaceable>module2.git</replaceable>
-end module-set
-</programlisting>
-</para>
-
-<para>The module-set's <literal>use-modules</literal> option created two 
modules
-internally, with &kdesrc-build; behaving as if it had read:</para>
-
-<programlisting>
-module module1
-    repository kde:<replaceable>module1.git</replaceable>
-end module
-
-module module2
-    repository kde:<replaceable>module2.git</replaceable>
-end module
-</programlisting>
-
-<para>The <literal>kde:</literal> &git; repository prefix used above is a
-shortcut which will be setup by &kdesrc-build; automatically. See the TechBase
-<ulink
-url="https://techbase.kde.org/Development/Git/Configuration#URL_Renaming";>URL
-Renaming</ulink> article for more information. Note that unlike most other
-options, this option can be specified multiple times in order to create as
-many aliases as necessary.</para>
-
-<tip><para>It is not required to use this option to take advantage of 
module-set,
-this option exists to make it easy to use the same repository across many
-different module sets.</para></tip>
-</entry>
-</row>
 
 <row id="conf-ignore-modules">
 <entry><link linkend="conf-ignore-modules">ignore-modules</link></entry>
diff --git a/modules/ksb/Application.pm b/modules/ksb/Application.pm
index f3283cd3..9cb9f29b 100644
--- a/modules/ksb/Application.pm
+++ b/modules/ksb/Application.pm
@@ -924,10 +924,6 @@ sub _parseModuleOptions ($ctx, $fileReader, $module, 
$endRE=undef)
     assert_isa($module, 'ksb::OptionsBase');
 
     state $moduleID = 0;
-    my $endWord = $module->isa('ksb::BuildContext') ? 'global'     :
-                  $module->isa('ksb::ModuleSet')    ? 'module-set' :
-                  $module->isa('ksb::Module')       ? 'module'     :
-                                                      'options';
 
     # Just look for an end marker if terminator not provided.
     $endRE //= qr/^end[\w\s]*$/;
@@ -945,6 +941,11 @@ sub _parseModuleOptions ($ctx, $fileReader, $module, 
$endRE=undef)
         # Sanity check, make sure the section is correctly terminated
         if(/^(module\b|options\b)/)
         {
+            my $endWord = $module->isa('ksb::BuildContext') ? 'global'     :
+                          $module->isa('ksb::ModuleSet')    ? 'module-set' :
+                          $module->isa('ksb::Module')       ? 'module'     :
+                                                              'options';
+
             error ("Invalid configuration file $current_file at line $.\nAdd 
an 'end $endWord' before " .
                    "starting a new module.\n");
             die make_exception('Config', "Invalid file $current_file");
@@ -1097,7 +1098,7 @@ sub _readConfigurationOptions ($ctx, $fh, 
$cmdlineGlobalOptions, $deferredOption
         # Now read in each global option.
         my $globalOpts = _parseModuleOptions($ctx, $fileReader, 
ksb::OptionsBase->new());
 
-        # Remove any cmdline options so they don't overwrite build context
+        # For those options that user passed in cmdline, we do not want their 
corresponding config options to overwrite build context, so we forget them.
         delete @{$globalOpts->{options}}{keys %{$cmdlineGlobalOptions}};
         $ctx->mergeOptionsFrom($globalOpts);
 
diff --git a/modules/ksb/BuildContext.pm b/modules/ksb/BuildContext.pm
index 4b7419a2..ae341914 100644
--- a/modules/ksb/BuildContext.pm
+++ b/modules/ksb/BuildContext.pm
@@ -97,7 +97,7 @@ my %GlobalOptions_private = (
     "debug-level"          => ksb::Debug::INFO,
     "filter-out-phases"    => "",
     "git-desired-protocol" => "git", # protocol to use for git *push* URLs 
(fetch requires https)
-    "git-repository-base"  => {}, # Base path template for use multiple times.
+    "git-repository-base"  => {},
     "manual-build"         => "",
     "manual-update"        => "",
     "repository"           => "", # module's git repo
@@ -800,23 +800,6 @@ sub setOption
 {
     my ($self, %options) = @_;
 
-    # Special-case handling
-    my $repoOption = 'git-repository-base';
-    if (exists $options{$repoOption}) {
-        my $value = $options{$repoOption};
-        my ($repo, $url) = ($value =~ /^([a-zA-Z0-9_-]+)\s+(.+)$/);
-
-        if (!$repo || !$url) {
-            die ksb::BuildException::Config->new($repoOption,
-                "Invalid git-repository-base setting: $value");
-        }
-
-        # This will be a hash reference instead of a scalar
-        my $hashref = $self->getOption($repoOption) || { };
-        $hashref->{$repo} = $url;
-        delete $options{$repoOption};
-    }
-
     # Actually set options.
     $self->SUPER::setOption(%options);
 
diff --git a/modules/ksb/Module.pm b/modules/ksb/Module.pm
index 2c1d84b7..28232d42 100644
--- a/modules/ksb/Module.pm
+++ b/modules/ksb/Module.pm
@@ -855,7 +855,7 @@ sub setOption
     my ($self, %options) = @_;
 
     # Ensure we don't accidentally get fed module-set options
-    for (qw(git-repository-base use-modules ignore-modules)) {
+    for (qw(use-modules ignore-modules)) {
         if (exists $options{$_}) {
             error (" r[b[*] module b[$self] should be declared as module-set 
to use b[$_]");
             die ksb::BuildException::Config->new($_, "Option $_ can only be 
used in module-set");
diff --git a/modules/ksb/OptionsBase.pm b/modules/ksb/OptionsBase.pm
index e1a5a0b7..77a79670 100644
--- a/modules/ksb/OptionsBase.pm
+++ b/modules/ksb/OptionsBase.pm
@@ -136,6 +136,34 @@ sub setOption ($self, %options)
         delete $options{'set-env'};
     }
 
+    # Special-case handling
+    my $repoOption = 'git-repository-base';
+    if (exists $options{$repoOption}) {
+        my $value = $options{$repoOption};
+
+        if (ref($value) eq 'HASH') {
+            # The case when we merge the constructed OptionBase module (from 
the config) into the BuildContext. The type of $value is a hash (dict).
+            foreach my $key (keys %{$value}) {
+                $self->{options}{$repoOption}{$key} = $value->{$key};
+            }
+            delete $options{$repoOption};
+        } else {
+            # The case when we first read the option from the config. The type 
of $value is a scalar (string).
+            my ($repo, $url) = ($value =~ /^([a-zA-Z0-9_-]+)\s+(.+)$/);
+
+            if (!$repo || !$url) {
+                die ksb::BuildException::Config->new($repoOption,
+                    "Invalid git-repository-base setting: $value");
+            }
+
+            # This will be a hash reference instead of a scalar
+            my $hashref = $self->getOption($repoOption) || {};
+            $hashref->{$repo} = $url;
+            $self->{options}{$repoOption} = $hashref;
+            return
+        }
+    }
+
     # Everything else can be dumped straight into our hash.
     @{$self->{options}}{keys %options} = values %options;
 }

Reply via email to