Patchwork [5,of,6,v3] run-tests: add option for running with and without Rust extensions

login
register
mail settings
Submitter Pierre-Yves David
Date March 9, 2020, 5:34 p.m.
Message ID <5e7e2fecabbc0859174a.1583775296@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/45638/
State Accepted
Headers show

Comments

Pierre-Yves David - March 9, 2020, 5:34 p.m.
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1583489775 -3600
#      Fri Mar 06 11:16:15 2020 +0100
# Node ID 5e7e2fecabbc0859174a1d09b092d3e0386ab458
# Parent  7653a195e622714c5c2fc9232941d1bb224273aa
# EXP-Topic rust-test-option
# Available At https://dev.heptapod.net/octobus/mercurial-devel/
#              hg pull https://dev.heptapod.net/octobus/mercurial-devel/ -r 5e7e2fecabbc
run-tests: add option for running with and without Rust extensions

This provide a simple and clear way to run the test with or without rust.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -53,6 +53,7 @@  import errno
 import json
 import multiprocessing
 import os
+import platform
 import random
 import re
 import shutil
@@ -555,6 +556,16 @@  def getparser():
         help="use pure Python code instead of C extensions",
     )
     hgconf.add_argument(
+        "--rust",
+        action="store_true",
+        help="use Rust code alongside C extensions",
+    )
+    hgconf.add_argument(
+        "--no-rust",
+        action="store_true",
+        help="do not use Rust code even if compiled",
+    )
+    hgconf.add_argument(
         "--with-chg",
         metavar="CHG",
         help="use specified chg wrapper in place of hg",
@@ -637,6 +648,15 @@  def parseargs(args, parser):
     if 'java' in sys.platform or '__pypy__' in sys.modules:
         options.pure = True
 
+    if platform.python_implementation() != 'CPython' and options.rust:
+        parser.error('Rust extensions are only available with CPython')
+
+    if options.pure and options.rust:
+        parser.error('--rust cannot be used with --pure')
+
+    if options.rust and options.no_rust:
+        parser.error('--rust cannot be used with --no-rust')
+
     if options.local:
         if options.with_hg or options.with_chg:
             parser.error('--local cannot be used with --with-hg or --with-chg')
@@ -3098,6 +3118,13 @@  class TestRunner(object):
         if self.options.pure:
             os.environ["HGTEST_RUN_TESTS_PURE"] = "--pure"
             os.environ["HGMODULEPOLICY"] = "py"
+        if self.options.rust:
+            os.environ["HGMODULEPOLICY"] = "rust+c"
+        if self.options.no_rust:
+            current_policy = os.environ.get("HGMODULEPOLICY", "")
+            if current_policy.startswith("rust+"):
+                os.environ["HGMODULEPOLICY"] = current_policy[len("rust+") :]
+            os.environ.pop("HGWITHRUSTEXT", None)
 
         if self.options.allow_slow_tests:
             os.environ["HGTEST_SLOW"] = "slow"
@@ -3431,6 +3458,10 @@  class TestRunner(object):
         setup_opts = b""
         if self.options.pure:
             setup_opts = b"--pure"
+        elif self.options.rust:
+            setup_opts = b"--rust"
+        elif self.options.no_rust:
+            setup_opts = b"--no-rust"
 
         # Run installer in hg root
         script = os.path.realpath(sys.argv[0])