changeset 172:5f305adeb584

Try to tighten up the run environment to make things more reproducible.
author Bryan O'Sullivan <bos@serpentine.com>
date Tue, 27 Mar 2007 15:04:47 -0700
parents 8c1703a98266
children 754312dc23d5
files en/Makefile en/examples/run-example
diffstat 2 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/en/Makefile	Mon Mar 26 23:57:58 2007 -0700
+++ b/en/Makefile	Tue Mar 27 15:04:47 2007 -0700
@@ -78,6 +78,9 @@
 	tour \
 	tour-merge-conflict
 
+example-prereqs := \
+	/usr/bin/merge
+
 dist-sources := \
 	../html/hgicon.png \
 	../html/index.html.var \
@@ -161,7 +164,7 @@
 %.eps: %.dot
 	dot -Tps -o $@ $<
 
-examples: examples/.run
+examples: $(example-prereqs) examples/.run
 
 examples/.run: $(example-sources:%=examples/%.run)
 	touch examples/.run
--- a/en/examples/run-example	Mon Mar 26 23:57:58 2007 -0700
+++ b/en/examples/run-example	Tue Mar 27 15:04:47 2007 -0700
@@ -46,6 +46,13 @@
             raise
     return False
 
+def find_path_to(program):
+    for p in os.environ.get('PATH', os.defpath).split(os.pathsep):
+        name = os.path.join(p, program)
+        if os.access(name, os.X_OK):
+            return p
+    return None
+        
 class example:
     shell = '/usr/bin/env bash'
     ps1 = '__run_example_ps1__ '
@@ -147,6 +154,16 @@
         print >> rcfp, 'PS1="%s"' % self.ps1
         print >> rcfp, 'PS2="%s"' % self.ps2
         print >> rcfp, 'unset HISTFILE'
+        path = ['/usr/bin', '/bin']
+        hg = find_path_to('hg')
+        if hg and hg not in path:
+            path.append(hg)
+        def re_export(envar):
+            v = os.getenv(envar)
+            if v is not None:
+                print >> rcfp, 'export ' + envar + '=' + v
+        print >> rcfp, 'export PATH=' + ':'.join(path)
+        re_export('PYTHONPATH')
         print >> rcfp, 'export EXAMPLE_DIR="%s"' % os.getcwd()
         print >> rcfp, 'export HGMERGE=merge'
         print >> rcfp, 'export LANG=C'
@@ -160,8 +177,8 @@
         sys.stderr.flush()
         self.pid, self.cfd = pty.fork()
         if self.pid == 0:
-            cmdline = ['/usr/bin/env', 'bash', '--noediting', '--noprofile',
-                       '--norc']
+            cmdline = ['/usr/bin/env', '-i', 'bash', '--noediting',
+                       '--noprofile', '--norc']
             try:
                 os.execv(cmdline[0], cmdline)
             except OSError, err: