Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Boost.Process with cpp-subprocess #28981

Merged
merged 3 commits into from Apr 10, 2024

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Dec 1, 2023

Closes #24907.

This PR is based on theStack's work.

The subprocess.hpp header has been sourced from the upstream repo with the only modification being the removal of convenience functions, which are not utilized in our codebase.

Windows-related changes will be addressed in subsequent follow-ups.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 1, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK achow101, theStack, Sjors, fanquake
Concept ACK TheCharlatan, dergoegge

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29744 (lint: Refactor lint checks to reuse exclusion logic; Support running individual lint checks in lint runner by davidgumberg)
  • #22417 (util/system: Close non-std fds when execing slave processes by luke-jr)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@TheCharlatan
Copy link
Contributor

Concept ACK

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the compile error is due to subprocess requiring C++17 and not allowing C++20 (or later)?

@@ -12,7 +12,7 @@
from subprocess import check_output, STDOUT, CalledProcessError

IGNORE_WORDS_FILE = 'test/lint/spelling.ignore-words.txt'
FILES_ARGS = ['git', 'ls-files', '--', ":(exclude)build-aux/m4/", ":(exclude)contrib/seeds/*.txt", ":(exclude)depends/", ":(exclude)doc/release-notes/", ":(exclude)src/leveldb/", ":(exclude)src/crc32c/", ":(exclude)src/qt/locale/", ":(exclude)src/qt/*.qrc", ":(exclude)src/secp256k1/", ":(exclude)src/minisketch/", ":(exclude)contrib/guix/patches"]
FILES_ARGS = ['git', 'ls-files', '--', ":(exclude)build-aux/m4/", ":(exclude)contrib/seeds/*.txt", ":(exclude)depends/", ":(exclude)doc/release-notes/", ":(exclude)src/leveldb/", ":(exclude)src/crc32c/", ":(exclude)src/qt/locale/", ":(exclude)src/qt/*.qrc", ":(exclude)src/secp256k1/", ":(exclude)src/minisketch/", ":(exclude)src/util/subprocess.hpp", ":(exclude)contrib/guix/patches"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could split this into one-per-line to avoid overly long lines, diffs and reduce merge conflicts?

Copy link
Member

@fanquake fanquake Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably easier to just fix the typos, then add more things for linters to exclude? No new ones should be introduced.

@fanquake
Copy link
Member

fanquake commented Dec 1, 2023

Concept ACK on removing Boost Process. Is the plan to also delete any unused code from this header? I don't think copy-pasting dead/untested code into this repository is a good idea, and only serves to complicate review, and potentially cause issues in future (it maybe already doesn't work with c++20?)

@theStack
Copy link
Contributor

theStack commented Dec 1, 2023

Concept ACK, thanks for picking this up.

@hebasto
Copy link
Member Author

hebasto commented Dec 1, 2023

Is the plan to also delete any unused code from this header?

I haven't consider it yet.

it maybe already doesn't work with c++20?

CI jobs that uses C++20 are passing so far.

@sipa
Copy link
Member

sipa commented Dec 1, 2023

Is the plan to also delete any unused code from this header?

If at all possible, I'd prefer for it to be subtreed, so that updating to newer upstream versions is easy.

@fanquake
Copy link
Member

fanquake commented Dec 1, 2023

I was actually thinking the opposite. I think a subtree is overkill here, and, upstream isn't exactly active (some random merges but no development), so I'm not sure if there will be many new versions.

I'd rather take the small(er) portion of any code we need, and have something better integrated/reviewed. Hopefully that will help avoid randomly pulling code from upstream, that isn't well developed or reviewed.

@fanquake
Copy link
Member

fanquake commented Dec 1, 2023

Note that the last version from upstream was nearly 4 years ago: https://github.com/arun11299/cpp-subprocess/releases/tag/v2.0.

@hebasto
Copy link
Member Author

hebasto commented Dec 1, 2023

