[svn:parrot] r42266 - in trunk: . config/gen/makefiles runtime/parrot/library t/library

fperrad at svn.parrot.org fperrad at svn.parrot.org
Thu Nov 5 11:01:03 UTC 2009


Author: fperrad
Date: Thu Nov  5 11:01:00 2009
New Revision: 42266
URL: https://trac.parrot.org/parrot/changeset/42266

Log:
[library] a new PIR library which allows configure step with an installed Parrot and no dependency.

Added:
   trunk/runtime/parrot/library/Configure.pir   (contents, props changed)
   trunk/t/library/configure.t   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/MANIFEST.generated
   trunk/config/gen/makefiles/root.in

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	Thu Nov  5 09:44:10 2009	(r42265)
+++ trunk/MANIFEST	Thu Nov  5 11:01:00 2009	(r42266)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Oct 28 00:57:35 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Nov  5 10:31:39 2009 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1158,6 +1158,7 @@
 runtime/parrot/languages/parrot/parrot.pir                  [library]
 runtime/parrot/library/CGI/QueryHash.pir                    [library]
 runtime/parrot/library/Config/JSON.pir                      [library]
+runtime/parrot/library/Configure.pir                        [library]
 runtime/parrot/library/Crow.pir                             [library]
 runtime/parrot/library/Curses.pir                           [library]
 runtime/parrot/library/Data/Dumper.pir                      [library]
@@ -1654,6 +1655,7 @@
 t/harness                                                   [test]
 t/include/fp_equality.t                                     [test]
 t/library/cgi_query_hash.t                                  [test]
+t/library/configure.t                                       [test]
 t/library/coroutine.t                                       [test]
 t/library/dumper.t                                          [test]
 t/library/getopt_obj.t                                      [test]

Modified: trunk/MANIFEST.generated
==============================================================================
--- trunk/MANIFEST.generated	Thu Nov  5 09:44:10 2009	(r42265)
+++ trunk/MANIFEST.generated	Thu Nov  5 11:01:00 2009	(r42266)
@@ -145,6 +145,7 @@
 runtime/parrot/include/warnings.pasm              [main]
 runtime/parrot/library/CGI/QueryHash.pbc          [main]
 runtime/parrot/library/Config/JSON.pbc            [main]
+runtime/parrot/library/Configure.pbc              [main]
 runtime/parrot/library/config.pbc                 [main]
 runtime/parrot/library/config.pir                 [main]
 runtime/parrot/library/Crow.pbc                   [main]

Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in	Thu Nov  5 09:44:10 2009	(r42265)
+++ trunk/config/gen/makefiles/root.in	Thu Nov  5 11:01:00 2009	(r42266)
@@ -258,6 +258,7 @@
     $(LIBRARY_DIR)/CGI/QueryHash.pbc \
     $(LIBRARY_DIR)/Crow.pbc \
     $(LIBRARY_DIR)/config.pbc \
+    $(LIBRARY_DIR)/Configure.pbc \
     $(LIBRARY_DIR)/Config/JSON.pbc \
     $(LIBRARY_DIR)/Data/Dumper/Base.pbc \
     $(LIBRARY_DIR)/Data/Dumper/Default.pbc \

