[go: up one dir, main page]

File: run.c

package info (click to toggle)
cook 2.29-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,656 kB
  • ctags: 4,083
  • sloc: ansic: 47,636; sh: 14,376; makefile: 4,656; yacc: 3,166; perl: 224; awk: 219
file content (1224 lines) | stat: -rw-r--r-- 39,657 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
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
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
/*
 *      cook - file construction tool
 *      Copyright (C) 1997-1999, 2001, 2003, 2004, 2006, 2007 Peter Miller;
 *      All rights reserved.
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 *
 * MANIFEST: functions to walk a single graph recipe node
 */

#include <common/ac/string.h>
#include <common/ac/unistd.h>   /* for getpid */

#include <common/error_intl.h>
#include <common/os_path_cat.h>
#include <common/str_list.h>
#include <common/trace.h>
#include <cook/cook.h>
#include <cook/dir_part.h>
#include <cook/fingerprint.h>
#include <common/ts.h>
#include <cook/graph.h>
#include <cook/graph/file.h>
#include <cook/graph/file_list.h>
#include <cook/graph/file_pair.h>
#include <cook/graph/recipe.h>
#include <cook/graph/run.h>
#include <cook/id.h>
#include <cook/id/variable.h>
#include <cook/match.h>
#include <cook/opcode/context.h>
#include <cook/opcode/list.h>
#include <cook/option.h>
#include <cook/os_interface.h>
#include <cook/recipe.h>
#include <cook/stmt.h>


static int
make_target_directories(graph_file_list_nrc_ty *gflp)
{
    size_t          k;
    int             status;
    int             echo;
    int             errok;

    status = 0;
    echo = !option_test(OPTION_SILENT);
    errok = option_test(OPTION_ERROK);
    for (k = 0; k < gflp->nfiles; ++k)
    {
        graph_file_and_type_ty *gftp;
        graph_file_ty   *gfp;
        string_ty       *s;

        gftp = gflp->item + k;
        gfp = gftp->file;
        s = dir_part(gfp->filename);
        if (s)
        {
            if (os_mkdir(s, echo) && !errok)
                status = -1;
            str_free(s);
        }
    }
    return status;
}


static string_ty *
host_binding_round_robin(opcode_context_ty *ocp, string_list_ty *slp)
{
    static int      j;

    if (!j)
        j = getpid();
    if (!slp || !slp->nstrings)
    {
        static string_ty *key;
        id_ty           *idp;

        if (!key)
            key = str_from_c("parallel_hosts");
        idp = opcode_context_id_search(ocp, key);
        if (!idp)
            return 0;
        slp = id_variable_query2(idp);
        if (!slp || !slp->nstrings)
            return 0;
    }
    return slp->string[j++ % slp->nstrings];
}


/**
  * The relevate funtion is used to make a symbolic link relative to its
  * destintion, rather than relative to dot (the current directory).
  */
static string_ty *
relevate(string_ty *from, string_ty *to)
{
    if (from->str_text[0] == '/')
        return str_copy(from);
    if (to->str_text[0] == '/')
        return os_path_cat(os_curdir(), from);
    const char *cp = to->str_text;
    from = str_copy(from);
    for (;;)
    {
        string_ty       *s2;

        cp = strchr(cp, '/');
        if (!cp)
            return from;
        for (;;)
        {
            ++cp;
            if (*cp != '/')
                break;
        }
        if (!*cp)
            return from;

        s2 = str_format("../%s", from->str_text);
        str_free(from);
        from = s2;
    }
}


/*
 * NAME
 *      graph_recipe_run
 *
 * SYNOPSIS
 *      graph_walk_status_ty graph_recipe_run(graph_recipe_ty *);
 *
 * DESCRIPTION
 *      The graph_recipe_run function is used via graph_walk_inner to
 *      perform a recipe.  If the derived files are out-of-date, the
 *      recipe body will be run to bring them up-to-date.
 *
 * RETURNS
 *      graph_walk_status_ty
 *              error           something went wrong
 *              uptodate        no action required
 *              uptodate_done   fingerprints indicate the file did not change
 *              done            targets are out of date, because the
 *                              recipe body was run
 */

