tests/test-issue1802.t
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 10 Jan 2018 08:53:22 -0800
changeset 35569 964212780daf
parent 34661 eb586ed5d8ce
child 42209 91a0bc50b288
permissions -rw-r--r--
rust: implementation of `hg` This commit provides a mostly-working implementation of the `hg` script in Rust along with scaffolding to support Rust in the repository. If you are familiar with Rust, the contents of the added rust/ directory should be pretty straightforward. We create an "hgcli" package that implements a binary application to run Mercurial. The output of this package is an "hg" binary. Our Rust `hg` (henceforth "rhg") essentially is a port of the existing `hg` Python script. The main difference is the creation of the embedded CPython interpreter is handled by the binary itself instead of relying on the shebang. In that sense, rhg is more similar to the "exe wrapper" we currently use on Windows. However, unlike the exe wrapper, rhg does not call the `hg` Python script. Instead, it uses the CPython APIs to import mercurial modules and call appropriate functions. The amount of code here is surprisingly small. It is my intent to replace the existing C-based exe wrapper with rhg. Preferably in the next Mercurial release. This should be achievable - at least for some Mercurial distributions. The future/timeline for rhg on other platforms is less clear. We already ship a hg.exe on Windows. So if we get the quirks with Rust worked out, shipping a Rust-based hg.exe should hopefully not be too contentious. Now onto the implementation. We're using python27-sys and the cpython crates for talking to the CPython API. We currently don't use too much functionality of the cpython crate and could have probably cut it out. However, it does provide a reasonable abstraction over unsafe {} CPython function calls. While we still have our fair share of those, at least we're not dealing with too much refcounting, error checking, etc. So I think the use of the cpython crate is justified. Plus, there is not-yet-implemented functionality that could benefit from cpython. I see our use of this crate only increasing. The cpython and python27-sys crates are not without their issues. The cpython crate didn't seem to account for the embedding use case in its design. Instead, it seems to assume that you are building a Python extension. It is making some questionable decisions around certain CPython APIs. For example, it insists that PyEval_ThreadsInitialized() is called and that the Python code likely isn't the main thread in the underlying application. It is also missing some functionality that is important for embedded use cases (such as exporting the path to the Python interpreter from its build script). After spending several hours trying to wrangle python27-sys and cpython, I gave up and forked the project on GitHub. Our Cargo.toml tracks this fork. I'm optimistic that the upstream project will accept our contributions and we can eventually unfork. There is a non-trivial amount of code in our custom Cargo build script. Our build.rs (which is called as part of building the hgcli crate): * Validates that the Python interpreter that was detected by the python27-sys crate provides a shared library (we only support shared library linking at this time - although this restriction could be loosened). * Validates that the Python is built with UCS-4 support. This ensures maximum Unicode compatibility. * Exports variables to the crate build allowing the built crate to e.g. find the path to the Python interpreter. The produced rhg should be considered alpha quality. There are several known deficiencies. Many of these are documented with inline TODOs. Probably the biggest limitation of rhg is that it assumes it is running from the ./rust/target/<target> directory of a source distribution. So, rhg is currently not very practical for real-world use. But, if you can `cargo build` it, running the binary *should* yield a working Mercurial CLI. In order to support using rhg with the test harness, we needed to hack up run-tests.py so the path to Mercurial's Python files is set properly. The change is extremely hacky and is only intended to be a stop-gap until the test harness gains first-class support for installing rhg. This will likely occur after we support running rhg outside the source directory. Despite its officially alpha quality, rhg copes extremely well with the test harness (at least on Linux). Using `run-tests.py --with-hg ../rust/target/debug/hg`, I only encounter the following failures: * test-run-tests.t -- Warnings emitted about using an unexpected Mercurial library. This is due to the hacky nature of setting the Python directory when run-tests.py detected rhg. * test-devel-warnings.t -- Expected stack trace missing frame for `hg` (This is expected since we no longer have an `hg` script!) * test-convert.t -- Test running `$PYTHON "$BINDIR"/hg`, which obviously assumes `hg` is a Python script. * test-merge-tools.t -- Same assumption about `hg` being executable with Python. * test-http-bad-server.t -- Seeing exit code 255 instead of 1 around line 358. * test-blackbox.t -- Exit code 255 instead of 1. * test-basic.t -- Exit code 255 instead of 1. It certainly looks like we have a bug around exit code handling. I don't think it is severe enough to hold up review and landing of this initial implementation. Perfect is the enemy of good. Differential Revision: https://phab.mercurial-scm.org/D1581
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22046
7a9cbb315d84 tests: replace exit 80 with #require
Matt Mackall <mpm@selenic.com>
parents: 18605
diff changeset
     1
