Fix -nopreprocess option to correctly generate output filenames and display filenames in warnings and errors

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10930 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2008-11-16 21:40:28 +00:00
commit 8ac9453f62
5 changed files with 81 additions and 53 deletions

View file

@ -1,9 +1,14 @@
2008-09-26 Mikel Bancroft <mikel@franz.com>
Version 1.3.37 (in progress)
============================
2008-11-01: wsfulton
2008-11-16: wsfulton
Fix -nopreprocess option to:
- correctly report file names in warning and error messages.
- use the original input filename that created the preprocessed output when
determining the C++ wrapper file name (in the absence of -o). Previously
the name of the input file containing the preprocessed output was used.
2008-11-11: wsfulton
[Java] Add patch #2152691 from MATSUURA Takanori which fixes compiles using the
Intel compiler

View file

@ -34,7 +34,9 @@ extern "C" {
extern void scanner_ignore_typedef(void);
extern void scanner_last_id(int);
extern void scanner_clear_rename(void);
extern void scanner_set_location(String_or_char *, int line);
extern void scanner_set_location(String_or_char *file, int line);
extern void scanner_set_main_input_file(String *file);
extern String *scanner_get_main_input_file();
extern void Swig_cparse_follow_locators(int);
extern void start_inline(char *, int);
extern String *scanner_ccode;

View file

@ -22,7 +22,10 @@ char cvsroot_cscanner_c[] = "$Id$";
static Scanner *scan = 0;
/* Global string containing C code. Used by the parser to grab code blocks */
DOHString *scanner_ccode = 0;
String *scanner_ccode = 0;
/* The main file being parsed */
static String *main_input_file = 0;
/* Error reporting/location information */
int cparse_line = 1;
@ -467,6 +470,14 @@ void scanner_next_token(int tok) {
next_token = tok;
}
void scanner_set_main_input_file(String *file) {
main_input_file = file;
}
String *scanner_get_main_input_file() {
return main_input_file;
}
/* ----------------------------------------------------------------------------
* int yylex()
*

View file

@ -1894,6 +1894,8 @@ include_directive: includetype options string LBRACKET {
$1.filename = Copy(cparse_file);
$1.line = cparse_line;
scanner_set_location(NewString($3),1);
if ($2 && GetFlag($2, "maininput"))
scanner_set_main_input_file(NewString($3));
} interface RBRACKET {
String *mname = 0;
$$ = $6;

View file

@ -965,11 +965,6 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
}
} else {
// Check the suffix for a .c file. If so, we're going to
// declare everything we see as "extern"
ForceExtern = check_suffix(input_file);
// Run the preprocessor
if (Verbose)
printf("Preprocessing...\n");
@ -997,7 +992,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (lang_config) {
Printf(fs, "\n%%include <%s>\n", lang_config);
}
Printf(fs, "%%include \"%s\"\n", Swig_last_file());
Printf(fs, "%%include(maininput=1) \"%s\"\n", Swig_last_file());
for (i = 0; i < Len(libfiles); i++) {
Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i));
}
@ -1006,7 +1001,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Delete(fs);
} else {
df = Swig_open(input_file);
cpps = NewFileFromFile(df);
cpps = Swig_read_file(df);
}
if (Swig_error_count()) {
SWIG_exit(EXIT_FAILURE);
@ -1016,47 +1011,53 @@ int SWIG_main(int argc, char *argv[], Language *l) {
SWIG_exit(EXIT_SUCCESS);
}
if (depend) {
String *outfile;
if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension);
if (!no_cpp) {
String *outfile;
if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension);
} else {
outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file));
}
} else {
outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file));
outfile = NewString(outfile_name);
}
if (dependencies_file && Len(dependencies_file) != 0) {
f_dependencies_file = NewFile(dependencies_file, "w", SWIG_output_files());
if (!f_dependencies_file) {
FileErrorDisplay(dependencies_file);
SWIG_exit(EXIT_FAILURE);
}
} else if (!depend_only) {
String *filename = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), depends_extension);
f_dependencies_file = NewFile(filename, "w", SWIG_output_files());
if (!f_dependencies_file) {
FileErrorDisplay(filename);
SWIG_exit(EXIT_FAILURE);
}
} else
f_dependencies_file = stdout;
if (dependencies_target) {
Printf(f_dependencies_file, "%s: ", dependencies_target);
} else {
Printf(f_dependencies_file, "%s: ", outfile);
}
List *files = Preprocessor_depend();
for (int i = 0; i < Len(files); i++) {
if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) {
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
}
}
Printf(f_dependencies_file, "\n");
if (f_dependencies_file != stdout)
Close(f_dependencies_file);
if (depend_only)
SWIG_exit(EXIT_SUCCESS);
} else {
outfile = NewString(outfile_name);
Printf(stderr, "Cannot generate dependencies with -nopreprocess\n");
// Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse
SWIG_exit(EXIT_FAILURE);
}
if (dependencies_file && Len(dependencies_file) != 0) {
f_dependencies_file = NewFile(dependencies_file, "w", SWIG_output_files());
if (!f_dependencies_file) {
FileErrorDisplay(dependencies_file);
SWIG_exit(EXIT_FAILURE);
}
} else if (!depend_only) {
String *filename = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), depends_extension);
f_dependencies_file = NewFile(filename, "w", SWIG_output_files());
if (!f_dependencies_file) {
FileErrorDisplay(filename);
SWIG_exit(EXIT_FAILURE);
}
} else
f_dependencies_file = stdout;
if (dependencies_target) {
Printf(f_dependencies_file, "%s: ", dependencies_target);
} else {
Printf(f_dependencies_file, "%s: ", outfile);
}
List *files = Preprocessor_depend();
for (int i = 0; i < Len(files); i++) {
if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) {
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
}
}
Printf(f_dependencies_file, "\n");
if (f_dependencies_file != stdout)
Close(f_dependencies_file);
if (depend_only)
SWIG_exit(EXIT_SUCCESS);
}
Seek(cpps, 0, SEEK_SET);
}
@ -1138,18 +1139,20 @@ int SWIG_main(int argc, char *argv[], Language *l) {
SWIG_exit(EXIT_FAILURE);
} else {
/* Set some filename information on the object */
Setattr(top, "infile", input_file);
String *infile = scanner_get_main_input_file();
Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
Setattr(top, "inputfile", input_file);
if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
Setattr(top, "outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension));
Setattr(top, "outfile", NewStringf("%s_wrap.%s", Swig_file_basename(infile), cpp_extension));
} else {
Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file)));
Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(infile)));
}
} else {
Setattr(top, "outfile", outfile_name);
}
if (!outfile_name_h) {
Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), hpp_extension));
Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(infile), hpp_extension));
} else {
Setattr(top, "outfile_h", outfile_name_h);
}
@ -1157,7 +1160,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (Swig_contract_mode_get()) {
Swig_contracts(top);
}
// Check the suffix for a c/c++ file. If so, we're going to declare everything we see as "extern"
ForceExtern = check_suffix(input_file);
lang->top(top);
if (browse) {
Swig_browser(top, 0);
}