graph_walk_status_ty
graph_recipe_run(graph_recipe_ty *grp, graph_ty *gp)
{
    graph_walk_status_ty status;
    time_t          target_age;
    long            target_depth;
    string_ty       *target_absent;
    int             forced;
    string_list_ty  wl;
    string_list_ty  younger;
    int             show_reasoning;
    string_ty       *target1;
    time_t          need_age;
    size_t          j;
    size_t          k;
    int             phony;
    sub_context_ty  *scp;
    time_t          timestamp_granularity;

    trace(("graph_recipe_run(grp = %08lX)\n{\n", (long)grp));
    status = graph_walk_status_uptodate;
    timestamp_granularity = ts_granularity();

    if (grp->ocp)
    {
        need_age = grp->ocp->need_age;
        opcode_context_resume(grp->ocp);
        status = graph_walk_status_done;
        goto resume;
    }
    need_age = 0;
    phony = !grp->rp->out_of_date;

    /*
     * create the opcode context for this recipe
     */
    grp->ocp = opcode_context_new(0, grp->mp);
    grp->ocp->gp = gp;

    /*
     * Warn about essential information which is kept only in
     * derived files.
     */
    if (gp->file_pair)
    {
        for (j = 0; j < grp->output->nfiles; ++j)
        {
            target1 = grp->output->item[j].file->filename;
            for (k = 0; k < grp->input->nfiles; ++k)
            {
                graph_file_pair_check
                (
                    gp->file_pair,
                    target1,
                    grp->input->item[k].file->filename,
                    gp
                );
            }
        }
    }

    /*
     * construct the ``target'' variable
     */
    string_list_constructor(&wl);
    assert(grp->output);
    assert(grp->output->nfiles > 0);
    if (grp->output->nfiles > 0)
    {
        target1 = grp->output->item[0].file->filename;
        string_list_append(&wl, target1);
    }
    else
        target1 = str_from_c("\7bogus\7");      /* mem leak */
    opcode_context_id_assign(grp->ocp, id_target, id_variable_new(&wl), -1);
    string_list_destructor(&wl);

    /*
     * construct the ``targets'' variable
     */
    string_list_constructor(&wl);
    assert(grp->input);
    for (j = 0; j < grp->output->nfiles; ++j)
        string_list_append(&wl, grp->output->item[j].file->filename);
    opcode_context_id_assign(grp->ocp, id_targets, id_variable_new(&wl), -1);
    string_list_destructor(&wl);

    /*
     * construct the ``need'' variable
     */
    string_list_constructor(&wl);
    assert(grp->input);
    for (j = 0; j < grp->input->nfiles; ++j)
        string_list_append(&wl, grp->input->item[j].file->filename);
    opcode_context_id_assign(grp->ocp, id_need, id_variable_new(&wl), -1);
    string_list_destructor(&wl);

    /*
     * Constructing the ``younger'' variable takes quite a bit
     * longer because we need to consult the file modification
     * times.  [[Fake an assignment to avoid problems with errors.]]
     */
    string_list_constructor(&younger);
    opcode_context_id_assign
    (
        grp->ocp,
        id_younger,
        id_variable_new(&younger),
        -1
    );

    /*
     * Flags apply to the precondition and to the ingredients
     * evaluation.  That is why the grammar puts them first.
     */
    recipe_flags_set(grp->rp);
    show_reasoning = option_test(OPTION_REASON);

    /*
     * see of the recipe is forced to activate
     */
    forced = option_test(OPTION_FORCE) | grp->multi_forced;
    if (forced && show_reasoning)
    {
        scp = sub_context_new();
        sub_var_set_string(scp, "File_Name", target1);
        error_with_position
        (
            &grp->rp->pos,
            scp,
            i18n("\"$filename\" is out of date because the \"forced\" flag is "
                "set (reason)")
        );
        sub_context_delete(scp);
    }

    /*
     * By taking a fingerprint of the ingredients, we can cause
     * the recipe to trigger when the number of ingredients change,
     * or when one ingredient is substituted for another, EVEN IF
     * the time stamps are all consistent.  (This is especially
     * important when an ingredient is *removed* from a library.)
     */
    if (option_test(OPTION_INGREDIENTS_FINGERPRINT))
    {
        string_list_ty  ingr;
        string_ty       *ingr2;
        string_ty       *ingr_fp;

        string_list_constructor(&ingr);
        for (j = 0; j < grp->input->nfiles; ++j)
        {
            graph_file_ty   *gfp;

            gfp = grp->input->item[j].file;
            string_list_append(&ingr, gfp->filename);
        }
        string_list_sort(&ingr);
        ingr2 = wl2str(&ingr, 0, ingr.nstrings, "\n");
        string_list_destructor(&ingr);
        ingr_fp = fp_fingerprint_string(ingr2);
        str_free(ingr2);

        /*
         * Not only does the fp_ingredients_fingerprint_differs
         * function check to see if it is different, it also
         * updates the cache files, so that it will be written
         * out at the next opportunity.
         */
        if (fp_ingredients_fingerprint_differs(target1, ingr_fp))
        {
            forced = 1;

            if (show_reasoning)
            {
                scp = sub_context_new();
                sub_var_set_string(scp, "File_Name", target1);
                error_with_position
                (
                    &grp->rp->pos,
                    scp,
                    i18n("\"$filename\" is out of date because the ingredients "
                        "changed (reason)")
                );
                sub_context_delete(scp);
            }
        }
        str_free(ingr_fp);
    }

    /*
     * age should be set to the worst case of all the targets
     *
     * The depth of the target search should be less than or equal
     * to the depth of the worst (shallowest) ingredients search.
     * This is to guarantee that when ingredients change they
     * result in targets shallower in the path being updated.
     */
    target_age = 0;
    target_absent = 0;
    target_depth = 32767;
    for (j = 0; j < grp->output->nfiles; ++j)
    {
        graph_file_ty   *gfp2;
        time_t          age2;
        long            depth2;

        gfp2 = grp->output->item[j].file;

        /*
         * Remember the oldest mtime for later, when we compare
         * them to see if it changed.  Only do this for
         * fingerprints - they will stay the same even when the
         * file is re-written.
         */
        if (option_test(OPTION_FINGERPRINT))
        {
            depth2 = 32767;
            age2 = cook_mtime_oldest(grp->ocp, gfp2->filename, &depth2, depth2);
            if (age2 < 0)
            {
                /*
                 * Error message already printed.
                 *
                 * cook_mtime_oldest calls os_mtime_oldest
                 * os_mtime_oldest calls stat_cache_oldest
                 * stat_cache_oldest calls stat_cache
                 * stat_cache_oldest prints the file time traces
                 *
                 * stat_cache calls lstat
                 * if there is an error, and the error isn't ENOENT or
                 * ENOTDIR, stat_cache calls error_intl_stat (which
                 * calls error_intl) to print it.
                 */
                trace(("Error message already printed?\n"));
                status = graph_walk_status_error;
                goto ret;
            }
            gfp2->mtime_oldest = age2;
        }

        depth2 = 32767;
        age2 = cook_mtime_newest(grp->ocp, gfp2->filename, &depth2, depth2);
        if (age2 < 0)
        {
            /*
             * Error message already printed.
             *
             * cook_time_newest calls os_mtime_newest
             * os_mtime_newest calls stat_cache_newest
             * stat_cache_newest calls stat_cache
             * stat_cache_newest prints the file time traces
             *
             * stat_cache calls lstat
             * if there is an error, and the error isn't ENOENT or
             * ENOTDIR, stat_cache calls error_intl_stat (which calls
             * error_intl) to print it.
             */
            trace(("Error message already printed?\n"));
            status = graph_walk_status_error;
            goto ret;
        }
        if (age2 == 0)
            target_absent = gfp2->filename;
        else
        {
            if (depth2 < target_depth)
                target_depth = depth2;
            if (!target_age || age2 < target_age)
                target_age = age2;
        }
    }
    if (!forced && target_absent && !phony)
    {
        if (show_reasoning)
        {
            scp = sub_context_new();
            sub_var_set_string(scp, "File_Name", target_absent);
            error_with_position
            (
                &grp->rp->pos,
                scp,
                i18n("\"$filename\" is out of date because it does not exist "
                    "(reason)")
            );
            sub_context_delete(scp);
        }
        forced = 1;
    }
    if (!forced && target_depth > 0 && option_test(OPTION_SHALLOW))
    {
        if (show_reasoning)
        {
            scp = sub_context_new();
            sub_var_set_string(scp, "File_Name", target1);
            error_with_position
            (
                &grp->rp->pos,
                scp,
                i18n("\"$filename\" is out of date because it is too deep "
                    "(reason)")
            );
            sub_context_delete(scp);
        }
        forced = 1;
    }
    if (forced)
    {
        /* make sure ``younger'' contains all ingredients */
        target_age = 0;
        target_depth = 0;
    }
    trace(("forced = %d;\n", forced));
    trace(("target_depth = %d;\n", target_depth));
    trace(("target_age = %ld;\n", (long)target_age));

    /*
     * Look at the mtimes for each of the ingredients.
     */
    need_age = 0;
    for (j = 0; j < grp->input->nfiles; ++j)
    {
        graph_file_and_type_ty *gftp2;
        graph_file_ty   *gfp2;
        time_t          age2;
        long            depth2;
        int             do_this_one;

        gftp2 = grp->input->item + j;
        gfp2 = gftp2->file;
        trace(("%d/%d \"%s\"\n", j, grp->input->nfiles,
                gfp2->filename->str_text));
        depth2 = 32767;
        age2 =
            cook_mtime_oldest
            (
                grp->ocp,
                gfp2->filename,
                &depth2,
                target_depth + 1
            );
        if (age2 < 0)
        {
            /*
             * Error message already printed.
             *
             *
             * cook_mtime_oldest calls os_mtime_oldest
             * os_mtime_oldest calls stat_cache_oldest
             * stat_cache_oldest calls stat_cache
             * stat_cache_oldest prints the file time traces
             *
             * stat_cache calls lstat
             * If there is an error, and the error isn't ENOENT or
             * ENOTDIR, stat_cache calls error_intl_stat (which calls
             * error_intl) to print it.
             */
            trace(("Error message already printed?\n"));
            status = graph_walk_status_error;
            goto ret;
        }

        /*
         * track the youngest ingredient,
         * in case we need to adjust the targets' times
         */
        if (age2 > need_age)
            need_age = age2;

        /*
         * This function is only called AFTER an ingredient has
         * been derived. It will exist (well, almost: it could
         * be a phony) and so the mtime in the stat cache will
         * have been set.
         *
        assert(age2 != 0);
         */

        /*
         * Check to see if this ingredient invalidates the
         * target, based on its age.  (Don't say anything if we
         * already know it's out of date.)
         */
        if (gfp2->done && gftp2->edge_type != edge_type_exists)
        {
            if (!forced)
            {
                if (show_reasoning)
                {
                    scp = sub_context_new();
                    sub_var_set_string(scp, "File_Name1", target1);
                    sub_var_set_string(scp, "File_Name2", gfp2->filename);
                    error_with_position
                    (
                        &grp->rp->pos,
                        scp,
                        i18n("$filename1 is out of date because $filename2 was "
                            "cooked and is now younger (reason)")
                    );
                    sub_context_delete(scp);
                }
                forced = 1;
            }
            string_list_append_unique(&younger, gfp2->filename);
        }

        /*
         * Check to see if this ingredient invalidates the
         * target, based on its age.  (Don't say anything if we
         * already know it's out of date.)
         * The edge type is relevant to the calculation.
         */
        do_this_one = 0;
        switch (gftp2->edge_type)
        {
        case edge_type_exists:
            /*
             * The "exists" edge type is merely an ordering
             * constraint.  It guarantees that the ingredient
             * will be up to date before this recipie's body
             * is evaluated.  The actual relative ages of the
             * ingredient and the target don't come into it.
             *
             * Also, the depth is not a consideration
             * (otherwise this could imply a `set shallow'
             * that the user did not intend.
             */
            depth2 = 32767;
            break;

        case edge_type_weak:
            /*
             * The "weak" edge type allows two files to have
             * the same time stamp, and still be up-to-date.
             */
            do_this_one = age2 > target_age;
            break;

        case edge_type_strict:
        case edge_type_default:
            /*
             * The "strict" edge type requires two files to
             * have distinct time stamps.
             */
            do_this_one = age2 >= target_age;
            break;
        }
        if (do_this_one && !phony)
        {
            if (!forced)
            {
                if (show_reasoning)
                {
                    scp = sub_context_new();
                    sub_var_set_string(scp, "File_Name1", target1);
                    sub_var_set_string(scp, "File_Name2", gfp2->filename);
                    error_with_position
                    (
                        &grp->rp->pos,
                        scp,
                        i18n("$filename1 is out of date because $filename2 is "
                            "younger (reason)")
                    );
                    sub_context_delete(scp);
                }
                forced = 1;
            }
            string_list_append_unique(&younger, gfp2->filename);
        }

        /*
         * Check to see if this ingredient invalidates the
         * target, based on its depth.  (Don't say anything if we
         * already know its out of date.)
         */
        if (depth2 < target_depth && !phony)
        {
            trace(("depth2 = %d;\n", depth2));
            if (!forced)
            {
                if (show_reasoning)
                {
                    scp = sub_context_new();
                    sub_var_set_string(scp, "File_Name1", target1);
                    sub_var_set_string(scp, "File_Name2", gfp2->filename);
                    error_with_position
                    (
                        &grp->rp->pos,
                        scp,
                        i18n("$filename1 is out of date because $filename2 is "
                            "shallower (reason)")
                    );
                    sub_context_delete(scp);
                }
                forced = 1;
            }
            string_list_append_unique(&younger, gfp2->filename);
        }
    }
    if (grp->input->nfiles == 0)
    {
        /*
         * If there are no input files, pretend that the
         * youngest ingredient is ``now'' if the file does not
         * exist, and a second older than the target if it does
         * exist.
         */
        if (forced)
            time(&need_age);
        else
            need_age = target_age - 1;
    }

    /*
     * Assign the ``younger'' variable.
     * (Use a normal assignment, we did the push already.)
     */
    trace(("mark\n"));
    opcode_context_id_assign
    (
        grp->ocp,
        id_younger,
        id_variable_new(&younger),
        -1
    );
    string_list_destructor(&younger);

    /*
     * See if we need to perform the actions attached to this recipe.
     */
    if (forced)
    {
        trace(("forced\n"));

        /*
         * Remember that we did something.
         */
        status = graph_walk_status_done;

        if (grp->rp->out_of_date)
        {
            /*
             * Make directories for the targets if asked to.
             */
            trace(("do recipe body\n"));
            if
            (
                option_test(OPTION_MKDIR)
            &&
                make_target_directories(grp->output) < 0
            )
            {
                /*
                 * Error message already printed.
                 *
                 * make_target_directories calls os_mkdir
                 * os_mkdir calls mkdir
                 *
                 * If there is an error, and the error isn't
                 * EEXISTS, os_mkdir calls error_intl to report the
                 * error.
                 */
                trace(("Error message already printed?\n"));
                status = graph_walk_status_error;
                goto ret;
            }

            /*
             * Unlink the targets if asked to.
             */
            if (option_test(OPTION_UNLINK))
            {
                for (k = 0; k < grp->output->nfiles; ++k)
                {
                    graph_file_ty  *gfp2;

                    gfp2 = grp->output->item[k].file;
                    if
                    (
                        os_delete(gfp2->filename, !option_test(OPTION_SILENT))
                    &&
                        !option_test(OPTION_ERROK)
                    )
                    {
                        /*
                         * Error message already printed.
                         *
                         * os_delete calls unlink
                         *
                         * If there is an error, and the error isn't
                         * ENOENT, os_delete calls error_intl to report
                         * the error.
                         */
                        trace(("Error message already printed?\n"));
                        status = graph_walk_status_error;
                        goto ret;
                    }
                }
            }

            /*
             * Create symbolic links to ingredients of they are not
             * present in the top level directory of the search path.
             */
            if (option_test(OPTION_SYMLINK_INGREDIENTS))
            {
                for (k = 0; k < grp->input->nfiles; ++k)
                {
                    graph_file_ty  *gfp2;
                    string_ty      *from;
                    string_ty      *to;

                    gfp2 = grp->input->item[k].file;
                    to = gfp2->filename;
                    from = cook_mtime_resolve1(grp->ocp, to);
                    if (from && !str_equal(from, to))
                    {
                        string_ty       *from2;

                        from2 = relevate(from, to);
                        int echo = !option_test(OPTION_SILENT);
                        os_symlink(from2, to, echo);
                        str_free(from2);
                    }
                    str_free(from);
                }
            }

            if (option_test(OPTION_TOUCH))
            {
                /*
                 * Touch the targets, if asked to touch
                 * rather than to build.
                 */
                for (k = 0; k < grp->output->nfiles; ++k)
                {
                    graph_file_ty  *gfp2;

                    gfp2 = grp->output->item[k].file;
                    if (!option_test(OPTION_SILENT))
                    {
                        scp = sub_context_new();
                        sub_var_set_string(scp, "File_Name", gfp2->filename);
                        error_intl(scp, i18n("touch $filename"));
                        sub_context_delete(scp);
                    }
                    if (os_touch(gfp2->filename))
                    {
                        /*
                         * Error message already printed.
                         *
                         * os_touch calls utime
                         *
                         * If there is an errror os_touch calls
                         * error_intl to report the error.
                         */
                        trace(("Error message already printed?\n"));
                        status = graph_walk_status_error;
                    }
                }
            }
            else
            {
                opcode_status_ty result;
                string_ty       *hostname;

                /*
                 * run the recipe body
                 */
                trace(("doing it now\n"));
                opcode_context_call(grp->ocp, grp->rp->out_of_date);
                hostname =
                    host_binding_round_robin(grp->ocp, grp->host_binding);
                if (hostname)
                {
                    opcode_context_host_binding_set(grp->ocp, hostname);
                }
              resume:
                result = opcode_context_execute(grp->ocp);
                switch (result)
                {
                case opcode_status_wait:
                    grp->ocp->need_age = need_age;
                    opcode_context_suspend(grp->ocp);
                    trace(("wait...\n"));
                    trace(("}\n"));
                    return graph_walk_status_wait;

                case opcode_status_success:
                    status = graph_walk_status_done;
                    break;

                case opcode_status_error:
                    if (option_test(OPTION_ERROK))
                        status = graph_walk_status_done;
                    else
                    {
                        /*
                         * Error message already printed.
                         *
                         * opcode_context_execute calls
                         *     opcode_context_execute_inner.
                         * opcode_context_execute_inner calls opcode_execute.
                         * opcode_execute calls the execute method of
                         *     the relevant opcode.
                         * All opcodes print an error message if they
                         * return opcde_status_error.
                         */
                        trace(("Error message already printed?\n"));
                        status = graph_walk_status_error;
                    }
                    break;

                case opcode_status_interrupted:
                    /*
                     * Error message already printed.
                     * by the interrupt handler.
                     */
                    trace(("Error message already printed?\n"));
                    status = graph_walk_status_error;
                    break;
                }

                /*
                 * Remove recipe targets on errors, unless asked to keep
                 * them around.  This ensures they will be built again;
                 * hopefully without errors the next time.  (Perfect
                 * cookbooks with exact dependencies don't need this,
                 * but users often omit dependencies; removing the file
                 * forces a re-build.)
                 */
                if
                (
                    status == graph_walk_status_error
                &&
                    !option_test(OPTION_PRECIOUS)
                )
                {
                    for (k = 0; k < grp->output->nfiles; ++k)
                    {
                        graph_file_ty   *gfp2;

                        gfp2 = grp->output->item[k].file;
                        os_delete(gfp2->filename, !option_test(OPTION_SILENT));
                    }
                }
            }
        }
        else
        {
            if (show_reasoning)
            {
                scp = sub_context_new();
                sub_var_set_string(scp, "File_Name", target1);
                error_intl(scp, i18n("$filename is phony (reason)"));
                sub_context_delete(scp);
            }

            /*
             * remember that this ``file'' has been ``changed''
             */
            for (j = 0; j < grp->output->nfiles; ++j)
            {
                graph_file_ty   *gfp;

                gfp = grp->output->item[j].file;
                gfp->done++;
            }
        }
    }
    else
    {
        trace(("not forced\n"));
        if (show_reasoning)
        {
            scp = sub_context_new();
            sub_var_set_string(scp, "File_Name", target1);
            error_intl(scp, i18n("$filename is up to date (reason)"));
            sub_context_delete(scp);
        }
        if (grp->rp->up_to_date)
        {
            opcode_status_ty result;

            /*
             * Make directories for the targets if asked to.
             * Often redundant, but it wont hurt.
             */
            if
            (
                option_test(OPTION_MKDIR)
            &&
                make_target_directories(grp->output) < 0
            )
            {
                /*
                 * Error message already printed.
                 *
                 * make_target_directories calls os_mkdir
                 * os_mkdir calls mkdir
                 *
                 * If there is an error, and the error isn't EEXISTS,
                 * os_mkdir calls error_intl to report the error.
                 */
                trace(("Error message already printed?\n"));
                status = graph_walk_status_error;
                goto ret;
            }

            /*
             * This feature isn't used often, don't worry
             * about making it parallel.
             */
            trace(("perform ``use'' clause\n"));
            opcode_context_call(grp->ocp, grp->rp->up_to_date);
            result = opcode_context_execute_nowait(grp->ocp);
            if (result != opcode_status_success)
            {
                /*
                 * Error message already printed.
                 *
                 * opcode_context_execute_nowait calls opcode_context_execute.
                 * opcode_context_execute calls opcode_context_execute_inner.
                 * opcode_context_execute_inner calls opcode_execute.
                 * opcode_execute calls the execute method of the relevant
                 *     opcode.
                 * All opcodes print an error message if they return
                 * opcde_status_error.
                 */
                trace(("Error message already printed?\n"));
                status = graph_walk_status_error;
            }
        }
    }

    /*
     * adjust file modification times
     * (tracking fingerprints as we go)
     */
  ret:
    trace(("mark\n"));
    if (status == graph_walk_status_done && grp->rp->out_of_date)
    {
        time_t          mtime;

        /*
         * The output files need to be at least this date
         * stamp to be mtime-consistent with the inputs.
         */
        mtime = need_age + timestamp_granularity;
        if (option_test(OPTION_FINGERPRINT))
        {
            /*
             * Update the times, and see if the pringerprint
             * changed.  If the fingerprint did not change
             * on any target, use the uptodate_done result,
             * otherwise use the done result.
             */
            status = graph_walk_status_uptodate_done;
            for (j = 0; j < grp->output->nfiles; ++j)
            {
                graph_file_ty   *gfp;
                time_t          t;
                long            depth4;

                gfp = grp->output->item[j].file;
                os_clear_stat(gfp->filename);
                if (os_mtime_adjust(gfp->filename, mtime))
                {
                    /*
                     * Error message already printed.
                     *
                     * os_mtime_adjust calls utime.
                     * If there is an error, os_mtime_sdjust calls
                     * error_intl top report the error.
                     */
                    trace(("Error message already printed?\n"));
                    status = graph_walk_status_error;
                    /*
                     * don't break here, need to
                     * update all of them
                     */
                    continue;
                }
                depth4 = 32767;
                t = cook_mtime_oldest(grp->ocp, gfp->filename, &depth4, depth4);
                if (t < 0)
                {
                    /*
                     * Error message already printed.
                     *
                     * cook_mtime_oldest calls os_mtime_oldest
                     * os_mtime_oldest calls stat_cache_oldest
                     * stat_cache_oldest calls stat_cache
                     * stat_cache_oldest prints the file time traces
                     *
                     * stat_cache calls lstat
                     * if there is an error, and the error isn't ENOENT or
                     * ENOTDIR, stat_cache calls error_intl_stat (which
                     * calls error_intl) to print it.
                     */
                    trace(("Error message already printed?\n"));
                    status = graph_walk_status_error;

                    /*
                     * don't break here, need to
                     * update all of them
                     */
                    continue;
                }
                if (t == gfp->mtime_oldest)
                {
                    if (!option_test(OPTION_SILENT))
                    {
                        scp = sub_context_new();
                        sub_var_set_string(scp, "File_Name", gfp->filename);
                        error_intl
                        (
                            scp,
                            i18n("$filename fingerprint unchanged")
                        );
                        sub_context_delete(scp);
                    }
                }
                else if (status != graph_walk_status_error)
                {
                    status = graph_walk_status_done;
                    gfp->done++;
                }
            }
        }
        else
        {
            /*
             * update the times if it worked
             * and if it was not a phony recipe
             */
            for (j = 0; j < grp->output->nfiles; ++j)
            {
                graph_file_ty   *gfp;

                gfp = grp->output->item[j].file;
                gfp->done++;    /* for out-of-date calcs */
                if (os_mtime_adjust(gfp->filename, mtime))
                {
                    /*
                     * Error message already printed.
                     *
                     * os_mtime_adjust calls utime.
                     * If there is an error, os_mtime_sdjust calls
                     * error_intl top report the error.
                     */
                    trace(("Error message already printed?\n"));
                    status = graph_walk_status_error;
                    /*
                     * don't break here, need to
                     * update all of them
                     */
                }
            }
        }
    }

    /*
     * Make sure the target times are consistent with the
     * ingredients times, when there was nothing to do.  This is
     * usually only necessary when finger prints are in use, but can
     * sometimes be necessary when file server times are out of
     * sync.  This guarantees that a later fingerprint-less run will
     * not find huge amounts of work to do.
     */
    trace(("mark\n"));
    if
    (
        (
            status == graph_walk_status_uptodate
        ||
            status == graph_walk_status_uptodate_done
        )
    &&
        grp->rp->out_of_date
    &&
        (option_test(OPTION_UPDATE) || option_test(OPTION_FINGERPRINT))
    )
    {
        time_t          need_age_youngest;

        /*
         * find the youngest ingredient's age
         * (will be in the stat cache or the fingerprint cache)
         */
        need_age_youngest = 0;
        for (j = 0; j < grp->input->nfiles; ++j)
        {
            graph_file_and_type_ty *gftp2;
            graph_file_ty   *gfp2;
            time_t          age2;
            long            depth2;

            gftp2 = grp->input->item + j;
            gfp2 = gftp2->file;
            depth2 = 32767;
            age2 = cook_mtime_newest(grp->ocp, gfp2->filename, &depth2, depth2);
            if (age2 > need_age_youngest)
                need_age_youngest = age2;
        }

        /*
         * Advance one second younger.  This is the youngest a
         * target may be to be mtime-consistent with the
         * ingredients.
         *
         * Actually, on Cygwin on FAT filesystems, the timestamp
         * granularity is 2 seconds.  There is no pathconf query
         * to tell you the time stamp granularity (sigh) so we
         * have to assume that if you are on Cygwin, you needd
         * a 2 second granularity, even if you are on an NTFS
         * file system with 1 second granularity.
         */
        need_age_youngest += timestamp_granularity;

        /*
         * check each of the targets for consistency
         */
        for (j = 0; j < grp->output->nfiles; ++j)
        {
            graph_file_ty   *gfp;
            time_t          age3;
            long            depth3;

            gfp = grp->output->item[j].file;
            depth3 = 32767;
            age3 = cook_mtime_newest(grp->ocp, gfp->filename, &depth3, depth3);
            if (age3 > 0 && depth3 == 0 && age3 < need_age_youngest)
            {
                os_mtime_adjust(gfp->filename, need_age_youngest);
                /*
                 * Error message already printed.
                 *
                 * os_mtime_adjust calls utime.  If there is an error,
                 * os_mtime_sdjust calls error_intl top report the
                 * error.
                 */
            }
        }
    }

    /*
     * cancel the recipe flags
     */
    option_undo_level(OPTION_LEVEL_RECIPE);
    if (grp->ocp)
    {
        opcode_context_delete(grp->ocp);
        grp->ocp = 0;
    }

    trace(("return %s;\n", graph_walk_status_name(status)));
    trace(("}\n"));
    return status;
}