@@ -367,6 +367,12 @@ open Printf
367
367
// END BOILERPLATE
368
368
"
369
369
370
+ let StringBoilerPlateSignature =
371
+ " // BEGIN BOILERPLATE
372
+ /// If set to true, then all error messages will just return the filled 'holes' delimited by ',,,'s - this is for language-neutral testing (e.g. localization-invariant baselines).
373
+ static member SwallowResourceText: bool with get, set
374
+ // END BOILERPLATE"
375
+
370
376
let generateResxAndSource ( fileName : string ) =
371
377
try
372
378
let printMessage fmt = Printf.ksprintf this.Log.LogMessage fmt
@@ -383,6 +389,7 @@ open Printf
383
389
)
384
390
385
391
let outFileName = Path.Combine(_ outputPath, justFileName + " .fs" )
392
+ let outFileSignatureName = Path.Combine(_ outputPath, justFileName + " .fsi" )
386
393
let outXmlFileName = Path.Combine(_ outputPath, justFileName + " .resx" )
387
394
388
395
let condition1 = File.Exists( outFileName)
@@ -400,7 +407,7 @@ open Printf
400
407
if condition5 then
401
408
printMessage " Skipping generation of %s and %s from %s since up-to-date" outFileName outXmlFileName fileName
402
409
403
- Some( fileName, outFileName, outXmlFileName)
410
+ Some( fileName, outFileSignatureName , outFileName, outXmlFileName)
404
411
else
405
412
printMessage
406
413
" Generating %s and %s from %s , because condition %d is false, see FSharpEmbedResourceText.fs in the F# source"
@@ -464,12 +471,20 @@ open Printf
464
471
printMessage " Generating %s " outFileName
465
472
use outStream = File.Create outFileName
466
473
use out = new StreamWriter( outStream)
474
+ use outSignatureStream = File.Create outFileSignatureName
475
+ use outSignature = new StreamWriter( outSignatureStream)
467
476
fprintfn out " // This is a generated file; the original input is '%s '" fileName
477
+ fprintfn outSignature " // This is a generated file; the original input is '%s '" fileName
468
478
fprintfn out " namespace %s " justFileName
479
+ fprintfn outSignature " namespace %s " justFileName
469
480
fprintfn out " %s " stringBoilerPlatePrefix
481
+ fprintfn outSignature " %s " stringBoilerPlatePrefix
470
482
fprintfn out " type internal SR private() ="
483
+ fprintfn outSignature " type internal SR ="
484
+ fprintfn outSignature " private new: unit -> SR"
471
485
let theResourceName = justFileName
472
486
fprintfn out " %s " ( StringBoilerPlate theResourceName)
487
+ fprintfn outSignature " %s " StringBoilerPlateSignature
473
488
474
489
printMessage " Generating resource methods for %s " outFileName
475
490
// gen each resource method
@@ -494,7 +509,9 @@ open Printf
494
509
495
510
formalArgs.Append " )" |> ignore
496
511
fprintfn out " /// %s " str
512
+ fprintfn outSignature " /// %s " str
497
513
fprintfn out " /// (Originally from %s :%d )" fileName ( lineNum + 1 )
514
+ fprintfn outSignature " /// (Originally from %s :%d )" fileName ( lineNum + 1 )
498
515
499
516
let justPercentsFromFormatString =
500
517
( holes
@@ -523,14 +540,31 @@ open Printf
523
540
errPrefix
524
541
ident
525
542
justPercentsFromFormatString
526
- ( actualArgs.ToString()))
543
+ ( actualArgs.ToString())
544
+
545
+ let signatureMember =
546
+ let returnType =
547
+ match optErrNum with
548
+ | None -> " string"
549
+ | Some _ -> " int * string"
550
+
551
+ if Array.isEmpty holes then
552
+ sprintf " static member %s : unit -> %s " ident returnType
553
+ else
554
+ holes
555
+ |> Array.mapi ( fun idx holeType -> sprintf " a%i : %s " idx holeType)
556
+ |> String.concat " * "
557
+ |> fun parameters -> sprintf " static member %s : %s -> %s " ident parameters returnType
558
+
559
+ fprintfn outSignature " %s " signatureMember)
527
560
528
561
printMessage " Generating .resx for %s " outFileName
529
562
fprintfn out " "
530
563
// gen validation method
531
564
fprintfn out " /// Call this method once to validate that all known resources are valid; throws if not"
532
565
533
566
fprintfn out " static member RunStartupValidation() ="
567
+ fprintfn outSignature " static member RunStartupValidation: unit -> unit"
534
568
535
569
stringInfos
536
570
|> Seq.iter ( fun ( lineNum , ( optErrNum , ident ), str , holes , netFormatString ) ->
@@ -554,7 +588,7 @@ open Printf
554
588
use outXmlStream = File.Create outXmlFileName
555
589
xd.Save outXmlStream
556
590
printMessage " Done %s " outFileName
557
- Some( fileName, outFileName, outXmlFileName)
591
+ Some( fileName, outFileSignatureName , outFileName, outXmlFileName)
558
592
with e ->
559
593
PrintErr( fileName, 0 , sprintf " An exception occurred when processing '%s '\n %s " fileName ( e.ToString()))
560
594
None
@@ -584,7 +618,14 @@ open Printf
584
618
585
619
let generatedSource , generatedResx =
586
620
[|
587
- for ( textFile, source, resx) in generatedFiles do
621
+ for ( textFile, signature, source, resx) in generatedFiles do
622
+ let signatureItem =
623
+ let item = TaskItem( signature)
624
+ item.SetMetadata( " AutoGen" , " true" )
625
+ item.SetMetadata( " DesignTime" , " true" )
626
+ item.SetMetadata( " DependentUpon" , resx)
627
+ item :> ITaskItem
628
+
588
629
let sourceItem =
589
630
let item = TaskItem( source)
590
631
item.SetMetadata( " AutoGen" , " true" )
@@ -598,13 +639,13 @@ open Printf
598
639
item.SetMetadata( " SourceDocumentPath" , textFile)
599
640
item :> ITaskItem
600
641
601
- yield ( sourceItem, resxItem)
642
+ yield ([| signatureItem ; sourceItem |] , resxItem)
602
643
|]
603
644
|> Array.unzip
604
645
605
646
let generatedResult = ( generatedFiles.Length = this.EmbeddedText.Length)
606
647
607
- _ generatedSource <- generatedSource
648
+ _ generatedSource <- Array.collect id generatedSource
608
649
_ generatedResx <- generatedResx
609
650
generatedResult && not this.Log.HasLoggedErrors
610
651
with TaskFailed ->
0 commit comments