I'd rather take the small(er) portion of any code we need, and have something better integrated/reviewed.

Maybe a subtree from our own fork? (to avoid bringing testing stuff to the main repo)

@fanquake
Copy link
Member

fanquake commented Dec 1, 2023

Maybe a subtree from our own fork?

I think that would mostly just re-introduce the awkwardness we ended up with with univalue, for not much benefit, and for code that shouldn't be critical (i.e compared to leveldb & libsecp256k1), this is for an optional feature, that is not used by a large proportion of the people running this software.

@TheCharlatan
Copy link
Contributor

Re #28981 (comment)

I'd rather take the small(er) portion of any code we need, and have something better integrated/reviewed.

Looking at the coverage report of the header, there seems to be some potential for pruning out (89.2% function coverage and 67.4% line coverage),

@hebasto
Copy link
Member Author

hebasto commented Dec 2, 2023

I switched to the Popen constructor that accepts const std::string& instead of std::vector<std::string> to address quoting issues on Windows.

@theStack
Since you initially chose to use a vector, do you have any objections to this approach?


Here are the Windows functional tests -- https://github.com/hebasto/bitcoin/actions/runs/7072075125/job/19250502576

@DrahtBot DrahtBot removed the CI failed label Dec 2, 2023
@hebasto hebasto marked this pull request as ready for review December 2, 2023 21:23
@hebasto
Copy link
Member Author

hebasto commented Dec 2, 2023

CI turned green. Undrafted.

cc @achow101 @Sjors

@theStack
Copy link
Contributor

theStack commented Dec 3, 2023

I switched to the Popen constructor that accepts const std::string& instead of std::vector<std::string> to address quoting issues on Windows.

@theStack Since you initially chose to use a vector, do you have any objections to this approach?

