Browse Source

[util] config-local.h to avoid accidental commits

During development it is often handy to change the config.h options from
their defaults, for example to enable debugging features.

To prevent accidental commits of debugging config.h changes, mdc
suggested having a config-local.h that is excluded from source control.
This file acts as a temporary config.h and can override any of the
defaults.

This commit is an attempt to implement the config-local.h feature.

The config.h file now has the following as its last line:
/* @TRYSOURCE config-local.h */

The @TRYSOURCE directive causes config-local.h to be included at that
point in the file.  If config-local.h does not exist, no error will be
printed and parsing will continue as normal.  Therefore, mkconfig.pl is
"trying" to "source" config-local.h.
tags/v0.9.4
Stefan Hajnoczi 16 years ago
parent
commit
f866b17998
4 changed files with 32 additions and 12 deletions
  1. 1
    0
      src/.gitignore
  2. 2
    2
      src/Makefile.housekeeping
  3. 2
    0
      src/config.h
  4. 27
    10
      src/util/mkconfig.pl

+ 1
- 0
src/.gitignore View File

2
 .echocheck
2
 .echocheck
3
 TAGS*
3
 TAGS*
4
 bin*
4
 bin*
5
+config-local.h

+ 2
- 2
src/Makefile.housekeeping View File

121
 CFLAGS	+= -include compiler.h
121
 CFLAGS	+= -include compiler.h
122
 
122
 
123
 # config/%.h files are generated from config.h using mkconfig.pl
123
 # config/%.h files are generated from config.h using mkconfig.pl
124
-config/%.h : config.h
125
-	$(MKCONFIG) $<
124
+config/%.h : config*.h
125
+	$(MKCONFIG) config.h
126
 CLEANUP	+= config/*.h
126
 CLEANUP	+= config/*.h
127
 
127
 
128
 # SRCDIRS lists all directories containing source files.
128
 # SRCDIRS lists all directories containing source files.

+ 2
- 0
src/config.h View File

166
 #undef	NULL_TRAP		/* Attempt to catch NULL function calls */
166
 #undef	NULL_TRAP		/* Attempt to catch NULL function calls */
167
 
167
 
168
 /* @END general.h */
168
 /* @END general.h */
169
+
170
+/* @TRYSOURCE config-local.h */

+ 27
- 10
src/util/mkconfig.pl View File

7
 
7
 
8
 my $cfgdir = "config";
8
 my $cfgdir = "config";
9
 my $config_h = shift || "config.h";
9
 my $config_h = shift || "config.h";
10
+my @input_files;
10
 
11
 
11
 # Read in a whole file
12
 # Read in a whole file
12
 #
13
 #
110
   return "\n#endif /* $guard */\n";
111
   return "\n#endif /* $guard */\n";
111
 } 
112
 } 
112
 
113
 
113
-# Get the new configuration by splitting config.h file using the
114
-# @BEGIN/@END tags
114
+# Parse one config.h file into an existing configuration
115
 #
115
 #
116
-sub new_config {
116
+sub parse_config {
117
   my $file = shift;
117
   my $file = shift;
118
-
119
-  my $cfg = {};
118
+  my $cfg = shift;
120
   my $cursor = "";
119
   my $cursor = "";
121
 
120
 
121
+  push ( @input_files, $file );
122
+
122
   open my $fh, "<$file" or die "Could not open $file: $!\n";
123
   open my $fh, "<$file" or die "Could not open $file: $!\n";
123
   while ( <$fh> ) {
124
   while ( <$fh> ) {
124
     if ( ( my $newcursor, my $suffix ) = /\@BEGIN\s+(\w+\.h)(.*)$/ ) {
125
     if ( ( my $newcursor, my $suffix ) = /\@BEGIN\s+(\w+\.h)(.*)$/ ) {
133
 	  ." at $file line $.\n" unless $cursor eq $oldcursor;
134
 	  ." at $file line $.\n" unless $cursor eq $oldcursor;
134
       $cfg->{$cursor} .= $prefix."*/\n";
135
       $cfg->{$cursor} .= $prefix."*/\n";
135
       $cursor = "";
136
       $cursor = "";
137
+    } elsif ( ( my $newfile ) = /\@TRYSOURCE\s+([\w\-]+\.h)/ ) {
138
+      die "Missing \"\@END $cursor\" before \"\@TRYSOURCE $newfile\""
139
+	  ." at $file line $.\n" if $cursor;
140
+      parse_config ( $newfile, $cfg ) if -e $newfile;
136
     } else {
141
     } else {
137
       $cfg->{$cursor} .= $_ if $cursor;
142
       $cfg->{$cursor} .= $_ if $cursor;
138
     }
143
     }
139
   }
144
   }
140
   close $fh;
145
   close $fh;
141
   die "Missing \"\@END $cursor\" in $file\n" if $cursor;
146
   die "Missing \"\@END $cursor\" in $file\n" if $cursor;
147
+}
142
 
148
 
143
-  foreach $cursor ( keys %$cfg ) {
149
+# Get the new configuration by splitting config.h file using the
150
+# @BEGIN/@END tags
151
+#
152
+sub new_config {
153
+  my $file = shift;
154
+  my $cfg = {};
155
+
156
+  parse_config ( $file, $cfg );
157
+
158
+  foreach my $cursor ( keys %$cfg ) {
144
     $cfg->{$cursor} .= postamble ( $cursor );
159
     $cfg->{$cursor} .= postamble ( $cursor );
145
   }
160
   }
146
 
161
 
180
 }
195
 }
181
 
196
 
182
 # If we now have fragments that are older than config.h, set the
197
 # If we now have fragments that are older than config.h, set the
183
-# timestamp on config.h to match the oldest fragment, to prevent make
184
-# from always attempting to rebuild the fragments.
198
+# timestamp on each input file to match the oldest fragment, to
199
+# prevent make from always attempting to rebuild the fragments.
185
 #
200
 #
186
-if ( $oldest < file_mtime ( $config_h ) ) {
187
-  utime time(), $oldest, $config_h or die "Could not touch $config_h: $!\n";
201
+foreach my $file ( @input_files ) {
202
+  if ( $oldest < file_mtime ( $file ) ) {
203
+    utime time(), $oldest, $file or die "Could not touch $file: $!\n";
204
+  }
188
 }
205
 }

Loading…
Cancel
Save