]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
comerr: compile_et -emit option for parallel make
authorMichael Meffie <mmeffie@sinenomine.net>
Wed, 1 Aug 2012 21:26:33 +0000 (17:26 -0400)
committerStephan Wiesand <stephan.wiesand@desy.de>
Thu, 7 Aug 2014 10:50:26 +0000 (06:50 -0400)
Add the -emit option to the compile_et command to support parallel make.

The -emit option allows make to generate the header and the source files
independently, instead of building two files at the some time.  This
avoids the issue where one command creates two separate files, which is
difficult to handle correctly for parallel makes.

Reviewed-on: http://gerrit.openafs.org/7921
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Marc Dionne <marc.c.dionne@gmail.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
(cherry picked from commit 9df43aacab0f311c15837b230761a11750f8b9cb)

Change-Id: Id560fcec356a4b36c0e311440f74a97a670c07d1
Reviewed-on: http://gerrit.openafs.org/11227
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
doc/man-pages/pod1/afs_compile_et.pod
src/comerr/compile_et.c
src/comerr/error_table.y
src/comerr/error_table_nt.c

index eaa1b49076069810bcce1c5e961284e7802a4aef..e60593d0b55a99c672c9228d317e0307274f0eb2 100644 (file)
@@ -9,7 +9,8 @@ afs_compile_et - Produce error text tables for compilation
 
 B<afs_compile_et> [B<-debug>] S<<< [B<-language> <I<lang>>] >>>
     S<<< [B<-prefix> <I<prefix>>] >>> S<<< [B<-v> <I<version>>] >>>
-    S<<< [B<-h> <I<include>>] >>> <I<error_table>>
+    S<<< [B<-h> <I<include>>] >>> <S<<< [B<-emit> <I<output>>] >>>
+    I<error_table>>
 
 =for html
 </div>
@@ -26,6 +27,13 @@ The error table specification should exist in the current working
 directory or in the directory specified with B<-prefix> and should be
 named F<error_table.et>.
 
+By default, B<afs_compile_et> generates two files in one invocation. This is
+problematic for parallel build systems. The B<-emit> option may be used to
+generate the output files independently with two separate invocations of
+B<afs_compile_et> for a given error table. This allows parallel build systems
+to generate the source and header files, and the targets which depend on the
+generated source and headers files, in parallel.
+
 =head1 CAUTIONS
 
 This command is used internally within the build process for OpenAFS.
@@ -79,6 +87,13 @@ The B<-h> option does not affect the source file generated by B<afs_compile_et>.
 Specified the type of output file: valid values are 1 (the default, for C
 files) or 2, for B<.msf> file generation.
 
+=item B<-emit> <I<output>>
+
+Specifies which program file to generate; the header file or the source file.
+Specify B<-emit header> (or B<-emit h>) to generate the F<.h> header file.
+Specify B<-emit source> (or B<-emit c>) to generate the F<.c> (or F<.msf>)
+source file.
+
 =back
 
 =head1 EXAMPLES
@@ -92,6 +107,16 @@ The following command generates K&R style files instead:
 
    % afs_compile_et -p path/to/src/ptserver -lang 'k&r-c' pterror
 
+The following command generates the F<pterror.h> file, but not the F<pterror.c>
+file.
+
+   % afs_compile_et -p path/to/src/ptserver -emit header pterror
+
+The following command generates the F<pterror.c> file, but not the F<pterror.h>
+file.
+
+   % afs_compile_et -p path/to/src/ptserver -emit source pterror
+
 =head1 SEE ALSO
 
 L<translate_et(1)>
index de877cda7c024fe4af5e8310110b3b6698e32255..0ef161877d04b22eec9b94dcc13f3638856f3636 100644 (file)
@@ -34,9 +34,11 @@ extern char *current_token;
 extern int table_number, current;
 char buffer[BUFSIZ];
 char *table_name = (char *)NULL;
-FILE *hfile, *cfile, *msfile;
+FILE *hfile = NULL, *cfile = NULL, *msfile = NULL;
 int version = 1;
 int use_msf = 0;
+int emit_source = 0;
+int emit_header = 0;
 
 /* lex stuff */
 extern FILE *yyin;
@@ -85,6 +87,12 @@ static const char *const prefix_args[] = {
     0,
 };
 
+static const char *const emit_args[] = {
+    "e",
+    "emit",
+    0,
+};
+
 static const char *const language_names[] = {
     "C",
     "K&R C",
@@ -129,7 +137,7 @@ static void
 usage(void)
 {
     fprintf(stderr,
-           "%s: usage: %s ERROR_TABLE [-debug] [-language LANG] [-h INCLUDE] [-p prefix] [-v version]\n",
+           "%s: usage: %s ERROR_TABLE [-debug] [-language LANG] [-h INCLUDE] [-p PREFIX] [-v VERSION] [-emit source|header]\n",
            whoami, whoami);
     exit(1);
 }
@@ -152,6 +160,7 @@ main(int argc, char **argv)
     int got_language = 0;
     char *got_include = 0;
     char *got_prefix = ".";
+    int got_emit = 0;
     char lcname[6];
 
 #ifdef AFS_AIX32_ENV
@@ -244,6 +253,24 @@ main(int argc, char **argv)
                }
                if (version == 2)
                    use_msf = 1;
+           } else if (check_arg(emit_args, arg)) {
+               arg = *++argv;
+               argc--;
+               got_emit = 1;
+               if (!strcasecmp(arg, "source")) {
+                   emit_source = 1;
+               } else if (!strcasecmp(arg, "c")) {
+                   emit_source = 1;
+               } else if (!strcasecmp(arg, "header")) {
+                   emit_header = 1;
+               } else if (!strcasecmp(arg, "h")) {
+                   emit_header = 1;
+               } else {
+                   fprintf(stderr, "%s: unknown emit argument - `%s'\n",
+                           whoami, arg);
+                   usage();
+                   exit(1);
+               }
            } else {
                fprintf(stderr, "%s: unknown control argument -`%s'\n",
                        whoami, arg);
@@ -261,6 +288,9 @@ main(int argc, char **argv)
        exit(1);
     }
 
+    if (!got_emit) {
+       emit_source = emit_header = 1; /* generate both by default */
+    }
 
     p = strrchr(filename, '/');
     if (p == (char *)NULL)
@@ -277,15 +307,19 @@ main(int argc, char **argv)
            *p = 0;
     }
 
