Commit a87dcba13f4501adc448d82c58fa1dfa7274046d

Authored by Jay Berkenbilt
1 parent f729a336

QPDFJob: generate declarations of trivial config methods

generate_auto_job
... ... @@ -94,6 +94,7 @@ class Main:
94 94 'init': 'libqpdf/qpdf/auto_job_init.hh',
95 95 'help': 'libqpdf/qpdf/auto_job_help.hh',
96 96 'schema': 'libqpdf/qpdf/auto_job_schema.hh',
  97 + # Others are added in top
97 98 }
98 99 SUMS = 'job.sums'
99 100  
... ... @@ -116,12 +117,24 @@ class Main:
116 117 return parser.parse_args(args)
117 118  
118 119 def top(self, options):
  120 + with open('job.yml', 'r') as f:
  121 + data = yaml.safe_load(f.read())
  122 + self.config_decls = {}
  123 + for o in data['options']:
  124 + table = o['table']
  125 + config = o.get('config', None)
  126 + if config is not None:
  127 + self.DESTS[config] = f'include/qpdf/auto_job_{config}.hh'
  128 + self.config_decls[config] = []
  129 + if table != 'main':
  130 + self.config_decls[config].append('QPDF_DLL Config& end();')
  131 +
119 132 if self.check_hashes():
120 133 exit(0)
121 134 elif options.check:
122 135 exit(f'{whoami}: auto job inputs have changed')
123 136 elif options.generate:
124   - self.generate()
  137 + self.generate(data)
125 138 else:
126 139 exit(f'{whoami} unknown mode')
127 140  
... ... @@ -289,10 +302,8 @@ class Main:
289 302 'Options without help: ' +
290 303 ', '.join(self.options_without_help))
291 304  
292   - def generate(self):
  305 + def generate(self, data):
293 306 warn(f'{whoami}: regenerating auto job files')
294   - with open('job.yml', 'r') as f:
295   - data = yaml.safe_load(f.read())
296 307 self.validate(data)
297 308 # Add the built-in help options to tables that we populate as
298 309 # we read job.yml since we won't encounter these in job.yml
... ... @@ -318,16 +329,21 @@ class Main:
318 329 print('static constexpr char const* JOB_SCHEMA_DATA = R"(' +
319 330 json.dumps(self.schema, indent=2, separators=(',', ': ')) +
320 331 ')";', file=f)
  332 + for k, v in self.config_decls.items():
  333 + with write_file(self.DESTS[k]) as f:
  334 + print(BANNER, file=f)
  335 + for i in v:
  336 + print(i, file=f)
321 337  
322 338 # Update hashes last to ensure that this will be rerun in the
323 339 # event of a failure.
324 340 self.update_hashes()
325 341 # DON'T ADD CODE TO generate AFTER update_hashes
326 342  
327   - def handle_trivial(self, i, identifier, cfg, kind, v):
328   - # QXXXQ could potentially generate declarations for config
329   - # methods separately by config object
  343 + def handle_trivial(self, i, identifier, cfg, prefix, kind, v):
  344 + decl_arg = 1
330 345 if kind == 'bare':
  346 + decl_arg = 0
331 347 self.init.append(f'this->ap.addBare("{i}", '
332 348 f'[this](){{{cfg}->{identifier}();}});')
333 349 elif kind == 'optional_parameter':
... ... @@ -345,6 +361,14 @@ class Main:
345 361 self.init.append(f'this->ap.addChoices("{i}", '
346 362 f'[this](char *x){{{cfg}->{identifier}(x);}}'
347 363 f', false, {v}_choices);')
  364 + # Generate declarations for config methods separately by
  365 + # config object.
  366 + config_class = prefix + 'Config'
  367 + arg = ''
  368 + if decl_arg:
  369 + arg = 'char const* parameter'
  370 + self.config_decls[cfg].append(
  371 + f'QPDF_DLL {config_class}& {identifier}({arg});')
348 372  
349 373 def handle_flag(self, i, identifier, kind, v):
350 374 if kind == 'bare':
... ... @@ -417,7 +441,9 @@ class Main:
417 441 for o in data['options']:
418 442 table = o['table']
419 443 config = o.get('config', None)
420   - table_prefix = o.get('prefix', table)
  444 + table_prefix = o.get('prefix', '')
  445 + arg_prefix = 'arg' + table_prefix
  446 + jdata_prefix = table_prefix or table
