hgbook

changeset 172:5f305adeb584

Try to tighten up the run environment to make things more reproducible.
author Bryan O'Sullivan <bos@serpentine.com>
date Tue Mar 27 15:04:47 2007 -0700 (2007-03-27)
parents 8c1703a98266
children 754312dc23d5
files en/Makefile en/examples/run-example
line diff
     1.1 --- a/en/Makefile	Mon Mar 26 23:57:58 2007 -0700
     1.2 +++ b/en/Makefile	Tue Mar 27 15:04:47 2007 -0700
     1.3 @@ -78,6 +78,9 @@
     1.4  	tour \
     1.5  	tour-merge-conflict
     1.6  
     1.7 +example-prereqs := \
     1.8 +	/usr/bin/merge
     1.9 +
    1.10  dist-sources := \
    1.11  	../html/hgicon.png \
    1.12  	../html/index.html.var \
    1.13 @@ -161,7 +164,7 @@
    1.14  %.eps: %.dot
    1.15  	dot -Tps -o $@ $<
    1.16  
    1.17 -examples: examples/.run
    1.18 +examples: $(example-prereqs) examples/.run
    1.19  
    1.20  examples/.run: $(example-sources:%=examples/%.run)
    1.21  	touch examples/.run
     2.1 --- a/en/examples/run-example	Mon Mar 26 23:57:58 2007 -0700
     2.2 +++ b/en/examples/run-example	Tue Mar 27 15:04:47 2007 -0700
     2.3 @@ -46,6 +46,13 @@
     2.4              raise
     2.5      return False
     2.6  
     2.7 +def find_path_to(program):
     2.8 +    for p in os.environ.get('PATH', os.defpath).split(os.pathsep):
     2.9 +        name = os.path.join(p, program)
    2.10 +        if os.access(name, os.X_OK):
    2.11 +            return p
    2.12 +    return None
    2.13 +        
    2.14  class example:
    2.15      shell = '/usr/bin/env bash'
    2.16      ps1 = '__run_example_ps1__ '
    2.17 @@ -147,6 +154,16 @@
    2.18          print >> rcfp, 'PS1="%s"' % self.ps1
    2.19          print >> rcfp, 'PS2="%s"' % self.ps2
    2.20          print >> rcfp, 'unset HISTFILE'
    2.21 +        path = ['/usr/bin', '/bin']
    2.22 +        hg = find_path_to('hg')
    2.23 +        if hg and hg not in path:
    2.24 +            path.append(hg)
    2.25 +        def re_export(envar):
    2.26 +            v = os.getenv(envar)
    2.27 +            if v is not None:
    2.28 +                print >> rcfp, 'export ' + envar + '=' + v
    2.29 +        print >> rcfp, 'export PATH=' + ':'.join(path)
    2.30 +        re_export('PYTHONPATH')
    2.31          print >> rcfp, 'export EXAMPLE_DIR="%s"' % os.getcwd()
    2.32          print >> rcfp, 'export HGMERGE=merge'
    2.33          print >> rcfp, 'export LANG=C'
    2.34 @@ -160,8 +177,8 @@
    2.35          sys.stderr.flush()
    2.36          self.pid, self.cfd = pty.fork()
    2.37          if self.pid == 0:
    2.38 -            cmdline = ['/usr/bin/env', 'bash', '--noediting', '--noprofile',
    2.39 -                       '--norc']
    2.40 +            cmdline = ['/usr/bin/env', '-i', 'bash', '--noediting',
    2.41 +                       '--noprofile', '--norc']
    2.42              try:
    2.43                  os.execv(cmdline[0], cmdline)
    2.44              except OSError, err: