winegcc: Lookup PATH in find_binary and don't try to run binaries that can't be found.

Based on winebuild.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-03-03 14:01:59 +01:00 committed by Alexandre Julliard
parent adc34d4a29
commit 945c61c32d
2 changed files with 44 additions and 7 deletions

View File

@ -34,6 +34,12 @@
# define min(x,y) (((x) < (y)) ? (x) : (y))
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
# define PATH_SEPARATOR ';'
#else
# define PATH_SEPARATOR ':'
#endif
int verbose = 0;
void error(const char* s, ...)
@ -305,18 +311,44 @@ file_type get_lib_type(enum target_platform platform, strarray* path, const char
const char *find_binary( const strarray* prefix, const char *name )
{
char *file_name, *args;
static strarray *path;
unsigned int i;
if (!prefix) return name;
if (strchr( name, '/' )) return name;
for (i = 0; i < prefix->size; i++)
file_name = xstrdup( name );
if ((args = strchr( file_name, ' ' ))) *args++ = 0;
if (prefix)
{
struct stat st;
char *prog = strmake( "%s/%s%s", prefix->base[i], name, EXEEXT );
if (stat( prog, &st ) == 0 && S_ISREG( st.st_mode ) && (st.st_mode & 0111)) return prog;
for (i = 0; i < prefix->size; i++)
{
struct stat st;
char *prog = strmake( "%s/%s%s", prefix->base[i], file_name, EXEEXT );
if (stat( prog, &st ) == 0 && S_ISREG( st.st_mode ) && (st.st_mode & 0111))
return args ? strmake( "%s %s", prog, args ) : prog;
free( prog );
}
}
return name;
if (!path)
{
path = strarray_alloc();
/* then append the PATH directories */
if (getenv( "PATH" ))
{
char *p = xstrdup( getenv( "PATH" ));
while (*p)
{
strarray_add( path, p );
while (*p && *p != PATH_SEPARATOR) p++;
if (!*p) break;
*p++ = 0;
}
}
}
return prefix == path ? NULL : find_binary( path, name );
}
int spawn(const strarray* prefix, const strarray* args, int ignore_errors)

View File

@ -316,6 +316,7 @@ static char* get_temp_file(const char* prefix, const char* suffix)
static const char* build_tool_name(struct options *opts, const char* base, const char* deflt)
{
const char *path;
char* str;
if (opts->target && opts->version)
@ -332,7 +333,10 @@ static const char* build_tool_name(struct options *opts, const char* base, const
}
else
str = xstrdup(deflt);
return find_binary( opts->prefix, str );
if ((path = find_binary( opts->prefix, str ))) return path;
error( "Could not find %s\n", base );
return NULL;
}
static strarray* get_translator(struct options *opts)
@ -877,6 +881,7 @@ static strarray *get_winebuild_args(struct options *opts)
binary = strmake( "%s/winebuild%s", bindir, EXEEXT );
else
binary = find_binary( opts->prefix, "winebuild" );
if (!binary) error( "Could not find winebuild\n" );
strarray_add( spec_args, binary );
if (verbose) strarray_add( spec_args, "-v" );
if (keep_generated) strarray_add( spec_args, "--save-temps" );