Pārlūkot izejas kodu

[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 gadus atpakaļ
vecāks
revīzija
f866b17998
4 mainītis faili ar 32 papildinājumiem un 12 dzēšanām
  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 Parādīt failu

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

+ 2
- 2
src/Makefile.housekeeping Parādīt failu

@@ -121,8 +121,8 @@ CFLAGS	+= $(SP_FLAGS)
121 121
 CFLAGS	+= -include compiler.h
122 122
 
123 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 126
 CLEANUP	+= config/*.h
127 127
 
128 128
 # SRCDIRS lists all directories containing source files.

+ 2
- 0
src/config.h Parādīt failu

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

+ 27
- 10
src/util/mkconfig.pl Parādīt failu

@@ -7,6 +7,7 @@ use warnings;
7 7
 
8 8
 my $cfgdir = "config";
9 9
 my $config_h = shift || "config.h";
10
+my @input_files;
10 11
 
11 12
 # Read in a whole file
12 13
 #
@@ -110,15 +111,15 @@ sub postamble {
110 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 117
   my $file = shift;
118
-
119
-  my $cfg = {};
118
+  my $cfg = shift;
120 119
   my $cursor = "";
121 120
 
121
+  push ( @input_files, $file );
122
+
122 123
   open my $fh, "<$file" or die "Could not open $file: $!\n";
123 124
   while ( <$fh> ) {
124 125
     if ( ( my $newcursor, my $suffix ) = /\@BEGIN\s+(\w+\.h)(.*)$/ ) {
@@ -133,14 +134,28 @@ sub new_config {
133 134
 	  ." at $file line $.\n" unless $cursor eq $oldcursor;
134 135
       $cfg->{$cursor} .= $prefix."*/\n";
135 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 141
     } else {
137 142
       $cfg->{$cursor} .= $_ if $cursor;
138 143
     }
139 144
   }
140 145
   close $fh;
141 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 159
     $cfg->{$cursor} .= postamble ( $cursor );
145 160
   }
146 161
 
@@ -180,9 +195,11 @@ foreach my $file ( keys %$new ) {
180 195
 }
181 196
 
182 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
 }

Notiek ielāde…
Atcelt
Saglabāt