#require execbit
15442
db0340f4b507 tests: use 'hghave execbit' for tests that manipulate x bit in file system
Mads Kiilerich <mads@kiilerich.com>
parents: 15337
diff changeset
     2
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
Create extension that can disable exec checks:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
  $ cat > noexec.py <<EOF
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
  > from mercurial import extensions, util
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
  > def setflags(orig, f, l, x):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     8
  >     pass
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     9
  > def checkexec(orig, path):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    10
  >     return False
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
  > def extsetup(ui):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
  >     extensions.wrapfunction(util, 'setflags', setflags)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
  >     extensions.wrapfunction(util, 'checkexec', checkexec)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
  > EOF
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
  $ hg init unix-repo
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
  $ cd unix-repo
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
  $ touch a
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    19
  $ hg add a
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
  $ hg commit -m 'unix: add a'
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    21
  $ hg clone . ../win-repo
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    22
  updating to branch default
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    24
  $ chmod +x a
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    25
  $ hg commit -m 'unix: chmod a'
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    26
  $ hg manifest -v
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    27
  755 * a
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    28
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    29
  $ cd ../win-repo
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    31
  $ touch b
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    32
  $ hg add b
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
  $ hg commit -m 'win: add b'
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    35
  $ hg manifest -v
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    36
  644   a
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
  644   b
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    38
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    39
  $ hg pull
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    40
  pulling from $TESTTMP/unix-repo
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    41
  searching for changes
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    42
  adding changesets
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    43
  adding manifests
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    44
  adding file changes
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    45
  added 1 changesets with 0 changes to 0 files (+1 heads)
34661
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 25125
diff changeset
    46
  new changesets 2d8bcf2dda39
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    47
  (run 'hg heads' to see heads, 'hg merge' to merge)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    48
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    49
  $ hg manifest -v -r tip
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    50
  755 * a
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    51
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    52
Simulate a Windows merge:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    53
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    54
  $ hg --config extensions.n=$TESTTMP/noexec.py merge --debug
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    55
    searching for copies back to rev 1
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    56
    unmatched files in local:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    57
     b
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    58
  resolving manifests
18605
bcf29565d89f manifestmerge: pass in branchmerge and force separately
Siddharth Agarwal <sid0@fb.com>
parents: 18334
diff changeset
    59
   branchmerge: True, force: False, partial: False
15625
efdcce3fd2d5 merge: make debug output easier to read
Martin Geisler <mg@aragost.com>
parents: 15442
diff changeset
    60
   ancestor: a03b0deabf2b, local: d6fa54f68ae1+, remote: 2d8bcf2dda39
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    61
   a: update permissions -> e
18334
44bda93df90e merge: changing the mode of a file is also an update
Mads Kiilerich <mads@kiilerich.com>
parents: 16913
diff changeset
    62
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    63
  (branch merge, don't forget to commit)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    64
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    65
Simulate a Windows commit:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    66
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    67
  $ hg --config extensions.n=$TESTTMP/noexec.py commit -m 'win: merge'
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    68
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    69
  $ hg manifest -v
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    70
  755 * a
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    71
  644   b
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 15625
diff changeset
    72
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 15625
diff changeset
    73
  $ cd ..