421 447 if table == 'main':
422 448 self.init.append('this->ap.selectMainOptionTable();')
423 449 elif table == 'help':
... ... @@ -426,12 +452,10 @@ class Main:
426 452 identifier = self.to_identifier(table, 'argEnd', False)
427 453 self.init.append(f'this->ap.registerOptionTable("{table}",'
428 454 f' b(&ArgParser::{identifier}));')
429   - prefix = 'arg' + o.get('prefix', '')
430 455 if o.get('positional', False):
431   - identifier = self.to_identifier(i, prefix, False)
432   - self.decls.append(f'void {prefix}Positional(char*);')
  456 + self.decls.append(f'void {arg_prefix}Positional(char*);')
433 457 self.init.append('this->ap.addPositional('
434   - f'p(&ArgParser::{prefix}Positional));')
  458 + f'p(&ArgParser::{arg_prefix}Positional));')
435 459 flags = {}
436 460  
437 461 for i in o.get('bare', []):
... ... @@ -448,21 +472,22 @@ class Main:
448 472  
449 473 for i, [kind, v] in flags.items():
450 474 self.options_without_help.add(f'--{i}')
451   - add_jdata(i, table_prefix)
  475 + add_jdata(i, table_prefix or table)
452 476 # QXXXQ complex, not_yet
453 477 if i in complex or i in not_yet or config is None:
454   - identifier = self.to_identifier(i, prefix, False)
  478 + identifier = self.to_identifier(i, arg_prefix, False)
455 479 self.handle_flag(i, identifier, kind, v)
456 480 else:
457 481 identifier = self.to_identifier(i, '', False)
458   - self.handle_trivial(i, identifier, config, kind, v)
  482 + self.handle_trivial(
  483 + i, identifier, config, table_prefix, kind, v)
459 484  
460 485 if table not in ('main', 'help'):
461 486 identifier = self.to_identifier(table, 'argEnd', False)
462 487 self.decls.append(f'void {identifier}();')
463 488 for o in data['options']:
464 489 table = o['table']
465   - table_prefix = o.get('prefix', table)
  490 + jdata_prefix = o.get('prefix', table)
466 491 if 'from_table' not in o:
467 492 continue
468 493 if table == 'main':
... ... @@ -476,7 +501,7 @@ class Main:
476 501 for j in ft['options']:
477 502 self.init.append('this->ap.copyFromOtherTable'
478 503 f'("{j}", "{other_table}");')
479   - add_jdata(j, table_prefix)
  504 + add_jdata(j, jdata_prefix or table)
480 505  
481 506 def generate_schema(self, data):
482 507 # XXX check data['json'] against what we know from jdata.
... ...
include/qpdf/QPDFJob.hh
... ... @@ -116,11 +116,8 @@ class QPDFJob
116 116 friend class Config;
117 117 public:
118 118 QPDF_DLL CopyAttConfig& filename(char const* parameter);
119   - // QXXXQ auto
120   - QPDF_DLL CopyAttConfig& prefix(char const* parameter);
121   - QPDF_DLL CopyAttConfig& password(char const* parameter);
122   - QPDF_DLL Config& end();
123   - // /QXXXQ
  119 +
  120 +# include <qpdf/auto_job_c_copy_att.hh>
