From owner-svn-src-projects@FreeBSD.ORG Fri Sep 18 01:41:46 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A4262106568B; Fri, 18 Sep 2009 01:41:46 +0000 (UTC) (envelope-from jb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 91E6B8FC19; Fri, 18 Sep 2009 01:41:46 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n8I1fkHZ075191; Fri, 18 Sep 2009 01:41:46 GMT (envelope-from jb@svn.freebsd.org) Received: (from jb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n8I1fk6O075185; Fri, 18 Sep 2009 01:41:46 GMT (envelope-from jb@svn.freebsd.org) Message-Id: <200909180141.n8I1fk6O075185@svn.freebsd.org> From: John Birrell Date: Fri, 18 Sep 2009 01:41:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r197301 - in projects/jbuild/usr.bin: jbuild jdirdep make X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Sep 2009 01:41:46 -0000 Author: jb Date: Fri Sep 18 01:41:46 2009 New Revision: 197301 URL: http://svn.freebsd.org/changeset/base/197301 Log: Work out what the exec path to the jbuild binary is based on logic from which(1) and then set that in the JBUILD variable so that child processes are execed with the same path. Save and set MANPATH in the child environment. Pass the JBUILD path through to jdirdep so that when dependencies change, the "jbuild gendirdep" gets executed using the same jbuild binary. Modified: projects/jbuild/usr.bin/jbuild/jbuild_version projects/jbuild/usr.bin/jdirdep/jdirdep.c projects/jbuild/usr.bin/jdirdep/jdirdep.h projects/jbuild/usr.bin/make/job.c projects/jbuild/usr.bin/make/main.c Modified: projects/jbuild/usr.bin/jbuild/jbuild_version ============================================================================== --- projects/jbuild/usr.bin/jbuild/jbuild_version Fri Sep 18 00:33:47 2009 (r197300) +++ projects/jbuild/usr.bin/jbuild/jbuild_version Fri Sep 18 01:41:46 2009 (r197301) @@ -1,5 +1,5 @@ # $FreeBSD$ -JBUILD_VERSION = 16 +JBUILD_VERSION = 17 CFLAGS += -DJBUILD_VERSION=\"${JBUILD_VERSION}\" Modified: projects/jbuild/usr.bin/jdirdep/jdirdep.c ============================================================================== --- projects/jbuild/usr.bin/jdirdep/jdirdep.c Fri Sep 18 00:33:47 2009 (r197300) +++ projects/jbuild/usr.bin/jdirdep/jdirdep.c Fri Sep 18 01:41:46 2009 (r197301) @@ -648,7 +648,7 @@ lockf_delete(void) static void do_dirdep(const char *srctop, const char *curdir, const char *srcrel, const char *objroot, - const char *sharedobj, int options) + const char *sharedobj, int options, const char *p_jbuild) { DIR *d; FILE *fp; @@ -1025,9 +1025,6 @@ do_dirdep(const char *srctop, const char err(1, "Could not delete '%s/%s", curdir, MAKEFILED); #ifdef JDIRDEP - const char *p_jbuild; - if ((p_jbuild = getenv("JBUILD")) == NULL) - p_jbuild = "jbuild"; snprintf(cmd, sizeof(cmd), "%s gendirdep", p_jbuild); #else snprintf(cmd, sizeof(cmd), "build gendirdep"); @@ -1054,7 +1051,7 @@ do_dirdep(const char *srctop, const char static void do_recurse(const char *srctop, const char *curdir, const char *srcrel, const char *objroot, - const char *sharedobj, int options) + const char *sharedobj, int options, const char *p_jbuild) { DIR *d; char path[MAXPATHLEN]; @@ -1084,7 +1081,7 @@ do_recurse(const char *srctop, const cha if (strcmp(de->d_name, MAKEFILE) == 0) { printf("Processing: %s\n", path); fflush(stdout); - do_dirdep(srctop, curdir, srcrel, objroot, sharedobj, options); + do_dirdep(srctop, curdir, srcrel, objroot, sharedobj, options, p_jbuild); continue; } @@ -1097,7 +1094,7 @@ do_recurse(const char *srctop, const cha snprintf(xsrcrel, sizeof(xsrcrel), "%s%s%s", srcrel, *srcrel == '\0' ? "" : "/", de->d_name); - do_recurse(srctop, path, xsrcrel, objroot, sharedobj, options); + do_recurse(srctop, path, xsrcrel, objroot, sharedobj, options, p_jbuild); } } @@ -1234,7 +1231,7 @@ jdirdep_incmk(const char *p) int jdirdep(const char *srctop, const char *curdir, const char *srcrel, const char *objroot, const char *objdir, const char *sharedobj, const char *filedep_name, - const char *meta_created, int options) + const char *meta_created, int options, const char *p_jbuild) { FILE *fp; char *meta_str = NULL; @@ -1285,9 +1282,9 @@ jdirdep(const char *srctop, const char * fclose(fp); } else if ((options & JDIRDEP_OPT_RECURSE) != 0) - do_recurse(srctop, curdir, srcrel, objroot, sharedobj, options); + do_recurse(srctop, curdir, srcrel, objroot, sharedobj, options, p_jbuild); else - do_dirdep(srctop, curdir, srcrel, objroot, sharedobj, options); + do_dirdep(srctop, curdir, srcrel, objroot, sharedobj, options, p_jbuild); jdirdep_db_close(); @@ -1303,6 +1300,7 @@ main(int argc, char *argv[]) { char curdir[MAXPATHLEN]; char *filedep_name = NULL; + char jbuild[MAXPATHLEN]; char objdir[MAXPATHLEN]; char objroot[MAXPATHLEN]; char objtop[MAXPATHLEN]; @@ -1335,6 +1333,11 @@ main(int argc, char *argv[]) strlcpy(srctop, p, sizeof(srctop)); + if ((p = getenv("JBUILD")) == NULL) + errx(1, "JBUILD is missing from the environment"); + + strlcpy(jbuild, p, sizeof(jbuild)); + if ((p = getenv("SUPMAC")) == NULL) errx(1, "SUPMAC is missing from the environment"); @@ -1420,6 +1423,6 @@ main(int argc, char *argv[]) } } - return(jdirdep(srctop, curdir, srcrel, objroot, objdir, sharedobj, filedep_name, NULL, options)); + return(jdirdep(srctop, curdir, srcrel, objroot, objdir, sharedobj, filedep_name, NULL, options, jbuild)); } #endif Modified: projects/jbuild/usr.bin/jdirdep/jdirdep.h ============================================================================== --- projects/jbuild/usr.bin/jdirdep/jdirdep.h Fri Sep 18 00:33:47 2009 (r197300) +++ projects/jbuild/usr.bin/jdirdep/jdirdep.h Fri Sep 18 01:41:46 2009 (r197301) @@ -22,7 +22,7 @@ typedef int (*db_cb_func)(void *, int, c int jdirdep(const char *srctop, const char *curdir, const char *srcrel, const char *objroot, const char *objdir, const char *sharedobj, const char *filedep_name, - const char *meta_created, int options); + const char *meta_created, int options, const char *jbuild); int64_t jdirdep_db_rowid(void); void jdirdep_db_close(void); void jdirdep_db_command(db_cb_func, void *, const char *, ...); Modified: projects/jbuild/usr.bin/make/job.c ============================================================================== --- projects/jbuild/usr.bin/make/job.c Fri Sep 18 00:33:47 2009 (r197300) +++ projects/jbuild/usr.bin/make/job.c Fri Sep 18 01:41:46 2009 (r197301) @@ -542,6 +542,7 @@ meta_exit(void) char sharedobj[MAXPATHLEN]; const char *curdir; const char *filedep_name; + const char *jbuild; const char *meta_created; const char *objdir; const char *objroot; @@ -587,6 +588,7 @@ meta_exit(void) srcrel = Var_Value(".SRCREL", VAR_GLOBAL); objdir = Var_Value(".OBJDIR", VAR_GLOBAL); objroot = Var_Value(".OBJROOT", VAR_GLOBAL); + jbuild = Var_Value("JBUILD", VAR_GLOBAL); filedep_name = Var_Value(".FILEDEP_NAME", VAR_GLOBAL); meta_created = Var_Value(".META_CREATED", VAR_GLOBAL); @@ -594,7 +596,8 @@ meta_exit(void) /* Add any new directory and/or source dependencies. */ jdirdep(srctop, curdir, srcrel, objroot, objdir, sharedobj, filedep_name, - meta_created, JDIRDEP_OPT_ADD | JDIRDEP_OPT_SOURCE | JDIRDEP_OPT_UPDATE); + meta_created, JDIRDEP_OPT_ADD | JDIRDEP_OPT_SOURCE | JDIRDEP_OPT_UPDATE, + jbuild); } } Modified: projects/jbuild/usr.bin/make/main.c ============================================================================== --- projects/jbuild/usr.bin/make/main.c Fri Sep 18 00:33:47 2009 (r197300) +++ projects/jbuild/usr.bin/make/main.c Fri Sep 18 01:41:46 2009 (r197301) @@ -119,6 +119,8 @@ static char **save_argv; /* saved argv * static char *save_makeflags;/* saved MAKEFLAGS */ #ifdef MAKE_IS_BUILD static char *save_mklvl; /* saved __MKLVL__ */ +static char *save_path; /* saved PATH */ +static char *save_manpath; /* saved MANPATH */ static char *clean_environ[2]; static char *default_machine = NULL; #endif @@ -953,6 +955,49 @@ mk_path_init(char *srctop, size_t ssrcto strlcpy(srctop, path, ssrctop); } + +static void +set_jbuild_path(char **argv) +{ + char candidate[PATH_MAX]; + char *p; + char *p_path; + char resolved_path[PATH_MAX]; + const char *d; + const char *p_jbuild; + struct stat fin; + + if ((p_jbuild = Var_Value("JBUILD", VAR_GLOBAL)) != NULL) { + fprintf(stderr, "JBUILD is already set to '%s'\n", p_jbuild); + } else if (strchr(argv[0], '/') == NULL) { + if ((p_path = strdup(save_path)) == NULL) + err(ENOMEM, "strdup"); + else { + p = p_path; + + while ((d = strsep(&p, ":")) != NULL) { + if (*d == '\0') + d = "."; + if (snprintf(candidate, sizeof(candidate), + "%s/jbuild", d) >= (int) sizeof(candidate)) + continue; + + if (access(candidate, X_OK) == 0 && + stat(candidate, &fin) == 0 && + S_ISREG(fin.st_mode) && + (getuid() != 0 || + (fin.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0)) { + Var_SetGlobal("JBUILD", candidate); + return; + } + } + } + free(p_path); + } else if (realpath(argv[0], resolved_path) == NULL) + err(errno, "Could not get realpath for '%s'", argv[0]); + else + Var_SetGlobal("JBUILD", resolved_path); +} #endif /** @@ -1004,6 +1049,8 @@ main(int argc, char **argv) #ifdef MAKE_IS_BUILD save_mklvl = getenv(MKLVL_ENVVAR); + save_path = getenv("PATH"); + save_manpath = getenv("MANPATH"); #endif /* @@ -1179,6 +1226,11 @@ main(int argc, char **argv) #ifdef MAKE_IS_BUILD if (default_machine != NULL) Var_SetGlobal("DEFAULT_MACHINE", default_machine); + + if (save_manpath != NULL) + setenv("MANPATH", save_manpath, 1); + + set_jbuild_path(argv); #endif /*