Diff
Not logged in

Differences From Artifact [d5bee856dc]:

To Artifact [ce49a5edf0]:


40
41
42
43
44
45
46










47
48
49
50
51
52
53
54
55
56
57































































58
59
60
61
62
63
64

65
66
67
68
69
70
71
  #
  # NOTE: This procedure sets up the default values for all configuration
  #       parameters used by the package uploader client.  The script
  #       argument is the fully qualified path and file name for the script
  #       being evaluated.
  #
  proc setupUploadVars { script } {










    #
    # NOTE: What is the fully qualified path to the directory containing the
    #       checkout for the package client?
    #
    variable checkoutDirectory

    if {![info exists checkoutDirectory]} then {
      set checkoutDirectory [file dirname $script]
    }

    #































































    # NOTE: The command to use when attempting to stage package files using
    #       Fossil.
    #
    variable fossilAddCommand; # DEFAULT fossil add {${fileName}}

    if {![info exists fossilAddCommand]} then {
      set fossilAddCommand {fossil add {${fileName}}}

    }

    #
    # NOTE: The command to use when attempting to commit package files using
    #       Fossil.
    #
    variable fossilCommitCommand; # DEFAULT fossil commit ...







>
>
>
>
>
>
>
>
>
>




|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|


|
>







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  #
  # NOTE: This procedure sets up the default values for all configuration
  #       parameters used by the package uploader client.  The script
  #       argument is the fully qualified path and file name for the script
  #       being evaluated.
  #
  proc setupUploadVars { script } {
    #
    # NOTE: The project code for the Fossil repository.  This will be checked
    #       prior to staging or committing any files.
    #
    variable projectCode; # DEFAULT: 9ceada8dbb8678898e5b2c05386e73b3ff2c2dec

    if {![info exists projectCode]} then {
      set projectCode 9ceada8dbb8678898e5b2c05386e73b3ff2c2dec
    }

    #
    # NOTE: What is the fully qualified path to the directory containing the
    #       checkout for the package client?
    #
    variable checkoutDirectory; # DEFAULT: <scriptDir>

    if {![info exists checkoutDirectory]} then {
      set checkoutDirectory [file dirname $script]
    }

    #
    # NOTE: The command to use when attempting to check for changes prior to
    #       staging files using Fossil.
    #
    variable fossilChangesCommand; # DEFAULT fossil changes ...

    if {![info exists fossilChangesCommand]} then {
      set fossilChangesCommand {fossil changes --chdir {${checkoutDirectory}}}
    }

    #
    # NOTE: The regular expression pattern used when attempting to verify
    #       that the Fossil checkout has no changes staged.  Generally, this
    #       pattern should only match an empty string.
    #
    variable fossilChangesPattern; # DEFAULT: {^$}

    if {![info exists fossilChangesPattern]} then {
      set fossilChangesPattern {^$}
    }

    #
    # NOTE: The command to use when attempting to check the checkout status
    #       prior to staging files using Fossil.
    #
    variable fossilInfoCommand; # DEFAULT fossil info ...

    if {![info exists fossilInfoCommand]} then {
      set fossilInfoCommand {fossil info --chdir {${checkoutDirectory}}}
    }

    #
    # NOTE: The regular expression pattern used when attempting to verify
    #       that the Fossil checkout belongs to the correct project.
    #
    variable fossilInfoProjectCodePattern; # DEFAULT: {^project-code:\\s+...\$}

    if {![info exists fossilInfoProjectCodePattern]} then {
      set fossilInfoProjectCodePattern [appendArgs \
          {^project-code:\\s+${projectCode}\$}]
    }

    #
    # NOTE: The regular expression pattern used when attempting to verify
    #       that the Fossil checkout is sitting on the correct branch.
    #
    variable fossilInfoTagsPattern; # DEFAULT: {^tags:\s+trunk(?:,|$)}

    if {![info exists fossilInfoTagsPattern]} then {
      set fossilInfoTagsPattern {^tags:\s+trunk(?:,|$)}
    }

    #
    # NOTE: The command to use when attempting to reset the checkout to the
    #       default branch prior to staging files using Fossil.
    #
    variable fossilUpdateCommand; # DEFAULT fossil update trunk ...

    if {![info exists fossilUpdateCommand]} then {
      set fossilUpdateCommand \
          {fossil update trunk --chdir {${checkoutDirectory}}}
    }

    #
    # NOTE: The command to use when attempting to stage package files using
    #       Fossil.
    #
    variable fossilAddCommand; # DEFAULT fossil add ...

    if {![info exists fossilAddCommand]} then {
      set fossilAddCommand \
          {fossil add  --chdir {${checkoutDirectory}} {${fileName}}}
    }

    #
    # NOTE: The command to use when attempting to commit package files using
    #       Fossil.
    #
    variable fossilCommitCommand; # DEFAULT fossil commit ...
456
457
458
459
460
461
462




































































































































463
464
465
466
467
468
469
470
471

472
















473
474
475
476
477

478
479
480


481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522


523
524
525
526
527
528
529

      return [eval ::PackageRepository::getFileViaHttp \
          [list $uri] [list 20] [list stdout] [list \
          [expr {!$verboseMetadataSubmit}]] $options]
    }
  }





































































































































  #
  # NOTE: This procedure attempts to stage the specified package files using
  #       Fossil.  The fileNames argument is a list of (fully?) qualified
  #       local file names to stage.
  #
  # <public>
  proc stagePackageFiles { language version platform fileNames } {
    variable checkoutDirectory
    variable fossilAddCommand


















    set relativeFileNames [getRelativeFileNames $fileNames]
    set savedPwd [pwd]; cd $checkoutDirectory

    foreach fileName $fileNames relativeFileName $relativeFileNames {
      file mkdir [file join \

          $language $version $platform [file dirname $relativeFileName]]

      file copy $fileName $relativeFileName


      set fileName $relativeFileName

      if {[isEagle]} then {
        set fileName [::PackageRepository::formatExecArgument $fileName]

        if {[catch {
          eval exec -success Success [subst $fossilAddCommand]
        } error]} then {
          cd $savedPwd

          error [appendArgs \
              "failed to stage file \"" $fileName "\": " $error]
        }
      } else {
        if {[catch {
          eval exec [subst $fossilAddCommand]
        } error]} then {
          cd $savedPwd

          error [appendArgs \
              "failed to stage file \"" $fileName "\": " $error]
        }
      }
    }

    cd $savedPwd
  }

  #
  # NOTE: This procedure attempts to commit the staged package files to the
  #       remote package file repository using Fossil.  The varName argument
  #       is the name of a scalar variable in the context of the immediate
  #       caller that will receive the resulting Fossil check-in identifier.
  #
  # <public>
  proc commitPackageFiles { varName } {
    variable checkoutDirectory
    variable fossilCommitCommand
    variable fossilCommitPattern


    set branch ""; # TODO: Figure out a good branch.
    set comment ""; # TODO: Figure out a good comment.



    if {[isEagle]} then {
      if {[catch {
        eval exec -nocarriagereturns -stdout output -stderr error \
            [subst $fossilCommitCommand]
      } result] == 0} then {
        set result [appendArgs $output $error]







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<



>
|

|
>
>
|







<
<

|





<
<

|



<
<









|




>
|
|
>
>







530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713


714
715
716
717
718
719
720


721
722
723
724
725


726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751

      return [eval ::PackageRepository::getFileViaHttp \
          [list $uri] [list 20] [list stdout] [list \
          [expr {!$verboseMetadataSubmit}]] $options]
    }
  }

  #
  # NOTE: This procedure attempts to verify that the checkout directory does
  #       not contain any (stray) changes.  There are no arguments.  Non-zero
  #       is returned if the verification is successful.
  #
  proc verifyThereAreNoChanges {} {
    variable checkoutDirectory
    variable fossilChangesCommand
    variable fossilChangesPattern

    if {[isEagle]} then {
      if {[catch {
        eval exec -nocarriagereturns -stdout output -stderr error \
            [subst $fossilChangesCommand]
      } result] == 0} then {
        set result [appendArgs $output $error]
      } else {
        return false
      }
    } else {
      if {[catch {
        eval exec [subst $fossilChangesCommand]
      } result]} then {
        return false
      }
    }

    if {![info exists result] || \
        ![regexp -- $fossilChangesPattern $result]} then {
      return false
    }

    return true
  }

  #
  # NOTE: This procedure attempts to verify that the checkout directory does
  #       belong to the correct project.  There are no arguments.  Non-zero
  #       is returned if the verification is successful.
  #
  proc verifyThisIsTheCorrectProject {} {
    variable checkoutDirectory
    variable fossilInfoCommand
    variable fossilInfoProjectCodePattern
    variable projectCode

    if {[isEagle]} then {
      if {[catch {
        eval exec -nocarriagereturns -stdout output -stderr error \
            [subst $fossilInfoCommand]
      } result] == 0} then {
        set result [appendArgs $output $error]
      } else {
        return false
      }
    } else {
      if {[catch {
        eval exec [subst $fossilInfoCommand]
      } result]} then {
        return false
      }
    }

    if {![info exists result] || ![regexp -line -- \
        [subst $fossilInfoProjectCodePattern] $result]} then {
      return false
    }

    return true
  }

  #
  # NOTE: This procedure attempts to verify that the checkout directory does
  #       belong to the correct branch.  There are no arguments.  Non-zero
  #       is returned if the verification is successful.
  #
  proc verifyThisIsTheCorrectBranch {} {
    variable checkoutDirectory
    variable fossilInfoCommand
    variable fossilInfoTagsPattern

    if {[isEagle]} then {
      if {[catch {
        eval exec -nocarriagereturns -stdout output -stderr error \
            [subst $fossilInfoCommand]
      } result] == 0} then {
        set result [appendArgs $output $error]
      } else {
        return false
      }
    } else {
      if {[catch {
        eval exec [subst $fossilInfoCommand]
      } result]} then {
        return false
      }
    }

    if {![info exists result] || \
        ![regexp -line -- $fossilInfoTagsPattern $result]} then {
      return false
    }

    return true
  }

  #
  # NOTE: This procedure attempts to change the branch for the checkout
  #       directory.  There are no arguments.  This procedure may raise
  #       script errors.
  #
  proc changeToTheCorrectBranch {} {
    variable checkoutDirectory
    variable fossilUpdateCommand

    if {[isEagle]} then {
      if {[catch {
        eval exec -success Success [subst $fossilUpdateCommand]
      } error]} then {
        error [appendArgs \
            "could not change branch: " $error]
      }
    } else {
      if {[catch {
        eval exec [subst $fossilUpdateCommand]
      } error]} then {
        error [appendArgs \
            "could not change branch: " $error]
      }
    }
  }

  #
  # NOTE: This procedure attempts to stage the specified package files using
  #       Fossil.  The fileNames argument is a list of (fully?) qualified
  #       local file names to stage.
  #
  # <public>
  proc stagePackageFiles { language version platform fileNames } {
    variable checkoutDirectory
    variable fossilAddCommand
    variable fossilUpdateCommand

    if {![verifyThereAreNoChanges]} then {
      error "cannot stage package files: there are pending changes"
    }

    if {![verifyThisIsTheCorrectProject]} then {
      error "cannot stage package files: wrong project"
    }

    if {![verifyThisIsTheCorrectBranch]} then {
      changeToTheCorrectBranch

      if {![verifyThisIsTheCorrectBranch]} then {
        error "cannot stage file: still on wrong branch"
      }
    }

    set relativeFileNames [getRelativeFileNames $fileNames]


    foreach fileName $fileNames relativeFileName $relativeFileNames {
      file mkdir [file join \
          $checkoutDirectory $language $version $platform \
          [file dirname $relativeFileName]]

      file copy $fileName \
          [file join $checkoutDirectory $relativeFileName]

      set fileName $relativeFileName; # NOTE: For [subst].

      if {[isEagle]} then {
        set fileName [::PackageRepository::formatExecArgument $fileName]

        if {[catch {
          eval exec -success Success [subst $fossilAddCommand]
        } error]} then {


          error [appendArgs \
              "could not stage file \"" $fileName "\": " $error]
        }
      } else {
        if {[catch {
          eval exec [subst $fossilAddCommand]
        } error]} then {


          error [appendArgs \
              "could not stage file \"" $fileName "\": " $error]
        }
      }
    }


  }

  #
  # NOTE: This procedure attempts to commit the staged package files to the
  #       remote package file repository using Fossil.  The varName argument
  #       is the name of a scalar variable in the context of the immediate
  #       caller that will receive the resulting Fossil check-in identifier.
  #
  # <public>
  proc commitPackageFiles { package patchLevel language version varName } {
    variable checkoutDirectory
    variable fossilCommitCommand
    variable fossilCommitPattern

    set branch [appendArgs pkg_ $package _ $patchLevel]

    set comment [appendArgs \
        "Add package " $package " v" $patchLevel " for " $language \
        " v" $version .]

    if {[isEagle]} then {
      if {[catch {
        eval exec -nocarriagereturns -stdout output -stderr error \
            [subst $fossilCommitCommand]
      } result] == 0} then {
        set result [appendArgs $output $error]