124 121  
125 122 private:
126 123 CopyAttConfig(Config&);
... ... @@ -138,74 +135,7 @@ class QPDFJob
138 135 QPDF_DLL
139 136 std::shared_ptr<CopyAttConfig> copyAttachmentsFrom();
140 137  
141   - // QXXXQ could potentially generate these declarations
142   - QPDF_DLL Config& allowWeakCrypto();
143   - QPDF_DLL Config& check();
144   - QPDF_DLL Config& checkLinearization();
145   - QPDF_DLL Config& coalesceContents();
146   - QPDF_DLL Config& collate(char const* parameter);
147   - QPDF_DLL Config& compressStreams(char const* parameter);
148   - QPDF_DLL Config& compressionLevel(char const* parameter);
149   - QPDF_DLL Config& copyEncryption(char const* parameter);
150   - QPDF_DLL Config& decrypt();
151   - QPDF_DLL Config& deterministicId();
152   - QPDF_DLL Config& empty();
153   - QPDF_DLL Config& encryptionFilePassword(char const* parameter);
154   - QPDF_DLL Config& externalizeInlineImages();
155   - QPDF_DLL Config& filteredStreamData();
156   - QPDF_DLL Config& flattenAnnotations(char const* parameter);
157   - QPDF_DLL Config& flattenRotation();
158   - QPDF_DLL Config& forceVersion(char const* parameter);
159   - QPDF_DLL Config& generateAppearances();
160   - QPDF_DLL Config& ignoreXrefStreams();
161   - QPDF_DLL Config& iiMinBytes(char const* parameter);
162   - QPDF_DLL Config& isEncrypted();
163   - QPDF_DLL Config& json();
164   - QPDF_DLL Config& jsonKey(char const* parameter);
165   - QPDF_DLL Config& jsonObject(char const* parameter);
166   - QPDF_DLL Config& keepFilesOpen(char const* parameter);
167   - QPDF_DLL Config& keepFilesOpenThreshold(char const* parameter);
168   - QPDF_DLL Config& keepInlineImages();
169   - QPDF_DLL Config& linearize();
170   - QPDF_DLL Config& linearizePass1(char const* parameter);
171   - QPDF_DLL Config& listAttachments();
172   - QPDF_DLL Config& minVersion(char const* parameter);
173   - QPDF_DLL Config& newlineBeforeEndstream();
174   - QPDF_DLL Config& noOriginalObjectIds();
175   - QPDF_DLL Config& noWarn();
176   - QPDF_DLL Config& normalizeContent(char const* parameter);
177   - QPDF_DLL Config& oiMinArea(char const* parameter);
178   - QPDF_DLL Config& oiMinHeight(char const* parameter);
179   - QPDF_DLL Config& oiMinWidth(char const* parameter);
180   - QPDF_DLL Config& optimizeImages();
181   - QPDF_DLL Config& password(char const* parameter);
182   - QPDF_DLL Config& passwordIsHexKey();
183   - QPDF_DLL Config& preserveUnreferenced();
184   - QPDF_DLL Config& preserveUnreferencedResources();
185   - QPDF_DLL Config& progress();
186   - QPDF_DLL Config& qdf();
187   - QPDF_DLL Config& rawStreamData();
188   - QPDF_DLL Config& recompressFlate();
189   - QPDF_DLL Config& removeAttachment(char const* parameter);
190   - QPDF_DLL Config& removePageLabels();
191   - QPDF_DLL Config& replaceInput();
192   - QPDF_DLL Config& requiresPassword();
193   - QPDF_DLL Config& showAttachment(char const* parameter);
194   - QPDF_DLL Config& showEncryption();
195   - QPDF_DLL Config& showEncryptionKey();
196   - QPDF_DLL Config& showLinearization();
197   - QPDF_DLL Config& showNpages();
198   - QPDF_DLL Config& showPages();
199   - QPDF_DLL Config& showXref();
200   - QPDF_DLL Config& splitPages(char const* parameter);
201   - QPDF_DLL Config& staticAesIv();
202   - QPDF_DLL Config& staticId();
203   - QPDF_DLL Config& suppressPasswordRecovery();
204   - QPDF_DLL Config& suppressRecovery();
205   - QPDF_DLL Config& verbose();
206   - QPDF_DLL Config& warningExit0();
207   - QPDF_DLL Config& withImages();
208   - // /QXXXQ
  138 +# include <qpdf/auto_job_c_main.hh>
209 139  
210 140 private:
211 141 Config() = delete;
... ...
include/qpdf/auto_job_c_copy_att.hh 0 → 100644
  1 +//
  2 +// This file is automatically generated by generate_auto_job.
  3 +// Edits will be automatically overwritten if the build is
  4 +// run in maintainer mode.
  5 +//
  6 +QPDF_DLL Config& end();
  7 +QPDF_DLL CopyAttConfig& prefix(char const* parameter);
  8 +QPDF_DLL CopyAttConfig& password(char const* parameter);
