Skip to content

Commit 888d2d7

Browse files
authored
Merge pull request #42 from NobodyXu/fix/configure-make
Add `configure_make`: Set `MAKEFLAGS` & `MFLAGS`
2 parents a66acbc + a55f5f2 commit 888d2d7

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/lib.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,41 @@ impl Client {
290290
///
291291
/// On platforms other than Unix and Windows this panics.
292292
pub fn configure(&self, cmd: &mut Command) {
293+
cmd.env("CARGO_MAKEFLAGS", &self.mflags_env());
294+
self.inner.configure(cmd);
295+
}
296+
297+
/// Configures a child process to have access to this client's jobserver as
298+
/// well.
299+
///
300+
/// This function is required to be called to ensure that a jobserver is
301+
/// properly inherited to a child process. If this function is *not* called
302+
/// then this `Client` will not be accessible in the child process. In other
303+
/// words, if not called, then `Client::from_env` will return `None` in the
304+
/// child process (or the equivalent of `Child::from_env` that `make` uses).
305+
///
306+
/// ## Platform-specific behavior
307+
///
308+
/// On Unix and Windows this will clobber the `CARGO_MAKEFLAGS`,
309+
/// `MAKEFLAGS` and `MFLAGS` environment variables for the child process,
310+
/// and on Unix this will also allow the two file descriptors for
311+
/// this client to be inherited to the child.
312+
///
313+
/// On platforms other than Unix and Windows this panics.
314+
pub fn configure_make(&self, cmd: &mut Command) {
315+
let value = self.mflags_env();
316+
cmd.env("CARGO_MAKEFLAGS", &value);
317+
cmd.env("MAKEFLAGS", &value);
318+
cmd.env("MFLAGS", &value);
319+
self.inner.configure(cmd);
320+
}
321+
322+
fn mflags_env(&self) -> String {
293323
let arg = self.inner.string_arg();
294324
// Older implementations of make use `--jobserver-fds` and newer
295325
// implementations use `--jobserver-auth`, pass both to try to catch
296326
// both implementations.
297-
let value = format!("-j --jobserver-fds={0} --jobserver-auth={0}", arg);
298-
cmd.env("CARGO_MAKEFLAGS", &value);
299-
self.inner.configure(cmd);
327+
format!("-j --jobserver-fds={0} --jobserver-auth={0}", arg)
300328
}
301329

302330
/// Converts this `Client` into a helper thread to deal with a blocking

0 commit comments

Comments
 (0)