Added: trunk/runtime/parrot/library/Configure.pir
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/runtime/parrot/library/Configure.pir	Thu Nov  5 11:01:00 2009	(r42266)
@@ -0,0 +1,165 @@
+# Copyright (C) 2009, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+Configure.pir - Configure step helpers
+
+=head1 DESCRIPTION
+
+Supply C<genfile> function, which handles
+
+=over 4
+
+=item variable substitution
+
+=item slash/backslash substitution (for Windows).
+
+=back
+
+Pure PIR, without any dependencies.
+
+See as example,
+L<http://github.com/fperrad/markdown/blob/master/Configure.pir>
+
+=head1 USAGE
+
+    # Retrieve the Parrot config
+    .local pmc config
+    $P0 = getinterp
+    config = $P0[.IGLOBALS_CONFIG_HASH]
+
+    # Sometime, we need extra configuration variables
+    config['foo'] = 'bar'
+
+    # Here, do the job
+    genfile('Makefile.in', 'Makefile', config)
+
+=cut
+
+.include 'sysinfo.pasm'
+
+.sub 'genfile'
+    .param string tmpl
+    .param string outfile
+    .param pmc config
+    $S0 = slurp(tmpl)
+    $S0 = subst_config($S0, config)
+    $S1 = sysinfo .SYSINFO_PARROT_OS
+    $S0 = subst_slash($S0, $S1)
+    output(outfile, $S0)
+    printerr "\n\tGenerating '"
+    printerr outfile
+    printerr "'\n\n"
+.end
+
+.sub 'slurp' :anon
+    .param string filename
+    $P0 = new 'FileHandle'
+    push_eh _handler
+    $S0 = $P0.'readall'(filename)
+    pop_eh
+    .return ($S0)
+  _handler:
+    .local pmc e
+    .get_results (e)
+    $S0 = "Can't open '"
+    $S0 .= filename
+    $S0 .= "' ("
+    $S1 = err
+    $S0 .= $S1
+    $S0 .= ")\n"
+    e = $S0
+    rethrow e
+.end
+
+.sub 'output' :anon
+    .param string filename
+    .param string content
+    $P0 = new 'FileHandle'
+    push_eh _handler
+    $P0.'open'(filename, 'w')
+    pop_eh
+    $P0.'puts'(content)
+    $P0.'close'()
+    .return ()
+  _handler:
+    .local pmc e
+    .get_results (e)
+    $S0 = "Can't open '"
+    $S0 .= filename
+    $S0 .= "' ("
+    $S1 = err
+    $S0 .= $S1
+    $S0 .= ")\n"
+    e = $S0
+    rethrow e
+.end
+
+.sub 'subst_config'
+    .param string content
+    .param pmc config
+    $P0 = split "\n", content
+    .local string result, line
+    result = ''
+  L1:
+    unless $P0 goto L2
+    line = shift $P0
+    $I0 = 0
+    $S0 = ''
+  L3:
+    $I1 = index line, '@', $I0
+    if $I1 < 0 goto L4
+    $I2 = $I1 - $I0
+    inc $I1
+    $I3 = index line, '@', $I1
+    if $I3 < 0 goto L4
+    $S1 = substr line, $I0, $I2
+    $S0 .= $S1
+    $I4 = $I3 - $I1
+    $S1 = substr line, $I1, $I4
+    $I7 = exists config[$S1]
+    unless $I7 goto L5
+    $S2 = config[$S1]
+    $S0 .= $S2
+    goto L6
+  L5:
+    printerr "\tunknown config: "
+    printerr $S1
+    printerr "\n"
+  L6:
+    $I0 = $I3 + 1
+    goto L3
+  L4:
+    $S1 = substr line, $I0
+    $S0 .= $S1
+    result .= $S0
+    result .= "\n"
+    goto L1
+  L2:
+    .return (result)
+.end
+
+.sub 'subst_slash'
+    .param string str
+    .param string OS
+    unless OS == 'MSWin32' goto L1
+    $P0 = split "/", str
+    str = join "\\", $P0
+    $P0 = split "\\\\", str
+    str = join "/", $P0
+    $P0 = split "\\*", str
+    str = join "\\\\*", $P0
+    .return (str)
+  L1:
+    $P0 = split "//", str
+    str = join "/", $P0
+    .return (str)
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+

Added: trunk/t/library/configure.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/t/library/configure.t	Thu Nov  5 11:01:00 2009	(r42266)
@@ -0,0 +1,71 @@
+#!parrot
+# Copyright (C) 2009, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+t/library/configure.t - Test the Configure PBC
+
+=head1 SYNOPSIS
+
+    % prove t/library/configure.t
+
+=cut
+
+.sub 'main' :main
+    .include 'test_more.pir'
+
+    load_bytecode 'Configure.pbc'
+
+    plan(12)
+    test_subst_config()
+    test_subst_slash()
+.end
+
+.sub 'test_subst_config'
+    .local pmc config
+    config = new 'Hash'
+    config['foo'] = 'bar'
+    $S0 = subst_config("# plain text", config)
+    is($S0, "# plain text\n", "plain text")
+    $S0 = subst_config("\t at echo foo", config)
+    is($S0, "\t at echo foo\n", "@ alone")
+    $S0 = subst_config("here @foo@ variable", config)
+    is($S0, "here bar variable\n", "variable")
+    $S0 = subst_config("here @foo@ variable, and here @foo at .", config)
+    is($S0, "here bar variable, and here bar.\n", "variable")
+.end
+
+.sub 'test_subst_slash'
+    $S1 = "path/to/somewhere/"
+    $S0 = subst_slash($S1, 'MSWin32')
+    is($S0, "path\\to\\somewhere\\", "paths on win32")
+    $S0 = subst_slash($S1, '*nix')
+    is($S0, $S1, "paths on *nix")
+
+    $S1 = "prove t/*.t"
+    $S0 = subst_slash($S1, 'MSWin32')
+    is($S0, "prove t\\\\*.t")
+    $S0 = subst_slash($S1, '*nix')
+    is($S0, $S1)
+
+    $S1 = "prove t//*.t"
+    $S0 = subst_slash($S1, 'MSWin32')
+    is($S0, "prove t/*.t")
+    $S0 = subst_slash($S1, '*nix')
+    is($S0, "prove t/*.t")
+
+    $S1 = "http:////host//paths//"
+    $S0 = subst_slash($S1, 'MSWin32')
+    is($S0, "http://host/paths/", "url on win32")
+    $S0 = subst_slash($S1, '*nix')
+    is($S0, "http://host/paths/", "url on *nix")
+.end
+
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:


More information about the parrot-commits mailing list