This adds some supplementary option to pkg_create to expose the substitution
mechanism. The idea being that, sometimes, in ports, we would like to have
the exact same substitutions that are available to pkg creation.

In my opinion, it makes sense to integrate this in pkg_create(1) proper, but
since I know ways too much about pkg internals, maybe I'm opiniated.

Of course, this would go together with a definition of CMD_SUBST in bsd.port.mk
that would prepare the list of substitution according to SUBST_VAR.

I haven't thought yet about %%flavor%% fragment inclusion. It's probably 
overkill, unless we actually find something that would like it...

Then you could e.g.,

post-install:
        ${CMD_SUBST} -C ${FILES}/foo.conf ${SYSCONFDIR}/foo.conf

or:

post-patch:
        ${CMD_SUBST} ${WRKSRC}/tweak.c

(there should also be a related overhaul to update-patches, so that it knows
about those backup files and that it does not work with the substituted files)


Index: pkg_create
===================================================================
RCS file: /mirrors/openbsd/cvs/src/usr.sbin/pkg_add/pkg_create,v
retrieving revision 1.115
diff -u -p -r1.115 pkg_create
--- pkg_create  16 Jun 2007 09:29:37 -0000      1.115
+++ pkg_create  6 Apr 2008 09:46:58 -0000
@@ -332,7 +332,26 @@ sub copy_subst
        copy_subst_fh($srcname, $dest);
 }
 
-our ($opt_p, $opt_f, $opt_c, $opt_d, $opt_v, $opt_i, $opt_k,
+sub subst_files
+{
+       my $copy = shift;
+
+       my $bak = defined($defines{BAK}) ? $defines{BAK} : '.bak';
+
+       while (my $src = shift) {
+               my $dest;
+               if ($copy) {
+                       $dest = shift or die "Odd number of files";
+               } else {
+                       $dest = $src;
+                       $src .= $bak;
+                       rename $dest, $src or die "Can't rename $dest";
+               }
+               copy_subst($src, $dest);
+       }
+}
+
+our ($opt_p, $opt_f, $opt_c, $opt_C, $opt_d, $opt_v, $opt_i, $opt_k,
        $opt_S, $opt_s, $opt_O, $opt_A, $opt_L,
        $opt_M, $opt_U, $opt_P, $opt_W, $opt_n,
        $opt_B, $opt_q, $opt_Q);
@@ -482,7 +501,7 @@ set_usage(
 
 my $plist = new OpenBSD::PackingList;
 try { 
-       getopts('p:f:c:d:vi:k:M:U:S:hs:OA:L:B:D:P:W:nqQ', 
+       getopts('p:f:c:d:vi:k:M:U:S:hsCA:L:B:D:P:W:nqQ', 
        {'D' => 
                sub { 
                        local $_ = shift;
@@ -513,6 +532,12 @@ try { 
        Usage($_);
 };
 
+if ($opt_s) {
+       set_usage('pkg_create [-Cs] file ...');
+       subst_files($opt_C, @ARGV);
+       exit(0);
+}
+
 if (@ARGV == 0) {
        $regen_package = 1;
 } elsif (@ARGV != 1) {
@@ -520,14 +545,6 @@ if (@ARGV == 0) {
 }
 
 try {
-
-if (defined $opt_s) {
-       Usage "Option s is no longer supported";
-}
-
-if (defined $opt_O) {
-       Usage "Option O is no longer supported";
-}
 
 if (defined $opt_Q) {
        $opt_q = 1;
Index: pkg_create.1
===================================================================
RCS file: /mirrors/openbsd/cvs/src/usr.sbin/pkg_add/pkg_create.1,v
retrieving revision 1.45
diff -u -p -r1.45 pkg_create.1
--- pkg_create.1        5 Nov 2007 17:15:16 -0000       1.45
+++ pkg_create.1        6 Apr 2008 09:46:58 -0000
@@ -51,7 +51,16 @@
 .Ar pkg-name
 .Ek
 .Nm pkg_create
+.Bk -words
 .Fl f Ar packinglist
+.Ek
+.Nm pkg_create
+.Fl s
+.Op Fl C
+.Oo Fl D Ar name
+.Ns = Ns Ar value ...
+.Oc
+.Ar file ...
 .Sh DESCRIPTION
 The
 .Nm
@@ -111,6 +120,8 @@ the argument itself.
 This string should also
 give some idea of which version of the product (if any) the package
 represents.
+.It Fl C
+Copy flag for subtitution mode, see below.
 .It Fl D Ar name Ns = Ns Ar value
 Define
 .Ar name
@@ -186,6 +197,8 @@ Print out the actual packing-list of the
 (query mode).
 Most often used in combination with
 .Fl n .
+.It Fl s
+Substitution mode, see below.
 .It Fl S Ar pkg-destdir
 Deprecated, use
 identical
@@ -215,6 +228,30 @@ package:
 .Bd -literal -offset indent
 pkg_create -f /var/db/pkg/kdelibs-3.4.3/+CONTENTS
 .Ed
+.Pp
+.Nm
+can also be invoked in substitution mode
+.Po
+.Fl s
+.Pc , 
+to be able to use the same 
+substitution conventions on a set of arbitrary files.
+In this mode, all files on the command lines will have their variables 
+replaced.
+The original files are kept as
+.Pa file.bak
+copies, by default.
+The extension can be changed by setting
+.Fl D Ar BAK
+to another value.
+If
+.Fl C
+is also specified,
+.Nm
+will instead parse the list of files as a list of
+.Ar src
+.Ar dest 
+filenames.
 .Sh PACKING LIST DETAILS
 The
 .Dq packing list

Reply via email to