comparison tests/run-tests.py @ 47575:27fb9f32e1a3

run-tests: always define a custom-bin directory We are always generating `python` / `python3` executable and we will soon often generate a `hg` executable. So let's always make it a thing. This will help us to make sure we have the appropriate binary available to all script. On both linux and Windows. Differential Revision: https://phab.mercurial-scm.org/D11044
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 09 Jul 2021 15:29:58 +0200
parents 2b2f5cf979c3
children c3c38eb08465
comparison
equal deleted inserted replaced
47574:2b2f5cf979c3 47575:27fb9f32e1a3
3019 self._testdir = None 3019 self._testdir = None
3020 self._outputdir = None 3020 self._outputdir = None
3021 self._hgtmp = None 3021 self._hgtmp = None
3022 self._installdir = None 3022 self._installdir = None
3023 self._bindir = None 3023 self._bindir = None
3024 self._tmpbindir = None 3024 # a place for run-tests.py to generate executable it needs
3025 self._custom_bin_dir = None
3025 self._pythondir = None 3026 self._pythondir = None
3026 # True if we had to infer the pythondir from --with-hg 3027 # True if we had to infer the pythondir from --with-hg
3027 self._pythondir_inferred = False 3028 self._pythondir_inferred = False
3028 self._coveragefile = None 3029 self._coveragefile = None
3029 self._createdfiles = [] 3030 self._createdfiles = []
3110 d = osenvironb.get(b'TMP', None) 3111 d = osenvironb.get(b'TMP', None)
3111 tmpdir = tempfile.mkdtemp(b'', b'hgtests.', d) 3112 tmpdir = tempfile.mkdtemp(b'', b'hgtests.', d)
3112 3113
3113 self._hgtmp = osenvironb[b'HGTMP'] = os.path.realpath(tmpdir) 3114 self._hgtmp = osenvironb[b'HGTMP'] = os.path.realpath(tmpdir)
3114 3115
3116 self._custom_bin_dir = os.path.join(self._hgtmp, b'custom-bin')
3117 os.makedirs(self._custom_bin_dir)
3118
3115 if self.options.with_hg: 3119 if self.options.with_hg:
3116 self._installdir = None 3120 self._installdir = None
3117 whg = self.options.with_hg 3121 whg = self.options.with_hg
3118 self._bindir = os.path.dirname(os.path.realpath(whg)) 3122 self._bindir = os.path.dirname(os.path.realpath(whg))
3119 assert isinstance(self._bindir, bytes) 3123 assert isinstance(self._bindir, bytes)
3120 self._hgcommand = os.path.basename(whg) 3124 self._hgcommand = os.path.basename(whg)
3121 self._tmpbindir = os.path.join(self._hgtmp, b'install', b'bin')
3122 os.makedirs(self._tmpbindir)
3123 3125
3124 normbin = os.path.normpath(os.path.abspath(whg)) 3126 normbin = os.path.normpath(os.path.abspath(whg))
3125 normbin = normbin.replace(_sys2bytes(os.sep), b'/') 3127 normbin = normbin.replace(_sys2bytes(os.sep), b'/')
3126 3128
3127 # Other Python scripts in the test harness need to 3129 # Other Python scripts in the test harness need to
3145 3147
3146 else: 3148 else:
3147 self._installdir = os.path.join(self._hgtmp, b"install") 3149 self._installdir = os.path.join(self._hgtmp, b"install")
3148 self._bindir = os.path.join(self._installdir, b"bin") 3150 self._bindir = os.path.join(self._installdir, b"bin")
3149 self._hgcommand = b'hg' 3151 self._hgcommand = b'hg'
3150 self._tmpbindir = self._bindir
3151 self._pythondir = os.path.join(self._installdir, b"lib", b"python") 3152 self._pythondir = os.path.join(self._installdir, b"lib", b"python")
3152 3153
3153 # Force the use of hg.exe instead of relying on MSYS to recognize hg is 3154 # Force the use of hg.exe instead of relying on MSYS to recognize hg is
3154 # a python script and feed it to python.exe. Legacy stdio is force 3155 # a python script and feed it to python.exe. Legacy stdio is force
3155 # enabled by hg.exe, and this is a more realistic way to launch hg 3156 # enabled by hg.exe, and this is a more realistic way to launch hg
3208 path.insert(1, chgbindir) 3209 path.insert(1, chgbindir)
3209 if rhgbindir != self._bindir: 3210 if rhgbindir != self._bindir:
3210 path.insert(1, rhgbindir) 3211 path.insert(1, rhgbindir)
3211 if self._testdir != runtestdir: 3212 if self._testdir != runtestdir:
3212 path = [self._testdir] + path 3213 path = [self._testdir] + path
3213 if self._tmpbindir != self._bindir: 3214 path = [self._custom_bin_dir] + path
3214 path = [self._tmpbindir] + path
3215 osenvironb[b"PATH"] = sepb.join(path) 3215 osenvironb[b"PATH"] = sepb.join(path)
3216 3216
3217 # Include TESTDIR in PYTHONPATH so that out-of-tree extensions 3217 # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
3218 # can run .../tests/run-tests.py test-foo where test-foo 3218 # can run .../tests/run-tests.py test-foo where test-foo
3219 # adds an extension to HGRC. Also include run-test.py directory to 3219 # adds an extension to HGRC. Also include run-test.py directory to
3552 if getattr(os, 'symlink', None) and not WINDOWS: 3552 if getattr(os, 'symlink', None) and not WINDOWS:
3553 msg = "# Making python executable in test path a symlink to '%s'" 3553 msg = "# Making python executable in test path a symlink to '%s'"
3554 msg %= sysexecutable 3554 msg %= sysexecutable
3555 vlog(msg) 3555 vlog(msg)
3556 for pyexename in pyexe_names: 3556 for pyexename in pyexe_names:
3557 mypython = os.path.join(self._tmpbindir, pyexename) 3557 mypython = os.path.join(self._custom_bin_dir, pyexename)
3558 try: 3558 try:
3559 if os.readlink(mypython) == sysexecutable: 3559 if os.readlink(mypython) == sysexecutable:
3560 continue 3560 continue
3561 os.unlink(mypython) 3561 os.unlink(mypython)
3562 except OSError as err: 3562 except OSError as err: