[PATCH 3 of 6 v3] setup-rust: add a --no-rust flag

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Mar 9 17:34:54 UTC 2020


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1583507190 -3600
#      Fri Mar 06 16:06:30 2020 +0100
# Node ID 4094a983cfe6f59ddbec04c34a0070137911d6fa
# Parent  bbfdc8c2f3a2ac0f3c4921351614f4e134b0d46d
# EXP-Topic rust-test-option
# Available At https://dev.heptapod.net/octobus/mercurial-devel/
#              hg pull https://dev.heptapod.net/octobus/mercurial-devel/ -r 4094a983cfe6
setup-rust: add a --no-rust flag

This new flag will make sure the rust extension will not be build. If neither
`--rust` nor `--no-rust` is specified the `HGWITHRUSTEXT` is used.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -136,14 +136,6 @@ else:
 
 ispypy = "PyPy" in sys.version
 
-hgrustext = os.environ.get('HGWITHRUSTEXT')
-# TODO record it for proper rebuild upon changes
-# (see mercurial/__modulepolicy__.py)
-if hgrustext != 'cpython' and hgrustext is not None:
-    if hgrustext:
-        printf('unkown HGWITHRUSTEXT value: %s' % hgrustext, file=sys.stderr)
-    hgrustext = None
-
 import ctypes
 import errno
 import stat, subprocess, time
@@ -478,14 +470,45 @@ class hgbuildmo(build):
 
 class hgdist(Distribution):
     pure = False
-    rust = hgrustext is not None
+    rust = False
+    no_rust = False
     cffi = ispypy
 
     global_options = Distribution.global_options + [
         ('pure', None, "use pure (slow) Python code instead of C extensions"),
         ('rust', None, "use Rust extensions additionally to C extensions"),
+        (
+            'no-rust',
+            None,
+            "do not use Rust extensions additionally to C extensions",
+        ),
     ]
 
+    negative_opt = Distribution.negative_opt.copy()
+    boolean_options = ['pure', 'rust', 'no-rust']
+    negative_opt['no-rust'] = 'rust'
+
+    def _set_command_options(self, command_obj, option_dict=None):
+        command_obj.boolean_options += self.boolean_options
+        return Distribution._set_command_options(
+            self, command_obj, option_dict=option_dict
+        )
+
+    def parse_command_line(self):
+        ret = Distribution.parse_command_line(self)
+        if not (self.rust or self.no_rust):
+            hgrustext = os.environ.get('HGWITHRUSTEXT')
+            # TODO record it for proper rebuild upon changes
+            # (see mercurial/__modulepolicy__.py)
+            if hgrustext != 'cpython' and hgrustext is not None:
+                if hgrustext:
+                    msg = 'unkown HGWITHRUSTEXT value: %s' % hgrustext
+                    printf(msg, file=sys.stderr)
+                hgrustext = None
+            self.rust = hgrustext is not None
+            self.no_rust = not self.rust
+        return ret
+
     def has_ext_modules(self):
         # self.ext_modules is emptied in hgbuildpy.finalize_options which is
         # too late for some cases



More information about the Mercurial-devel mailing list