deprecate use of include path to find the input file for behaviour that is compatible with other compilers and interopability for ccache

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10936 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2008-11-22 12:29:41 +00:00
commit 533ccb5097
7 changed files with 43 additions and 21 deletions

View file

@ -1,6 +1,11 @@
Version 1.3.37 (in progress)
============================
2008-11-21: wsfulton
The use of the include path to find the input file is now deprecated.
This makes the behaviour of SWIG the same as C/C++ compilers in preparation
for use with ccache.
2008-11-16: wsfulton
Fix -nopreprocess option to:
- correctly report file names in warning and error messages.

View file

@ -1886,16 +1886,19 @@ fragment_directive: FRAGMENT LPAREN fname COMMA kwargs RPAREN HBLOCK {
;
/* ------------------------------------------------------------
%includefile "filename" [ declarations ]
%importfile "filename" [ declarations ]
%includefile "filename" [option1="xyz", ...] [ declarations ]
%importfile "filename" [option1="xyz", ...] [ declarations ]
------------------------------------------------------------ */
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));
if ($2) {
String *maininput = Getattr($2, "maininput");
if (maininput)
scanner_set_main_input_file(NewString(maininput));
}
} interface RBRACKET {
String *mname = 0;
$$ = $6;

View file

@ -49,6 +49,7 @@
#define WARN_DEPRECATED_NOEXTERN 122
#define WARN_DEPRECATED_NODEFAULT 123
#define WARN_DEPRECATED_TYPEMAP_LANG 124
#define WARN_DEPRECATED_INPUT_FILE 125
/* -- Preprocessor -- */

View file

@ -947,7 +947,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (!s) {
fprintf(stderr, "Unable to locate '%s' in the SWIG library.\n", input_file);
} else {
FILE *f = Swig_open(outfile);
FILE *f = Swig_include_open(outfile);
if (f) {
fclose(f);
fprintf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile);
@ -974,17 +974,22 @@ int SWIG_main(int argc, char *argv[], Language *l) {
String *fs = NewString("");
FILE *df = Swig_open(input_file);
if (!df) {
char *cfile = Char(input_file);
if (cfile && cfile[0] == '-') {
Printf(stderr, "Unable to find option or file '%s', ", input_file);
Printf(stderr, "use 'swig -help' for more information.\n");
df = Swig_include_open(input_file);
if (!df) {
char *cfile = Char(input_file);
if (cfile && cfile[0] == '-') {
Printf(stderr, "Unable to find option or file '%s', ", input_file);
Printf(stderr, "use 'swig -help' for more information.\n");
} else {
Printf(stderr, "Unable to find file '%s'.\n", input_file);
}
SWIG_exit(EXIT_FAILURE);
} else {
Printf(stderr, "Unable to find file '%s'.\n", input_file);
Swig_warning(WARN_DEPRECATED_INPUT_FILE, "SWIG", 1, "Use of the include path to find the input file is deprecated and will not work with ccache. Please include the path when specifying the input file.\n"); // so that behaviour is like c/c++ compilers
}
SWIG_exit(EXIT_FAILURE);
}
fclose(df);
if (!no_cpp) {
fclose(df);
Printf(fs, "%%include <swig.swg>\n");
if (allkw) {
Printf(fs, "%%include <allkw.swg>\n");
@ -992,7 +997,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (lang_config) {
Printf(fs, "\n%%include <%s>\n", lang_config);
}
Printf(fs, "%%include(maininput=1) \"%s\"\n", Swig_last_file());
Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", input_file, Swig_last_file());
for (i = 0; i < Len(libfiles); i++) {
Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i));
}
@ -1000,8 +1005,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
cpps = Preprocessor_parse(fs);
Delete(fs);
} else {
df = Swig_open(input_file);
cpps = Swig_read_file(df);
fclose(df);
}
if (Swig_error_count()) {
SWIG_exit(EXIT_FAILURE);

View file

@ -1624,7 +1624,7 @@ public:
} else if (Strcmp(code, "include") == 0) {
/* Include a file into the .pm file */
if (value) {
FILE *f = Swig_open(value);
FILE *f = Swig_include_open(value);
if (!f) {
Printf(stderr, "%s : Line %d. Unable to locate file %s\n", input_file, line_number, value);
} else {

View file

@ -151,10 +151,11 @@ List *Swig_search_path() {
/* -----------------------------------------------------------------------------
* Swig_open()
*
* Looks for a file and open it. Returns an open FILE * on success.
* open a file, optionally looking for it in the include path. Returns an open
* FILE * on success.
* ----------------------------------------------------------------------------- */
static FILE *Swig_open_any(const String_or_char *name, int sysfile) {
static FILE *Swig_open_file(const String_or_char *name, int sysfile, int use_include_path) {
FILE *f;
String *filename;
List *spath = 0;
@ -169,7 +170,7 @@ static FILE *Swig_open_any(const String_or_char *name, int sysfile) {
filename = NewString(cname);
assert(filename);
f = fopen(Char(filename), "r");
if (!f) {
if (!f && use_include_path) {
spath = Swig_search_path_any(sysfile);
ilen = Len(spath);
for (i = 0; i < ilen; i++) {
@ -193,8 +194,14 @@ static FILE *Swig_open_any(const String_or_char *name, int sysfile) {
return f;
}
/* Open a file - searching the include paths to find it */
FILE *Swig_include_open(const String_or_char *name) {
return Swig_open_file(name, 0, 1);
}
/* Open a file - does not use include paths to find it */
FILE *Swig_open(const String_or_char *name) {
return Swig_open_any(name, 0);
return Swig_open_file(name, 0, 0);
}
@ -235,7 +242,7 @@ static String *Swig_include_any(const String_or_char *name, int sysfile) {
String *str;
String *file;
f = Swig_open_any(name, sysfile);
f = Swig_open_file(name, sysfile, 1);
if (!f)
return 0;
str = Swig_read_file(f);
@ -265,7 +272,7 @@ String *Swig_include_sys(const String_or_char *name) {
int Swig_insert_file(const String_or_char *filename, File *outfile) {
char buffer[4096];
int nbytes;
FILE *f = Swig_open(filename);
FILE *f = Swig_include_open(filename);
if (!f)
return -1;

View file

@ -14,6 +14,7 @@ extern void Swig_push_directory(const String_or_char *dirname);
extern void Swig_pop_directory(void);
extern String *Swig_last_file(void);
extern List *Swig_search_path(void);
extern FILE *Swig_include_open(const String_or_char *name);
extern FILE *Swig_open(const String_or_char *name);
extern String *Swig_read_file(FILE *f);
extern String *Swig_include(const String_or_char *name);