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

Make the single argument constructor inherit the env #113

Merged
merged 16 commits into from
Nov 8, 2023

Conversation

mjcarroll
Copy link
Contributor

@mjcarroll mjcarroll commented Oct 31, 2023

Now there are three ways to spawn a subprocess:

  • Subprocess({"env"}) - Spawn subprocess and inherit environment from current executable
  • Subprocess({"env"}, {}) - Spawn subprocess with empty custom environment
  • Subprocess({"env"}, {"FOO=BAR"}) - Spawn subprocess with custom environment.

Opening for comment, still needs tests + docs

Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Merging #113 (f59eccb) into gz-utils2 (8529918) will increase coverage by 1.21%.
The diff coverage is 100.00%.

❗ Current head f59eccb differs from pull request most recent head a81031c. Consider uploading reports for the commit a81031c to get more accurate results

@@              Coverage Diff              @@
##           gz-utils2     #113      +/-   ##
=============================================
+ Coverage      79.67%   80.89%   +1.21%     
=============================================
  Files              8        8              
  Lines            364      382      +18     
=============================================
+ Hits             290      309      +19     
+ Misses            74       73       -1     
Files Coverage Δ
include/gz/utils/Subprocess.hh 97.14% <100.00%> (+0.53%) ⬆️
src/Environment.cc 88.52% <100.00%> (+1.48%) ⬆️

... and 1 file with indirect coverage changes

This adds functions for using collections with the environment.  It
allows for conveniently retreiving and setting the environment variables
via a map, rather than individually.

This also adds a clearenv and printenv for completeness.

Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
@mjcarroll mjcarroll changed the base branch from gz-utils2 to mjcarroll/environment_features November 1, 2023 16:12
@mjcarroll mjcarroll force-pushed the mjcarroll/inheritenv branch from 4d1e541 to d64ff9b Compare November 1, 2023 16:13
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
@mjcarroll mjcarroll force-pushed the mjcarroll/inheritenv branch from d64ff9b to a0a1c47 Compare November 2, 2023 14:57
@mjcarroll mjcarroll marked this pull request as ready for review November 2, 2023 14:58
@mjcarroll mjcarroll requested a review from azeey as a code owner November 2, 2023 14:58
@mjcarroll mjcarroll self-assigned this Nov 3, 2023
@azeey
Copy link
Contributor

azeey commented Nov 6, 2023

Windows CI is not happy

Base automatically changed from mjcarroll/environment_features to gz-utils2 November 7, 2023 14:20
@mjcarroll
Copy link
Contributor Author

Windows CI is not happy

And not in an expected place, I will take a look.

Signed-off-by: Michael Carroll <[email protected]>
@mjcarroll
Copy link
Contributor Author

@azeey should be good now

@mjcarroll mjcarroll closed this Nov 8, 2023
@mjcarroll mjcarroll reopened this Nov 8, 2023
public: Subprocess(const std::vector<std::string> &_commandLine,
const std::vector<std::string> &_environment = {}):
gz::utils::EnvironmentMap _environment):
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this signature, but would it does break API. Would it be possible to add Subprocess(const std::vector<std::string> &_commandLine, const std::vector<std::string> &_environment)` that would turn around and call this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, ended up refactoring out my strings -> map -> strings functions so I can use the delegating constructor here.

One hitch is that it makes the map and vector constructors ambiguous:

// Could be either
Subprocess({}, {})

So now you have to explicitly do:

Subprocess({}, gz::utils::EnvironmentMap{});

Not a huge deal, but a little less clean imo.

Signed-off-by: Michael Carroll <[email protected]>
Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

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

LGTM!

include/gz/utils/Subprocess.hh Outdated Show resolved Hide resolved
Signed-off-by: Michael Carroll <[email protected]>
@mjcarroll mjcarroll merged commit db61818 into gz-utils2 Nov 8, 2023
8 checks passed
@mjcarroll mjcarroll deleted the mjcarroll/inheritenv branch November 8, 2023 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants