Skip to content

Add a `safe_c` template subroutine

Currently, we have a c() subroutine for obtaining configuration variables, however if the requested variable is not defined then this subroutine returns "". In many cases, we would prefer a build failure when a requested variable is not set, instead of continuing while using the empty string.

I believe we can define another subroutine that is the same as c() except it sets error_if_undef => 1. As a placeholder name, let's call this new subroutine safe_c. c is nice because it is short, we already have pc defined, as well. Maybe we should call this proposed subroutine sc.

My untested proposed patch is:

diff --git a/lib/RBM.pm b/lib/RBM.pm
index 074e385..bec5a30 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -652,6 +652,7 @@ sub process_template {
         project    => $project,
         p          => $config->{projects}{$project},
         c          => sub { project_config($project, @_) },
+        safe_c     => sub { project_config($project, @_, { error_if_undef => 1 }) },
         pc         => sub {
             my @args = @_;
             $args[2] = { $_[2] ? %{$_[2]} : (), origin_project => $project };
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information