Commit 4185f1ce by Adam Nemet Committed by Adam Nemet

tlink.c (initial_cwd): New variable.

	* tlink.c (initial_cwd): New variable.
	(tlink_init): Initialize it.
	(recompile_files): Use tlink_execute() instead of system().  Don't
	duplicate verbose output of collect_execute.  Restore initial_cwd.
	Update comment before the function.

From-SVN: r86577
parent d0c5c9b1
2004-08-25 Adam Nemet <anemet@lnxw.com>
* tlink.c (initial_cwd): New variable.
(tlink_init): Initialize it.
(recompile_files): Use tlink_execute() instead of system(). Don't
duplicate verbose output of collect_execute. Restore initial_cwd.
Update comment before the function.
2004-08-25 Ziemowit Laski <zlaski@apple.com> 2004-08-25 Ziemowit Laski <zlaski@apple.com>
* c-typeck.c (build_c_cast): In ObjC, always preserve (and silently * c-typeck.c (build_c_cast): In ObjC, always preserve (and silently
......
...@@ -38,6 +38,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -38,6 +38,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
extern int prepends_underscore; extern int prepends_underscore;
static int tlink_verbose; static int tlink_verbose;
static char initial_cwd[MAXPATHLEN + 1];
/* Hash table boilerplate for working with htab_t. We have hash tables /* Hash table boilerplate for working with htab_t. We have hash tables
for symbol names, file names, and demangled symbols. */ for symbol names, file names, and demangled symbols. */
...@@ -272,6 +274,8 @@ tlink_init (void) ...@@ -272,6 +274,8 @@ tlink_init (void)
if (debug) if (debug)
tlink_verbose = 3; tlink_verbose = 3;
} }
getcwd (initial_cwd, sizeof (initial_cwd));
} }
static int static int
...@@ -432,9 +436,7 @@ maybe_tweak (char *line, file *f) ...@@ -432,9 +436,7 @@ maybe_tweak (char *line, file *f)
} }
/* Update the repo files for each of the object files we have adjusted and /* Update the repo files for each of the object files we have adjusted and
recompile. recompile. */
XXX Should this use collect_execute instead of system? */
static int static int
recompile_files (void) recompile_files (void)
...@@ -446,7 +448,10 @@ recompile_files (void) ...@@ -446,7 +448,10 @@ recompile_files (void)
while ((f = file_pop ()) != NULL) while ((f = file_pop ()) != NULL)
{ {
char *line, *command; char *line;
const char *p, *q;
char **argv;
struct obstack arg_stack;
FILE *stream = fopen (f->key, "r"); FILE *stream = fopen (f->key, "r");
const char *const outname = frob_extension (f->key, ".rnw"); const char *const outname = frob_extension (f->key, ".rnw");
FILE *output = fopen (outname, "w"); FILE *output = fopen (outname, "w");
...@@ -465,31 +470,68 @@ recompile_files (void) ...@@ -465,31 +470,68 @@ recompile_files (void)
fclose (output); fclose (output);
rename (outname, f->key); rename (outname, f->key);
obstack_grow (&temporary_obstack, "cd ", 3);
obstack_grow (&temporary_obstack, f->dir, strlen (f->dir));
obstack_grow (&temporary_obstack, "; ", 2);
obstack_grow (&temporary_obstack, c_file_name, strlen (c_file_name));
obstack_1grow (&temporary_obstack, ' ');
if (!f->args) if (!f->args)
{ {
error ("repository file `%s' does not contain command-line " error ("repository file `%s' does not contain command-line "
"arguments", f->key); "arguments", f->key);
return 0; return 0;
} }
obstack_grow (&temporary_obstack, f->args, strlen (f->args));
obstack_1grow (&temporary_obstack, ' '); /* Build a null-terminated argv array suitable for
command = obstack_copy0 (&temporary_obstack, f->main, strlen (f->main)); tlink_execute(). Manipulate arguments on the arg_stack while
building argv on the temporary_obstack. */
obstack_init (&arg_stack);
obstack_ptr_grow (&temporary_obstack, c_file_name);
for (p = f->args; *p != '\0'; p = q + 1)
{
/* Arguments are delimited by single-quotes. Find the
opening quote. */
p = strchr (p, '\'');
if (!p)
goto done;
/* Find the closing quote. */
q = strchr (p + 1, '\'');
if (!q)
goto done;
obstack_grow (&arg_stack, p + 1, q - (p + 1));
/* Replace '\'' with '. This is how set_collect_gcc_options
encodes a single-quote. */
while (q[1] == '\\' && q[2] == '\'' && q[3] == '\'')
{
const char *r;
r = strchr (q + 4, '\'');
if (!r)
goto done;
obstack_grow (&arg_stack, q + 3, r - (q + 3));
q = r;
}
obstack_1grow (&arg_stack, '\0');
obstack_ptr_grow (&temporary_obstack, obstack_finish (&arg_stack));
}
done:
obstack_ptr_grow (&temporary_obstack, f->main);
obstack_ptr_grow (&temporary_obstack, NULL);
argv = obstack_finish (&temporary_obstack);
if (tlink_verbose) if (tlink_verbose)
fprintf (stderr, _("collect: recompiling %s\n"), f->main); fprintf (stderr, _("collect: recompiling %s\n"), f->main);
if (tlink_verbose >= 3)
fprintf (stderr, "%s\n", command);
if (system (command) != 0) if (chdir (f->dir) != 0
|| tlink_execute (c_file_name, argv, NULL) != 0
|| chdir (initial_cwd) != 0)
return 0; return 0;
read_repo_file (f); read_repo_file (f);
obstack_free (&arg_stack, NULL);
obstack_free (&temporary_obstack, temporary_firstobj); obstack_free (&temporary_obstack, temporary_firstobj);
} }
return 1; return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment