[distcc] Re: detecting architecture of DISTCC HOSTS ?
Han-Wen Nienhuys
hanwen at byrd.xs4all.nl
Mon Feb 20 12:55:54 GMT 2006
In article <dtcb5g$7ss$1 at sea.gmane.org>,
Han-Wen Nienhuys <hanwen at xs4all.nl> wrote:
>>There is not anything like that at the moment, but you could add it
>>fairly easily, probably without modifying the server code. It'd be a
>>worthy addition.
>
>Come to think of it, having another feature would actually be even
>better: it would be nice if I could setup a mapping, so that if distcc
>gets invoked on Linux
>
> distcc gcc
>
>it will call
>
> i686-linux-gcc
>
>on other hosts, while it will do
>
> powerpc-darwin-gcc
>
>if distcc was started on a Mac.
See this patch, also on
http://www.xs4all.nl/~hanwen/public/software/distcc-substitute.patch
For example
DISTCC_SUBSTITUTE_GXX='i686-linux-g++' distcc
will remotely invoke i686-linux-g++ when g++ is run locally.
This is useful as cross-building some packages require both a native
gcc and a cross-compiling gcc to be present. Setting
DISTCC_SUBSTITUTE_GCC= allows the native compiler invocations to be
distcc'd to different machine types as well.
Arguably, there it might even be sensible to have
DISTCC_SUBSTITUTE_<compilername>_<hostname>
but I have left it out, as I don't need it.
My groff knowledge is non-existent. Could someone review my diffs to
the manpage? Thanks!
diff -ur distcc-2.18.3/man/distcc.1 distcc-2.18.3.subs/man/distcc.1
--- distcc-2.18.3/man/distcc.1 2004-10-24 07:05:23.000000000 +0200
+++ distcc-2.18.3.subs/man/distcc.1 2006-02-20 13:50:35.000000000 +0100
@@ -420,6 +420,19 @@
error stream or in the log file. This can be helpful in debugging
problems. Bug reports should include verbose output.
.TP
+.B "DISTCC_SUBSTITUTE_compilername"
+Before shipping a job to a remote client, distcc will substitute
+the value of this variable for
+.B compiler;
+compilername should uppercase, with non-alphanumeric characters
+replaced by Xs. For example, a call of g++ can be changed to by
+i686-linux-g++-3.4 remotely by setting
+.PP
+.nf
+ DISTCC_SUBSTITUTE_GXX="i686-linux-g++-3.4"
+.fi
+.PP
+.TP
.B "DISTCC_LOG"
Log file to receive messages from distcc itself, rather
than stderr.
@@ -469,10 +482,11 @@
mixed-architecture machines, although some changes to the
compilation commands may be required.
.PP
-The compilation command passed to distcc must be one that
-will execute properly on every volunteer machine to produce
-an object file of the appropriate type. If the machines
-have different processors, then simply using
+The compilation command passed to distcc or set in
+DISTCC_SUBSTITUTE_compilername must be one that will execute properly
+on every volunteer machine to produce an object file of the
+appropriate type. If the machines have different processors, then
+simply using
.B distcc cc
will probably not work, because that will normally invoke the
volunteer's native compiler.
diff -ur distcc-2.18.3/src/distcc.c distcc-2.18.3.subs/src/distcc.c
--- distcc-2.18.3/src/distcc.c 2004-10-02 02:47:07.000000000 +0200
+++ distcc-2.18.3.subs/src/distcc.c 2006-02-20 13:11:49.000000000 +0100
@@ -136,7 +136,6 @@
}
-
/**
* distcc client entry point.
*
diff -ur distcc-2.18.3/src/remote.c distcc-2.18.3.subs/src/remote.c
--- distcc-2.18.3/src/remote.c 2004-10-24 07:05:49.000000000 +0200
+++ distcc-2.18.3.subs/src/remote.c 2006-02-20 13:44:02.000000000 +0100
@@ -33,6 +33,7 @@
#include <string.h>
#include <fcntl.h>
#include <errno.h>
+#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -115,6 +116,44 @@
return 0;
}
+static int isidchar (int c)
+{
+ return isalnum (c) || c == '_' || c == '-';
+}
+
+/*
+ * On a remote host of different architecture, we might want to
+ * execute TARGET-gcc iso. gcc.
+ * this is controlled with DISTCC_SUBSTITUTE_<upcase compiler name>
+ */
+static char *
+dcc_substitute_compiler_name (char *name)
+{
+ const char *generic = "DISTCC_SUBSTITUTE_" ;
+ size_t n = strlen (generic);
+ char *key = malloc (strlen (name) + n + 1);
+ char *p = key;
+ char *q = name;
+
+ if (!key) {
+ rs_log_crit("allocation failed!");
+ return NULL;
+ }
+
+ strncpy (key, generic, n);
+ for (p = key + n, q = name; *q; q++, p++) {
+ *p = toupper (*q);
+ if (!isidchar(*p))
+ *p = 'X';
+ }
+ *p = 0;
+
+ if (getenv (key))
+ return strdup (getenv (key));
+
+ return name;
+}
+
/* Send a request across to the already-open server.
*
@@ -187,6 +226,8 @@
if (gettimeofday(&before, NULL))
rs_log_warning("gettimeofday failed");
+ argv[0] = dcc_substitute_compiler_name (argv[0]);
+
dcc_note_execution(host, argv);
dcc_note_state(DCC_PHASE_CONNECT, input_fname, host->hostname);
More information about the distcc
mailing list