No objections at all. I would have expected that passing the arguments as a single string is more prone to quoting issues than if it's done in a list, where quoting shouldn't be needed at all, but if it works, all the better :) (Maybe that unverified assumption made me use the std::vector Popen ctor back then, but I honestly don't really remember).

@hebasto
Copy link
Member Author

hebasto commented Dec 3, 2023

I switched to the Popen constructor that accepts const std::string& instead of std::vector<std::string> to address quoting issues on Windows.
@theStack Since you initially chose to use a vector, do you have any objections to this approach?

No objections at all. I would have expected that passing the arguments as a single string is more prone to quoting issues than if it's done in a list, where quoting shouldn't be needed at all, but if it works, all the better :) (Maybe that unverified assumption made me use the std::vector Popen ctor back then, but I honestly don't really remember).

To support the string-based approach, let's consider echo-ing a JSON-parsable string on Windows:

>echo {"success": true}
{"success": true}

and reproducing it using Python's subprocess module, which interface is mimicked in cpp-subprocess:

>>> import subprocess
>>> subprocess.run("cmd.exe /c echo {\"success\": true}")
{"success": true}
CompletedProcess(args='cmd.exe /c echo {"success": true}', returncode=0)

It becomes intricate when using a list of strings:

>>> subprocess.run(["cmd.exe", "/c", "echo", "{\"success\": true}"])
"{\"success\": true}"

or

>>> subprocess.run(["cmd.exe", "/c", "echo", "{\"success\":", "true}"])
{\"success\": true}

or

>>> subprocess.run(['cmd.exe', '/c', 'echo', '{"success":', 'true}'])
{\"success\": true}

hebasto and others added 3 commits March 27, 2024 14:16
Upstream repo: https://github.com/arun11299/cpp-subprocess
Commit: 4025693decacaceb9420efedbf4967a04cb028e7

The "Convenience Functions" section is unused in our codebase, so it has
been removed.
This primarily affects the `RunCommandParseJSON` utility function.
@hebasto
Copy link
Member Author

hebasto commented Mar 27, 2024

Rebased due to the conflict with the merged #29479.

@Sjors @theStack @achow101 sorry for invalidating your acks :)

@achow101
Copy link
Member

reACK d5a7155

Checked diff is just for resolving rebase conflicts.

@DrahtBot DrahtBot requested review from Sjors and theStack March 27, 2024 21:47
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Light re-ACK d5a7155

(as per git range-diff 86e1f24...d5a7155)

theStack added a commit to theStack/bitcoin that referenced this pull request Mar 28, 2024
As Boost::Process has been replaced by cpp-subprocess (PR bitcoin#28981), this
patch touches an unused code part and is hence not needed anymore.
@Sjors
Copy link
Member

Sjors commented Apr 2, 2024

re-tACK d5a7155

Tested display address from the GUI on a Trezor on Ubuntu.

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d5a7155 - with the expectation that this code is going to be maintained as our own. Next PRs should:

  • Remove linter exclusions and fix all issues.
  • Delete all unused code.
  • Rewrite in C++20.
  • hpp -> cpp ?

@fanquake fanquake merged commit 0a9cfd1 into bitcoin:master Apr 10, 2024
16 checks passed
theStack added a commit to theStack/bitcoin that referenced this pull request Apr 10, 2024
As Boost::Process has been replaced by cpp-subprocess (PR bitcoin#28981), this
patch touches an unused code part and is hence not needed anymore.
@hebasto hebasto deleted the 231130-replace-bp branch April 10, 2024 10:27
fanquake added a commit that referenced this pull request Apr 10, 2024
95c594f depends: remove no longer needed patch for Boost::Process (Sebastian Falbesoner)

Pull request description:

  As Boost::Process has been replaced by cpp-subprocess (PR #28981), this patch touches an unused code part and is hence not needed anymore.

ACKs for top commit:
  hebasto:
    ACK 95c594f, I have reviewed the code and it looks OK.
  fanquake:
    ACK 95c594f

Tree-SHA512: 0309b826f8c260e4180624f17302e51329fc4bd7a5431997d6d27d468dd5f7dbcd9db6a742efaba33ba30dbe361830eb1446fdbec927505ccf42412f9211934e
fanquake added a commit that referenced this pull request Apr 11, 2024
13f5391 Fix typos in `subprocess.hpp` (Hennadii Stepanov)

Pull request description:

  Resolves one item in the #28981 (review):
  >    - Remove linter exclusions and fix all issues.

  Based on upstream arun11299/cpp-subprocess#101.

ACKs for top commit:
  fanquake:
    ACK 13f5391

Tree-SHA512: 2ee27a5b7d1ba6f47a5148add155c918eadaaffb94a4b5dd3edea00e63440b87291c559361bf25a8db1567debff78cf7e9466dc34f14331ca1d426994837df93
Pttn added a commit to RiecoinTeam/Riecoin that referenced this pull request Apr 13, 2024
# Conflicts:
#	test/lint/lint-includes.py
#	test/lint/lint-spelling.py
hebasto added a commit to hebasto/bitcoin that referenced this pull request Apr 18, 2024
hebasto added a commit to hebasto/bitcoin that referenced this pull request Apr 18, 2024
@hebasto
Copy link
Member Author

hebasto commented Apr 23, 2024

... with the expectation that this code is going to be maintained as our own. Next PRs should:

  • Remove linter exclusions and fix all issues.

See:

  • Delete all unused code.

The work has been started in #29865.

hebasto added a commit to hebasto/bitcoin that referenced this pull request Apr 24, 2024
b8fd285 fixup! cmake: Add external signer support (Hennadii Stepanov)

Pull request description:

  This PR ports changes from bitcoin#28981.

ACKs for top commit:
  laanwj:
    Code review ACK b8fd285

Tree-SHA512: 338f0c8b4c94e2c706658c6b2f1306de8b6d9836dcebcefe7b81cd79d5dabf471b03afc597047a42351fda72b6c9ec2828b02c177f03df0011d3b801addda1bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Replacing Boost Process