{
char *tmp_stdout, *tmp_stderr, *tmp_dia;
struct stat st;
- int status;
+ int status, tmp_stdout_fd, tmp_stderr_fd;
tmp_stdout = format("%s.tmp.stdout", cached_obj);
- create_empty_tmp_file(&tmp_stdout);
+ tmp_stdout_fd = create_tmp_fd(&tmp_stdout);
tmp_stderr = format("%s.tmp.stderr", cached_obj);
- create_empty_tmp_file(&tmp_stderr);
+ tmp_stderr_fd = create_tmp_fd(&tmp_stderr);
args_add(args, "-o");
args_add(args, output_obj);
}
cc_log("Running real compiler");
- status = execute(args->argv, tmp_stdout, tmp_stderr);
+ status = execute(args->argv, tmp_stdout_fd, tmp_stderr_fd);
args_pop(args, 3);
if (stat(tmp_stdout, &st) != 0) {
char *input_base;
char *tmp;
char *path_stdout, *path_stderr;
- int status;
+ int status, path_stderr_fd;
struct file_hash *result;
/* ~/hello.c -> tmp.hello.123.i
}
path_stderr = format("%s/tmp.cpp_stderr", temp_dir());
- create_empty_tmp_file(&path_stderr);
+ path_stderr_fd = create_tmp_fd(&path_stderr);
add_pending_tmp_file(path_stderr);
time_of_compilation = time(NULL);
- if (!direct_i_file) {
- /* The temporary file needs the proper i_extension for the compiler to do
- * its thing. However, create_empty_tmp_file appends a suffix to the
- * filename, which is why the temporary file is created in two steps. */
- char *path_stdout_tmp = format("%s/%s.tmp", temp_dir(), input_base);
- create_empty_tmp_file(&path_stdout_tmp);
- path_stdout = format("%s.%s", path_stdout_tmp, conf->cpp_extension);
- x_rename(path_stdout_tmp, path_stdout);
- free(path_stdout_tmp);
+ if (direct_i_file) {
+ /* We are compiling a .i or .ii file - that means we can skip the cpp stage
+ * and directly form the correct i_tmpfile. */
+ path_stdout = input_file;
+ status = 0;
+ } else {
+ /* Run cpp on the input file to obtain the .i. */
+ int path_stdout_fd;
+ path_stdout = format("%s/%s.stdout", temp_dir(), input_base);
+ path_stdout_fd = create_tmp_fd(&path_stdout);
add_pending_tmp_file(path_stdout);
- /* run cpp on the input file to obtain the .i */
args_add(args, "-E");
args_add(args, input_file);
cc_log("Running preprocessor");
- status = execute(args->argv, path_stdout, path_stderr);
+ status = execute(args->argv, path_stdout_fd, path_stderr_fd);
args_pop(args, 2);
- } else {
- /* we are compiling a .i or .ii file - that means we
- can skip the cpp stage and directly form the
- correct i_tmpfile */
- path_stdout = input_file;
- status = 0;
}
if (status != 0) {
}
if (conf->unify) {
- /*
- * When we are doing the unifying tricks we need to include the
- * input file name in the hash to get the warnings right.
- */
+ /* When we are doing the unifying tricks we need to include the input file
+ * name in the hash to get the warnings right. */
hash_delimiter(hash, "unifyfilename");
hash_string(hash, input_file);
fatal("Failed to open %s: %s", path_stderr, strerror(errno));
}
- i_tmpfile = path_stdout;
+ if (direct_i_file) {
+ i_tmpfile = input_file;
+ } else {
+ /* i_tmpfile needs the proper cpp_extension for the compiler to do its
+ * thing correctly. */
+ i_tmpfile = format("%s.%s", path_stdout, conf->cpp_extension);
+ x_rename(path_stdout, i_tmpfile);
+ add_pending_tmp_file(i_tmpfile);
+ }
if (conf->run_second_cpp) {
free(path_stderr);
/* ------------------------------------------------------------------------- */
/* execute.c */
-int execute(char **argv,
- const char *path_stdout,
- const char *path_stderr);
+int execute(char **argv, int fd_out, int fd_err);
char *find_executable(const char *name, const char *exclude_name);
void print_command(FILE *fp, char **argv);
# define link(src,dst) (CreateHardLink(dst,src,NULL) ? 0 : -1)
# define lstat(a,b) stat(a,b)
# define execv(a,b) win32execute(a,b,0,NULL,NULL)
+#error TODO: Adapt win32execute to new execute API
# define execute(a,b,c) win32execute(*(a),a,1,b,c)
# define PATH_DELIM ";"
# define F_RDLCK 0
the full path to the compiler to run is in argv[0]
*/
int
-execute(char **argv, const char *path_stdout, const char *path_stderr)
+execute(char **argv, int fd_out, int fd_err)
{
pid_t pid;
- int status, fd_out, fd_err;
+ int status;
cc_log_argv("Executing ", argv);
-
- tmp_unlink(path_stdout);
- fd_out = open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
- if (fd_out == -1) {
- fatal("Error creating %s: %s", path_stdout, strerror(errno));
- }
-
- tmp_unlink(path_stderr);
- fd_err = open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
- if (fd_err == -1) {
- fatal("Error creating %s: %s", path_stderr, strerror(errno));
- }
-
pid = fork();
if (pid == -1) fatal("Failed to fork: %s", strerror(errno));