-    if (use_msf) {
-       sprintf(msf_file, "%s.msf", ename);
-    } else {
-       sprintf(c_file, "%s.c", ename);
+    if (emit_source) {
+       if (use_msf) {
+           sprintf(msf_file, "%s.msf", ename);
+       } else {
+           sprintf(c_file, "%s.c", ename);
+       }
     }
-    if (got_include) {
-       sprintf(h_file, "%s.h", got_include);
-    } else {
-       sprintf(h_file, "%s.h", ename);
+    if (emit_header) {
+       if (got_include) {
+           sprintf(h_file, "%s.h", got_include);
+       } else {
+           sprintf(h_file, "%s.h", ename);
+       }
     }
     p = strrchr(filename, '.');
     if (p == NULL) {
@@ -307,13 +341,15 @@ main(int argc, char **argv)
        yyout = stdout;
     }
 
-    hfile = fopen(h_file, "w");
-    if (hfile == (FILE *) NULL) {
-       perror(h_file);
-       exit(1);
+    if (emit_header) {
+       hfile = fopen(h_file, "w");
+       if (hfile == NULL) {
+           perror(h_file);
+           exit(1);
+       }
+       fprintf(hfile, warning, h_file);
     }
-    fprintf(hfile, warning, h_file);
-    if (got_include) {
+    if (emit_header && got_include) {
        char buffer[BUFSIZ];
        char prolog_h_file[MAXPATHLEN];
        FILE *prolog_hfile;
@@ -347,14 +383,14 @@ main(int argc, char **argv)
        }
     }
 
-    if (use_msf) {
+    if (emit_source && use_msf) {
        msfile = fopen(msf_file, "w");
        if (msfile == (FILE *) NULL) {
            perror(msf_file);
            exit(1);
        }
        fprintf(msfile, msf_warning, msf_file);
-    } else {
+    } else if (emit_source) {
        cfile = fopen(c_file, "w");
        if (cfile == (FILE *) NULL) {
            perror(c_file);
@@ -378,46 +414,52 @@ main(int argc, char **argv)
     fclose(yyin);              /* bye bye input file */
 
     if (!use_msf) {
-       fputs("    0\n};\n\n", cfile);
-       fprintf(cfile,
-               "static const struct error_table et = { text, %ldL, %d };\n\n",
-               (long int)table_number, current);
-       fputs("static struct et_list etlink = { 0, &et};\n\n", cfile);
-       fprintf(cfile, "void initialize_%s_error_table(void) {\n",
-               table_name);
-       fputs("    afs_add_to_error_table(&etlink);\n", cfile);
-       fputs("}\n", cfile);
-       fclose(cfile);
-
-
-       fprintf(hfile, "extern void initialize_%s_error_table(void);\n",
-               table_name);
+       if (cfile) {
+           fputs("    0\n};\n\n", cfile);
+           fprintf(cfile,
+                   "static const struct error_table et = { text, %ldL, %d };\n\n",
+                   (long int)table_number, current);
+           fputs("static struct et_list etlink = { 0, &et};\n\n", cfile);
+           fprintf(cfile, "void initialize_%s_error_table(void) {\n",
+                   table_name);
+           fputs("    afs_add_to_error_table(&etlink);\n", cfile);
+           fputs("}\n", cfile);
+           fclose(cfile);
+       }
+       if (hfile) {
+           fprintf(hfile, "extern void initialize_%s_error_table(void);\n",
+                   table_name);
+       }
     } else {
-       fprintf(hfile, "#define initialize_%s_error_table(void)\n",
-               table_name);
+       if (hfile) {
+           fprintf(hfile, "#define initialize_%s_error_table(void)\n",
+                   table_name);
+       }
     }
 
-    fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", table_name,
-           (long int)table_number);
-    /* compatibility... */
-    fprintf(hfile, "\n/* for compatibility with older versions... */\n");
-    fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
-           table_name, table_name);
-    fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", table_name,
-           table_name);
-    fprintf(hfile, "\n/* for compatibility with other users... */\n");
-    lcstring(lcname, table_name, sizeof(lcname));
-    fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", lcname,
-           (long int)table_number);
-    fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
-           lcname, table_name);
-    fprintf(hfile,
-           "#define initialize_%s_error_table initialize_%s_error_table\n",
-           lcname, table_name);
-    fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", lcname,
-           lcname);
-    fclose(hfile);             /* bye bye include file */
-    if (use_msf)
+    if (hfile) {
+       fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", table_name,
+               (long int)table_number);
+       /* compatibility... */
+       fprintf(hfile, "\n/* for compatibility with older versions... */\n");
+       fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
+               table_name, table_name);
+       fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n",
+               table_name, table_name);
+       fprintf(hfile, "\n/* for compatibility with other users... */\n");
+       lcstring(lcname, table_name, sizeof(lcname));
+       fprintf(hfile, "#define ERROR_TABLE_BASE_%s (%ldL)\n", lcname,
+               (long int)table_number);
+       fprintf(hfile, "#define init_%s_err_tbl initialize_%s_error_table\n",
+               lcname, table_name);
+       fprintf(hfile,
+               "#define initialize_%s_error_table initialize_%s_error_table\n",
+               lcname, table_name);
+       fprintf(hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", lcname,
+               lcname);
+       fclose(hfile);          /* bye bye include file */
+    }
+    if (msfile)
        fclose(msfile);
     return 0;
 }
