Patchwork [2,of,5,STABLE] setup-rust: add a --no-rust flag

login
register
mail settings
Submitter Pierre-Yves David
Date March 6, 2020, 4:25 p.m.
Message ID <a8944769d23b226e8916.1583511922@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/45562/
State Superseded
Headers show

Comments

Pierre-Yves David - March 6, 2020, 4:25 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1583507190 -3600
#      Fri Mar 06 16:06:30 2020 +0100
# Branch stable
# Node ID a8944769d23b226e89162099ed3c18ea09b31126
# Parent  8a8b350871ac41bd33be78b200853275a6a235a2
# EXP-Topic rust-test-option
# Available At https://dev.heptapod.net/octobus/mercurial-devel/
#              hg pull https://dev.heptapod.net/octobus/mercurial-devel/ -r a8944769d23b
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.

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -138,13 +138,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:
-        print('unkown HGWITHRUSTEXT value: %s' % hgrustext, file=sys.stderr)
-    hgrustext = None
 
 import ctypes
 import errno
@@ -480,14 +473,47 @@  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 and 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:
+                    print(
+                        'unkown HGWITHRUSTEXT value: %s' % hgrustext,
+                        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