Lines Matching full:shell
101 * Job_ParseShell Given a special dependency line with target '.SHELL',
102 * define the shell that is used for the creation
160 * A shell defines how the commands are run. All commands for a target are
161 * written into a single file, which is then given to the shell to execute
165 * The name of the shell is the basename for the predefined shells, such as
167 * basename is used to select the type of shell; the longest match wins.
171 * echoOn, noPrint and noPrintLen. When echoOff is executed by the shell, it
178 * In case a shell doesn't have error control, echoTmpl is a printf template
182 * causing the shell to exit on error. If any of these strings are empty when
186 * shell code injection, the escaped command is safe to use in double quotes.
189 * "echo" flag causes the shell to start echoing commands right away. The
190 * "exit" flag causes the shell to exit when an error is detected in one of
193 typedef struct Shell {
196 * The name of the shell. For Bourne and C shells, this is used only
197 * to find the shell description when used as the single source of a
198 * .SHELL target. For user-defined shells, this is the full path of
199 * the shell.
207 * shell. This is usually the same as echoOff */
226 char commentChar; /* character used by shell for comment lines */
228 const char *echoFlag; /* shell flag to echo commands */
229 const char *errFlag; /* shell flag to exit on error */
230 } Shell;
247 * Write shell commands to a file.
300 * select one of the predefined shells as the default shell.
303 * name or the full path of a sh-compatible shell, which will be used as
304 * the default shell.
306 * ".SHELL" lines in Makefiles can choose the default shell from the
325 static Shell shells[] = {
328 * An sh-compatible shell with a non-standard name.
403 * with the setting of the 'echo' shell variable. Sadly,
427 * This is the shell to which we pass all commands in the Makefile.
430 static Shell *shell = &shells[DEFSHELL_INDEX];
434 static char *shell_freeIt = NULL; /* Allocated memory for custom .SHELL */
805 if (shell->hasEchoCtl)
806 ShellWriter_WriteLine(wr, shell->echoOff);
812 ShellWriter_WriteFmt(wr, shell->echoTmpl, escCmd);
818 if (shell->hasEchoCtl)
819 ShellWriter_WriteLine(wr, shell->echoOn);
836 ShellWriter_WriteLine(wr, shell->errOff);
846 ShellWriter_WriteLine(wr, shell->errOn);
852 * The shell has no built-in error control, so emulate error control by
853 * enclosing each shell command in a template like "{ %s \n } || exit $?"
854 * (configurable per shell).
873 *inout_cmdTemplate = shell->runIgnTmpl;
889 else if (shell->hasErrCtl)
891 else if (shell->runIgnTmpl != NULL && shell->runIgnTmpl[0] != '\0') {
899 * Write a shell command to the job's commands file, to be run later.
902 * given to make, stick a shell-specific echoOff command in the script.
904 * If the command starts with '-' and the shell has no error control (none
923 /* Template for writing a command to the shell file */
951 * If the shell doesn't have error control, the alternate echoing
955 escCmd = shell->hasErrCtl ? NULL : EscapeShellDblQuot(xcmd);
958 if (job->echo && run && shell->hasEchoCtl)
960 else if (shell->hasErrCtl)
969 * If errors are being checked and the shell doesn't have
974 if (!shell->hasErrCtl && shell->runChkTmpl != NULL &&
975 shell->runChkTmpl[0] != '\0') {
985 cmdTemplate = escCmd[0] == shell->commentChar ||
987 ? shell->runIgnTmpl
988 : shell->runChkTmpl;
993 if (DEBUG(SHELL) && strcmp(shellName, "sh") == 0)
1008 * Write all commands to the shell file that is later executed.
1013 * Return whether at least one command was written to the shell file.
1193 Punt("Cannot write shell script for '%s': %s",
1416 * Execute the shell for the given job.
1418 * See Job_CatchOutput for handling the output of the shell.
1510 * to clear it before routing the shell's error output to
1559 Punt("Cannot write shell script for '%s': %s",
1573 /* Create the argv needed to execute the shell for a given job. */
1583 if ((shell->errFlag != NULL && shell->errFlag[0] != '-') ||
1584 (shell->echoFlag != NULL && shell->echoFlag[0] != '-')) {
1588 * shell thinks its second argument is a file to source.
1597 (shell->errFlag != NULL ? shell->errFlag : "")),
1599 (shell->echoFlag != NULL ? shell->echoFlag : "")));
1606 if (!job->ignerr && shell->errFlag != NULL) {
1607 argv[argc] = UNCONST(shell->errFlag);
1610 if (job->echo && shell->echoFlag != NULL) {
1611 argv[argc] = UNCONST(shell->echoFlag);
1622 * tfile is the name of a file into which all shell commands
1623 * are put. It is removed before the child shell is executed,
1658 * jobs. PMake is forked and a child shell created.
1666 char *argv[10]; /* Argument vector to shell */
1742 /* If we're not supposed to execute a shell, don't. */
1766 * Set up the control arguments to the shell. This is based on the
1771 /* Create the pipe by which we'll get the shell's output. */
1779 * If the shell has an output filter (which only csh and ksh have by default),
1781 * shell.
1791 if (shell->noPrint == NULL || shell->noPrint[0] == '\0')
1795 * XXX: What happens if shell->noPrint occurs on the boundary of
1800 while ((ep = strstr(p, shell->noPrint)) != NULL) {
1813 p = ep + shell->noPrintLen;
1828 * In the output of the shell, the 'noPrint' lines are removed. If the
1906 * to the shell description), we print the line, preceded
1919 * do anything in the default shell, this bug has gone
2166 shellName = shell->name;
2188 Var_SetWithFlags(SCOPE_CMDLINE, ".SHELL", shellPath,
2190 if (shell->errFlag == NULL)
2191 shell->errFlag = "";
2192 if (shell->echoFlag == NULL)
2193 shell->echoFlag = "";
2194 if (shell->hasErrCtl && shell->errFlag[0] != '\0') {
2196 strcmp(shell->errFlag, &shellErrFlag[1]) != 0) {
2201 shellErrFlag = str_concat2("-", shell->errFlag);
2209 * Return the string literal that is used in the current command shell
2215 return shell->newline;
2352 /* Find a shell in 'shells' given its name, or return NULL. */
2353 static Shell *
2356 Shell *sh = shells;
2357 const Shell *shellsEnd = sh + sizeof shells / sizeof shells[0];
2367 * Parse a shell specification and set up 'shell', shellPath and
2371 * line The shell spec
2377 * 'shell' points to a Shell structure (either predefined or
2378 * created from the shell spec), shellPath is the full path of the
2379 * shell described by 'shell', while shellName is just the
2383 * A shell specification consists of a .SHELL target, with dependency
2390 * name Name of shell.
2391 * path Location of shell.
2398 * hasErrCtl True if shell has error checking control
2417 Shell newShell;
2419 Shell *sh;
2506 "%s: No matching shell", newShell.name);
2510 shell = sh;
2530 "%s: No matching shell", shellName);
2534 shell = sh;
2536 shell = bmake_malloc(sizeof *shell);
2537 *shell = newShell;
2543 if (shell->echoOn != NULL && shell->echoOff != NULL)
2544 shell->hasEchoCtl = true;
2546 if (!shell->hasErrCtl) {
2547 if (shell->echoTmpl == NULL)
2548 shell->echoTmpl = "";
2549 if (shell->runIgnTmpl == NULL)
2550 shell->runIgnTmpl = "%s\n";
2555 * by the shell specification.