... ...
include/qpdf/auto_job_c_main.hh 0 → 100644
  1 +//
  2 +// This file is automatically generated by generate_auto_job.
  3 +// Edits will be automatically overwritten if the build is
  4 +// run in maintainer mode.
  5 +//
  6 +QPDF_DLL Config& allowWeakCrypto();
  7 +QPDF_DLL Config& check();
  8 +QPDF_DLL Config& checkLinearization();
  9 +QPDF_DLL Config& coalesceContents();
  10 +QPDF_DLL Config& decrypt();
  11 +QPDF_DLL Config& deterministicId();
  12 +QPDF_DLL Config& empty();
  13 +QPDF_DLL Config& externalizeInlineImages();
  14 +QPDF_DLL Config& filteredStreamData();
  15 +QPDF_DLL Config& flattenRotation();
  16 +QPDF_DLL Config& generateAppearances();
  17 +QPDF_DLL Config& ignoreXrefStreams();
  18 +QPDF_DLL Config& isEncrypted();
  19 +QPDF_DLL Config& json();
  20 +QPDF_DLL Config& keepInlineImages();
  21 +QPDF_DLL Config& linearize();
  22 +QPDF_DLL Config& listAttachments();
  23 +QPDF_DLL Config& newlineBeforeEndstream();
  24 +QPDF_DLL Config& noOriginalObjectIds();
  25 +QPDF_DLL Config& noWarn();
  26 +QPDF_DLL Config& optimizeImages();
  27 +QPDF_DLL Config& passwordIsHexKey();
  28 +QPDF_DLL Config& preserveUnreferenced();
  29 +QPDF_DLL Config& preserveUnreferencedResources();
  30 +QPDF_DLL Config& progress();
  31 +QPDF_DLL Config& qdf();
  32 +QPDF_DLL Config& rawStreamData();
  33 +QPDF_DLL Config& recompressFlate();
  34 +QPDF_DLL Config& removePageLabels();
  35 +QPDF_DLL Config& replaceInput();
  36 +QPDF_DLL Config& requiresPassword();
  37 +QPDF_DLL Config& showEncryption();
  38 +QPDF_DLL Config& showEncryptionKey();
  39 +QPDF_DLL Config& showLinearization();
  40 +QPDF_DLL Config& showNpages();
  41 +QPDF_DLL Config& showPages();
  42 +QPDF_DLL Config& showXref();
  43 +QPDF_DLL Config& staticAesIv();
  44 +QPDF_DLL Config& staticId();
  45 +QPDF_DLL Config& suppressPasswordRecovery();
  46 +QPDF_DLL Config& suppressRecovery();
  47 +QPDF_DLL Config& verbose();
  48 +QPDF_DLL Config& warningExit0();
  49 +QPDF_DLL Config& withImages();
  50 +QPDF_DLL Config& collate(char const* parameter);
  51 +QPDF_DLL Config& splitPages(char const* parameter);
  52 +QPDF_DLL Config& compressionLevel(char const* parameter);
  53 +QPDF_DLL Config& copyEncryption(char const* parameter);
  54 +QPDF_DLL Config& encryptionFilePassword(char const* parameter);
  55 +QPDF_DLL Config& forceVersion(char const* parameter);
  56 +QPDF_DLL Config& iiMinBytes(char const* parameter);
  57 +QPDF_DLL Config& jsonObject(char const* parameter);
  58 +QPDF_DLL Config& keepFilesOpenThreshold(char const* parameter);
  59 +QPDF_DLL Config& linearizePass1(char const* parameter);
  60 +QPDF_DLL Config& minVersion(char const* parameter);
  61 +QPDF_DLL Config& oiMinArea(char const* parameter);
  62 +QPDF_DLL Config& oiMinHeight(char const* parameter);
  63 +QPDF_DLL Config& oiMinWidth(char const* parameter);
  64 +QPDF_DLL Config& password(char const* parameter);
  65 +QPDF_DLL Config& removeAttachment(char const* parameter);
  66 +QPDF_DLL Config& showAttachment(char const* parameter);
  67 +QPDF_DLL Config& compressStreams(char const* parameter);
  68 +QPDF_DLL Config& flattenAnnotations(char const* parameter);
  69 +QPDF_DLL Config& jsonKey(char const* parameter);
  70 +QPDF_DLL Config& keepFilesOpen(char const* parameter);
  71 +QPDF_DLL Config& normalizeContent(char const* parameter);
... ...
job.sums
1 1 # Generated by generate_auto_job
2   -generate_auto_job e18ae51cee2838fe44c37237a344fb48abe7a6d3f9cfa745d2f1dbc9c294e7b7
  2 +generate_auto_job 36a09904317400caa4a2434f5b2acd59c20905a28479f45bba5e1fcfc654e697
  3 +include/qpdf/auto_job_c_copy_att.hh caffae3d1faf2cd92a07ba77da638cce31da3e074a047918834195c0f3ed508a
  4 +include/qpdf/auto_job_c_main.hh 5fdd9c85aa295a3caec467b9607fe82c874cd3aaeb7806b9d18074f7b96fd085
3 5 job.yml 55d272cca0657e1f96ca92f5253edb6c6e24e6ea19e37690446d2111adc13f91
4 6 libqpdf/qpdf/auto_job_decl.hh e9844137bf53345f2c6973378b314a2510ebce83ac8ceb378588cd6afdd87c06
5 7 libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
... ...