index cdb2702f397043587410069cbbf8116b770c0c21..62331c2b34311b0943fa0fa18699b93dd7acd8cd 100644 (file)
@@ -192,7 +192,7 @@ void add_ec(const char *name, const char *description)
 #else
                 fprintf(msfile, "%d %s\n", current, description);
 #endif /* !sun */
-        } else {
+        } else if (cfile){
            fprintf(cfile, "\t\"%s\",\n", description);
        }
        if (error_codes == (char **)NULL) {
@@ -215,8 +215,8 @@ void add_ec_val(const char *name, const char *val, const char *description)
        }
       
        while (ncurrent > current) {
-            if (!msfile)
-                fputs("\t(char *)NULL,\n", cfile);
+            if (cfile)
+                fputs("\tNULL,\n", cfile);
             current++;
         }
         if (msfile) {
@@ -226,7 +226,7 @@ void add_ec_val(const char *name, const char *val, const char *description)
 #else
                 fprintf(msfile, "%d %s\n", current, description);
 #endif /* ! sun */
-        } else {       
+        } else if (cfile) {
            fprintf(cfile, "\t\"%s\",\n", description);
        }
        if (error_codes == (char **)NULL) {
@@ -242,6 +242,8 @@ void add_ec_val(const char *name, const char *val, const char *description)
 void put_ecs(void)
 {
        int i;
+       if (!hfile)
+           return;
        for (i = 0; i < current; i++) {
             if (error_codes[i] != (char *)NULL)
                  fprintf(hfile, "#define %-40s (%ldL)\n",
@@ -284,7 +286,7 @@ int char_to_num(char c)
 
 void set_table_num(char *string)
 {
-        if (msfile) {
+        if (use_msf) {
            set_table_1num(string);
            return;
        }
@@ -321,7 +323,7 @@ void set_table_fun(char *astring)
             exit(1);
         }
     }
-    if (msfile) 
+    if (use_msf)
        table_number += (atoi(astring)) << 28;
 }
 
index b1ee9cdfe2059128450dcc397cbff7aa2f8d7a93..f7e36eadfb943fa0720c6fd8f4614e8e5b524e73 100755 (executable)
@@ -1022,7 +1022,7 @@ add_ec(const char *name, const char *description)
 #else
            fprintf(msfile, "%d %s\n", current, description);
 #endif /* !sun */
-    } else {
+    } else if (cfile) {
        fprintf(cfile, "\t\"%s\",\n", description);
     }
     if (error_codes == (char **)NULL) {
@@ -1045,8 +1045,8 @@ add_ec_val(const char *name, const char *val, const char *description)
     }
 
     while (ncurrent > current) {
-       if (!msfile)
-           fputs("\t(char *)NULL,\n", cfile);
+       if (cfile)
+           fputs("\tNULL,\n", cfile);
        current++;
     }
     if (msfile) {
@@ -1056,7 +1056,7 @@ add_ec_val(const char *name, const char *val, const char *description)
 #else
            fprintf(msfile, "%d %s\n", current, description);
 #endif /* ! sun */
-    } else {
+    } else if (cfile) {
        fprintf(cfile, "\t\"%s\",\n", description);
     }
     if (error_codes == (char **)NULL) {
@@ -1073,6 +1073,8 @@ void
 put_ecs(void)
 {
     int i;
+    if (!hfile)
+        return;
     for (i = 0; i < current; i++) {
        if (error_codes[i] != (char *)NULL)
            fprintf(hfile, "#define %-40s (%ldL)\n", error_codes[i],
@@ -1112,7 +1114,7 @@ char_to_num(char c)
 void
 set_table_num(char *string)
 {
-    if (msfile) {
+    if (use_msf) {
        set_table_1num(string);
        return;
     }
@@ -1149,7 +1151,7 @@ set_table_fun(char *astring)
            exit(1);
        }
     }
-    if (msfile)
+    if (use_msf)
        table_number += (atoi(astring)) << 28;
 }