forked from DOCGroup/MPC
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathProjectCreator.pm
More file actions
6187 lines (5392 loc) · 199 KB
/
ProjectCreator.pm
File metadata and controls
6187 lines (5392 loc) · 199 KB
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
package ProjectCreator;
# ************************************************************
# Description : Base class for all project creators
# Author : Chad Elliott
# Create Date : 3/13/2002
# ************************************************************
# ************************************************************
# Pragmas
# ************************************************************
use strict;
use FileHandle;
use File::Path;
use mpc_debug;
use Creator;
use TemplateInputReader;
use TemplateParser;
use FeatureParser;
use CommandHelper;
use Data::Dumper;
#use Tie::IxHash;
use vars qw(@ISA);
@ISA = qw(Creator);
# ************************************************************
# Data Section
# ************************************************************
## The basic extensions known to a project creator
my $BaseClassExtension = 'mpb';
my $ProjectCreatorExtension = 'mpc';
my $TemplateExtension = 'mpd';
my $TemplateInputExtension = 'mpt';
## This feature is enabled or disabled depending on whether
## or not the -static option is used.
my $static_libs_feature = 'static_libs_only';
## Valid names for assignments within a project
## Bit Meaning
## 0 Preserve the order for additions (1) or invert it (0)
## 1 Add this value to template input value (if there is one)
## 2 Preserve <% %> settings for evaluation within the template
my %validNames = ('after' => 1,
'avoids' => 3,
'custom_only' => 1,
'dllout' => 1,
'dynamicflags' => 3,
'exename' => 1,
'exeout' => 1,
'includes' => 3,
'libout' => 1,
'libpaths' => 3,
'libs' => 2,
'lit_libs' => 2,
'macros' => 3,
'managed' => 1,
'pch_header' => 1,
'pch_source' => 1,
'postbuild' => 5,
'postclean' => 5,
'prebuild' => 5,
'pure_libs' => 2,
'recurse' => 1,
'recursive_includes' => 3,
'recursive_libpaths' => 3,
'requires' => 3,
'sharedname' => 1,
'staticflags' => 3,
'staticname' => 1,
'tagchecks' => 1,
'tagname' => 1,
'version' => 1,
'webapp' => 1,
);
## Custom definitions only
## Bit Meaning
## 0 Value is always an array
## 1 Value is an array and name gets 'outputext' converted to 'files'
## 2 Value is always scalar
## 3 Name can also be used in an 'optional' clause
## 4 Needs <%...%> conversion
my %customDefined = ('automatic_in' => 0x04,
'automatic_out' => 0x04,
'command' => 0x14,
'commandflags' => 0x14,
'dependent' => 0x14,
'dependent_libs' => 0x14,
'precommand' => 0x14,
'postcommand' => 0x14,
'inputext' => 0x01,
'libpath' => 0x04,
'output_follows_input' => 0x04,
'output_option' => 0x14,
'pch_postrule' => 0x04,
'pre_extension' => 0x08,
'source_pre_extension' => 0x08,
'template_pre_extension' => 0x08,
'header_pre_extension' => 0x08,
'inline_pre_extension' => 0x08,
'documentation_pre_extension' => 0x08,
'resource_pre_extension' => 0x08,
'generic_pre_extension' => 0x08,
'pre_filename' => 0x08,
'source_pre_filename' => 0x08,
'template_pre_filename' => 0x08,
'header_pre_filename' => 0x08,
'inline_pre_filename' => 0x08,
'documentation_pre_filename' => 0x08,
'resource_pre_filename' => 0x08,
'generic_pre_filename' => 0x08,
'pre_dirname' => 0x08,
'source_pre_dirname' => 0x08,
'template_pre_dirname' => 0x08,
'header_pre_dirname' => 0x08,
'inline_pre_dirname' => 0x08,
'documentation_pre_dirname' => 0x08,
'resource_pre_dirname' => 0x08,
'generic_pre_dirname' => 0x08,
'source_outputext' => 0x0a,
'template_outputext' => 0x0a,
'header_outputext' => 0x0a,
'inline_outputext' => 0x0a,
'documentation_outputext' => 0x0a,
'resource_outputext' => 0x0a,
'generic_outputext' => 0x0a,
);
## Custom sections as well as definitions
## Value Meaning
## 0 No modifications
## 1 Needs <%...%> conversion
my %custom = ('command' => 1,
'commandflags' => 1,
'dependent' => 1,
'dependent_libs'=> 1,
'gendir' => 0,
'precommand' => 1,
'postcommand' => 1,
);
## All matching assignment arrays will get these keywords
my @default_matching_assignments = ('recurse',
);
## Deal with these components in a special way
my %specialComponents = ('header_files' => 1,
'inline_files' => 1,
'template_files' => 1,
);
my %sourceComponents = ('source_files' => 1,
'template_files' => 1,
);
my $defgroup = 'default_group';
my $grouped_key = 'grouped_';
my $tikey = '/ti/';
## Matches with generic_outputext
my $generic_key = 'generic_files';
## These constants are used with the "project info" and
## must match the order that is defined by the call order
## of ProjectCreator::update_project_info(). This called
## order is determined by the TemplateParser.
##
## NOTE: If you are going to add a new constant, you must make it the
## numeric value of the CONFIGURATIONS constant and increment
## the existing CONFIGURATIONS value.
use constant PROJECT_NAME => 0;
use constant DEPENDENCIES => 1;
use constant PROJECT_GUID => 2;
use constant LANGUAGE => 3;
use constant CUSTOM_ONLY => 4;
use constant NO_CROSS_COMPILE => 5;
use constant MANAGED_PROJECT => 6;
use constant MAKE_GROUP => 7;
use constant CONFIGURATIONS => 8;
# ************************************************************
# C++ Specific Component Settings
# ************************************************************
## Resource files tag for C++
my $cppresource = 'resource_files';
## Valid component names within a project along with the valid file extensions
my %cppvc = ('source_files' => [ "\\.cpp", "\\.cxx", "\\.cc", "\\.c", "\\.C", ],
'template_files' => [ "_T\\.cpp", "_T\\.cxx", "_T\\.cc", "_T\\.c", "_T\\.C", "_t\\.cpp", "_t\\.cxx", "_t\\.cc", "_t\\.c", "_t\\.C", "\\.tpp" ],
'header_files' => [ "\\.h", "\\.hpp", "\\.hxx", "\\.hh", ],
'inline_files' => [ "\\.i", "\\.ipp", "\\.ixx", "\\.inl", ],
'documentation_files' => [ "README", "readme", "\\.doc", "\\.txt", "\\.html" ],
$cppresource => [ "\\.rc", ],
);
## Exclude these extensions when auto generating the component values
my %cppec = ('source_files' => $cppvc{'template_files'},
);
## These matching assignment arrays will get added, but only to the
## specific project component types.
my %cppma = ('source_files' => ['buildflags',
'managed',
'no_pch',
],
'header_files' => [ 'dependent_upon',
],
);
# ************************************************************
# C# Specific Component Settings
# ************************************************************
## Resource files tag for C#
my $csresource = 'resx_files';
## Valid component names within a project along with the valid file extensions
my %csvc = ('source_files' => [ "\\.cs" ],
'config_files' => [ "\\.config" ],
$csresource => [ "\\.resx", "\\.resources" ],
'aspx_files' => [ "\\.aspx" ],
'ico_files' => [ "\\.ico" ],
'documentation_files' => [ "README", "readme", "\\.doc", "\\.txt", "\\.html" ],
'embedded_resource_files' => [],
'resource_files' => [],
'page_files' => [],
'appdef_files' => [],
'splash_files' => [],
);
my %csma = ('source_files' => [ 'dependent_upon',
'subtype',
],
$csresource => [ 'dependent_upon',
'generates_source',
'subtype',
],
);
# ************************************************************
# Java Specific Component Settings
# ************************************************************
## Valid component names within a project along with the valid file extensions
my %jvc = ('source_files' => [ "\\.java" ],
'documentation_files' => [ "README", "readme", "\\.doc", "\\.txt", "\\.html" ],
);
# ************************************************************
# Visual Basic Specific Component Settings
# ************************************************************
## Resource files tag for VB
my $vbresource = 'resx_files';
## Valid component names within a project along with the valid file extensions
my %vbvc = ('source_files' => [ "\\.vb" ],
'config_files' => [ "\\.config" ],
$vbresource => [ "\\.resx" ],
'aspx_files' => [ "\\.aspx" ],
'ico_files' => [ "\\.ico" ],
'documentation_files' => [ "README", "readme", "\\.doc", "\\.txt", "\\.html" ],
);
my %vbma = ('source_files' => [ 'subtype' ],
);
# ************************************************************
# Language Specific Component Settings
# ************************************************************
# Index Description
# ----- -----------
# 0 File types
# 1 Files automatically excluded from source_files
# 2 Assignments available in standard file types
# 3 The entry point for executables
# 4 The language uses a C preprocessor
# 5 Name of the tag for 'resource_files' for this language
# * This is special because it gets treated like source_files in that
# a project with only these files is a library/exe not "custom only".
## NOTE: We call the constant as a function to support Perl 5.6.
my %language = (Creator::cplusplus() => [ \%cppvc, \%cppec, \%cppma, 'main',
1, $cppresource ],
Creator::csharp() => [ \%csvc, {}, \%csma, 'Main', 0,
$csresource ],
Creator::java() => [ \%jvc, {}, {}, 'main', 0 ],
Creator::vb() => [ \%vbvc, {}, \%vbma, 'Main', 0,
$vbresource ],
);
my %mains;
# ************************************************************
# Subroutine Section
# ************************************************************
sub new {
my($class, $global, $inc, $template, $ti, $dynamic, $static, $relative, $addtemp, $addproj, $progress, $toplevel, $baseprojs, $gfeature, $relative_f, $feature, $features, $hierarchy, $exclude, $makeco, $nmod, $applypj, $genins, $into, $language, $use_env, $expandvars, $gendot, $comments, $foreclipse, $pid) = @_;
my $self = $class->SUPER::new($global, $inc,
$template, $ti, $dynamic, $static,
$relative, $addtemp, $addproj,
$progress, $toplevel, $baseprojs,
$feature, $features,
$hierarchy, $nmod, $applypj,
$into, $language, $use_env,
$expandvars,
'project');
$self->{$self->{'type_check'}} = 0;
$self->{'feature_defined'} = 0;
$self->{'features_changed'} = undef;
$self->{'project_info'} = [];
$self->{'lib_locations'} = {};
$self->{'reading_parent'} = [];
$self->{'dll_exe_template_input'}= {};
$self->{'lib_exe_template_input'}= {};
$self->{'lib_template_input'} = {};
$self->{'dll_template_input'} = {};
$self->{'flag_overrides'} = {};
$self->{'custom_special_output'} = {};
$self->{'custom_special_depend'} = {};
$self->{'special_supplied'} = {};
$self->{'pctype'} = $self->extractType("$self");
$self->{'verbatim'} = {};
$self->{'verbatim_accessed'} = {$self->{'pctype'} => {}};
$self->{'defaulted'} = {};
$self->{'custom_types'} = {};
$self->{'parents_read'} = {};
$self->{'inheritance_tree'} = {};
$self->{'remove_files'} = {};
$self->{'expanded'} = {};
$self->{'dependency_attributes'} = {};
$self->{'gfeature_file'} = $gfeature;
$self->{'relative_file'} = $relative_f;
$self->{'feature_parser'} = $self->create_feature_parser($features,
$feature);
$self->{'sort_files'} = $self->sort_files();
$self->{'source_callback'} = undef;
$self->{'dollar_special'} = $self->dollar_special();
$self->{'generate_ins'} = $genins;
$self->{'addtemp_state'} = undef;
$self->{'command_subs'} = $self->get_command_subs();
$self->{'escape_spaces'} = $self->escape_spaces();
$self->{'current_template'} = undef;
$self->{'make_coexistence'} = $makeco;
$self->{'forcount'} = 0;
$self->add_default_matching_assignments();
$self->reset_generating_types();
$self->{'pid'} = $pid;
$self->{'llctr'} = 0; # counts the hash insertion order for mp-mpc
return $self;
}
sub is_keyword {
## Is the name passed in a known keyword for a project. This includes
## keywords mapped by Define_Custom or Modify_Custom.
my($self, $name) = @_;
return $self->{'valid_names'}->{$name};
}
sub read_global_configuration {
my $self = shift;
my $input = $self->get_global_cfg();
my $status = 1;
if (defined $input) {
## If it doesn't contain a path, search the include path
if ($input !~ /[\/\\]/) {
$input = $self->search_include_path($input);
$input = $self->get_global_cfg() if (!defined $input);
}
## Read and parse the global project file
$self->{'reading_global'} = 1;
$status = $self->parse_file($input);
$self->{'reading_global'} = 0;
}
return $status;
}
sub convert_to_template_assignment {
my($self, $name, $value, $calledfrom) = @_;
## If the value we are going to set for $name has been used as a
## scoped template variable, we need to hijack the whole assignment
## and turn it into a template variable assignment.
my $atemp = $self->get_addtemp();
foreach my $key (grep(/::$name$/, keys %$atemp)) {
$self->update_template_variable(0, $calledfrom, $key, $value);
}
}
sub create_recursive_settings {
my($self, $name, $value, $assign) = @_;
## Handle both recursive_includes and recursive_libpaths in one
## search and replace.
if ($name =~ s/^recursive_//) {
## This portion of code was lifted directly from Creator::relative()
## but modified to always expand the variables. We will turn the
## expanded values back into variables below and once they're passed
## off to the assignment processing code, they will be turned into
## relative values (if possible).
if (index($value, '$') >= 0) {
my $ovalue = $value;
my($rel, $how) = $self->get_initial_relative_values();
$value = $self->expand_variables($value, $rel, 0, undef, 1);
if ($ovalue eq $value || index($value, '$') >= 0) {
($rel, $how) = $self->get_secondary_relative_values();
$value = $self->expand_variables($value, $rel, 0, undef, 1, 1);
}
}
## Create an array out of the recursive directory list. Convert all
## of the relative or full path values back into $() values.
my @dirs = ();
my $elems = $self->create_array($value);
foreach my $elem (@$elems) {
my $dlist = $self->recursive_directory_list($elem, []);
if ($dlist eq '') {
## This directory doesn't exist, just add the original value
push(@dirs, $elem);
}
else {
## Create an array out of the directory list and add it to our
## array.
my $array = $self->create_array($dlist);
push(@dirs, @$array);
}
}
## We need to return a string, so we join it all together space
## separated.
$value = join(' ', $self->back_to_variable(\@dirs));
}
return $name, $value;
}
sub process_assignment {
my($self, $name, $value, $assign, $calledfrom) = @_;
$calledfrom = 0 if (!defined $calledfrom);
## See if the name is one of the special "recursive" settings. If so,
## fix up the value and change the name.
($name, $value) = $self->create_recursive_settings($name, $value, $assign);
if (defined $value) {
if ($name eq 'after') {
mpc_debug::chkpnt_pre_after_keyword_assignment($name, $value, $assign, $calledfrom);
## Support dependency attributes. They may or may not be used by
## the project or workspace creator implementation. They are
## stored separately from the dependencies themselves. Also, note
## that a value to be added may contain more than one element to be
## added. This function will be called for each one, so we only
## need to handle one at a time.
if ($value =~ s/(\s*([^:]+)):([^\s]+)/$1/) {
## The value may contain multiple projects. But, only one
## dependency attribute will be present at any time. So, once we
## get here, we need to remove any of the other projects from the
## front of the key string.
my $key = $2;
my $value = $3;
$key =~ s/.*\s+//;
$self->{'dependency_attributes'}->{$key} = $value;
}
## Check the after value and warn the user in the event that it
## contains a value that can not be used within a project name.
if (!$self->valid_project_name($value)) {
$self->warning("after '$value' contains an invalid project name in " .
$self->{'current_input'} . ' at line ' .
$self->get_line_number() . '.');
}
## Support the '*' mechanism as in the project name, to allow
## the user to correctly depend on another project within the same
## directory.
if (index($value, '*') >= 0) {
$value = $self->fill_type_name($value,
$self->get_default_project_name());
}
mpc_debug::chkpnt_post_after_keyword_assignment($name, $value, $assign, $calledfrom);
}
## Support the '*' mechanism for libs assignment as well.
elsif ($name eq 'libs' && index($value, '*') >= 0) {
$value = $self->fill_type_name($value, $self->get_default_project_name());
}
## If this particular project type does not consider the dollar sign
## special and the user has provided two dollarsigns as an escape, we
## will turn it into a single dollar sign.
if (!$self->{'dollar_special'} && index($value, '$$') >= 0) {
$value =~ s/\$\$/\$/g;
}
## If the assignment name is valid and requires parameter (<%...%>)
## replacement, then do so. But, only do so on actual keywords.
## User defined keywords must not have the parameters replaced in
## order for them to get the correct replacement values later on.
if (defined $validNames{$name} &&
($validNames{$name} & 0x04) == 0 && index($value, '<%') >= 0) {
$value = $self->replace_parameters($value, $self->{'command_subs'});
}
}
if ($calledfrom == 0) {
$self->convert_to_template_assignment($name, $value, $calledfrom);
}
## Call the base process_assigment() after we have modified the name and
## value.
$self->SUPER::process_assignment($name, $value, $assign);
## Support keyword mapping here only at the project level scope. The
## scoped keyword mapping is done through the parse_scoped_assignment()
## method.
if (!defined $assign || $assign == $self->get_assignment_hash()) {
my $mapped = $self->{'valid_names'}->{$name};
if (defined $mapped && UNIVERSAL::isa($mapped, 'ARRAY')) {
$self->parse_scoped_assignment($$mapped[0], 0,
$$mapped[1], $value,
$self->{'generated_exts'}->{$$mapped[0]});
}
}
}
sub process_assignment_add {
my($self, $name, $value, $assign) = @_;
## See if the name is one of the special "recursive" settings. If so,
## fix up the value and change the name.
($name, $value) = $self->create_recursive_settings($name, $value, $assign);
return $self->SUPER::process_assignment_add($name, $value, $assign);
}
sub process_assignment_sub {
my($self, $name, $value, $assign) = @_;
## See if the name is one of the special "recursive" settings. If so,
## fix up the value and change the name.
($name, $value) = $self->create_recursive_settings($name, $value, $assign);
## If the assignment name is valid and requires parameter (<%...%>)
## replacement, then do so. But, only do so on actual keywords.
## User defined keywords must not have the parameters replaced in
## order for them to get the correct replacement values later on.
if (defined $validNames{$name} &&
($validNames{$name} & 0x04) == 0 && index($value, '<%') >= 0) {
$value = $self->replace_parameters($value, $self->{'command_subs'});
}
return $self->SUPER::process_assignment_sub($name, $value, $assign);
}
sub addition_core {
my($self, $name, $value, $nval, $assign) = @_;
## If there is a previous value ($nval) and the keyword is going to be
## evaled, we need to separate the values with a command separator.
## This has to be done at the MPC level because it isn't always
## possible for the user to know if a value has already been added to
## the keyword (prebuild, postbuild and postclean).
if (defined $nval &&
defined $validNames{$name} && ($validNames{$name} & 4)) {
if ($self->preserve_assignment_order($name)) {
$value = '<%cmdsep%> ' . $value;
}
else {
$value .= '<%cmdsep%>';
}
}
## For an addition, we need to see if it is a project keyword being
## used within a 'specific' section. If it is, we may need to update
## scoped settings for that variable (which are in essence template
## variables).
$self->convert_to_template_assignment($name, $value, 1);
## Next, we just give everything to the base class method.
$self->SUPER::addition_core($name, $value, $nval, $assign);
}
sub subtraction_core {
my($self, $name, $value, $nval, $assign) = @_;
## For a subtraction, we need to see if it is a project keyword being
## used within a 'specific' section. If it is, we may need to update
## scoped settings for that variable (which are in essence template
## variables).
$self->convert_to_template_assignment($name, $value, -1);
## Next, we just give everything to the base class method.
$self->SUPER::subtraction_core($name, $value, $nval, $assign);
}
sub get_assignment_for_modification {
my($self, $name, $assign, $subtraction) = @_;
## If we weren't passed an assignment hash, then we need to
## look one up that may possibly correctly deal with keyword mappings
if (!defined $assign) {
my $mapped = $self->{'valid_names'}->{$name};
if (defined $mapped && UNIVERSAL::isa($mapped, 'ARRAY')) {
$name = $$mapped[1];
$assign = $self->{'generated_exts'}->{$$mapped[0]};
}
}
## Get the assignment value
my $value = $self->get_assignment($name, $assign);
## If we are involved in a subtraction, we get back a value and
## it's a scoped or mapped assignment, then we need to possibly
## expand any template variables. Otherwise, the subtractions
## may not work correctly.
if ($subtraction && defined $value && defined $assign) {
$value = $self->relative($value, 1);
}
return $value;
}
sub begin_project {
my($self, $parents) = @_;
my $status = 1;
my $error;
## Deal with the inheritance hierarchy first
## Add in the base projects from the command line
if (!$self->{'reading_global'} &&
!defined $self->{'reading_parent'}->[0]) {
my $baseprojs = $self->get_baseprojs();
if (defined $parents) {
StringProcessor::merge($parents, $baseprojs);
}
else {
$parents = $baseprojs;
}
}
if (defined $parents) {
foreach my $parent (@$parents) {
## Read in the parent onto ourself
my $file = $self->search_include_path(
"$parent.$BaseClassExtension");
if (!defined $file) {
$file = $self->search_include_path(
"$parent.$ProjectCreatorExtension");
}
if (defined $file) {
if (defined $self->{'reading_parent'}->[0]) {
if (StringProcessor::fgrep($file, $self->{'reading_parent'})) {
$status = 0;
$error = 'Cyclic inheritance detected: ' . $parent;
}
}
if ($status) {
if (!defined $self->{'parents_read'}->{$file}) {
$self->{'parents_read'}->{$file} = 1;
## Push the base project file onto the parent stack
push(@{$self->{'reading_parent'}}, $file);
## Collect up some information about the inheritance tree
my $tree = $self->{'current_input'};
if (!defined $self->{'inheritance_tree'}->{$tree}) {
$self->{'inheritance_tree'}->{$tree} = {};
}
my $hash = $self->{'inheritance_tree'}->{$tree};
foreach my $p (@{$self->{'reading_parent'}}) {
$$hash{$p} = {} if (!defined $$hash{$p});
$hash = $$hash{$p};
}
## Begin reading the parent
mpc_debug::chkpnt_pre_parse_base_project($file);
$status = $self->parse_file($file);
mpc_debug::chkpnt_post_parse_base_project($file, $status);
## Take the base project file off of the parent stack
pop(@{$self->{'reading_parent'}});
$error = "Invalid parent: $parent" if (!$status);
}
else {
## The base project has already been read. So, if
## we are reading the original project (not a parent base
## project), then the current base project is redundant.
if (!defined $self->{'reading_parent'}->[0]) {
$file =~ s/\.[^\.]+$//;
$self->information('Inheriting from \'' .
$self->mpc_basename($file) .
'\' in ' . $self->{'current_input'} .
' is redundant at line ' .
$self->get_line_number() . '.');
}
}
}
}
else {
$status = 0;
$error = "Unable to locate parent: $parent";
}
}
}
## Copy each value from global_assign into assign
if (!$self->{'reading_global'}) {
foreach my $key (keys %{$self->{'global_assign'}}) {
if (!defined $self->{'assign'}->{$key}) {
$self->{'assign'}->{$key} = $self->{'global_assign'}->{$key};
}
}
}
return $status, $error;
}
sub get_process_project_type {
my($self, $types) = @_;
my $type = '';
my $defcomp = $self->get_default_component_name();
foreach my $t (split(/\s*,\s*/, $types)) {
my $not = ($t =~ s/^!\s*//);
if ($not) {
if ($t eq $self->{'pctype'}) {
$type = '';
last;
}
else {
$type = $self->{'pctype'};
}
}
elsif ($t eq $self->{'pctype'} || $t eq $defcomp) {
$type = $t;
last;
}
}
return $type;
}
sub matches_specific_scope {
my($self, $elements) = @_;
## First check for properties that correspond to the current project
## type. Elements that begin with "prop:" indicate a property.
my $list = '';
my $props = $self->get_properties();
foreach my $prop (split(/\s*,\s*/, $elements)) {
my $not = ($prop =~ s/^!\s*//);
if ($prop =~/(.+):(.+)/) {
if ($1 eq 'prop') {
$prop = $2;
if ($not) {
return $self->{'pctype'} if (!$$props{$prop});
}
else {
return $self->{'pctype'} if ($$props{$prop});
}
}
else {
$self->warning("$prop is not recognized.");
}
}
else {
$list .= ($not ? '!' : '') . $prop . ',';
}
}
## If none of the elements match a property, then check the type
## against the current project type or the default component name
## (which is what it would be set to if a specific clause is used with
## out parenthesis).
my $type = $self->get_process_project_type($list);
return $self->{'pctype'} if ($type eq $self->{'pctype'} ||
$type eq $self->get_default_component_name());
## Nothing matched
return undef;
}
sub parse_line {
my($self, $ih, $line) = @_;
my($status,
$errorString,
@values) = $self->parse_known($line, $ih);
## parse_known() passes back an array of values
## that make up the contents of the line parsed.
## The array can have 0 to 4 items. The first,
## if defined, is always an identifier of some
## sort.
if ($status && defined $values[0]) {
if ($values[0] eq $self->{'grammar_type'}) {
my $name = $values[1];
my $typecheck = $self->{'type_check'};
if (defined $name && $name eq '}') {
## Project Ending
if (!defined $self->{'reading_parent'}->[0] &&
!$self->{'reading_global'}) {
## Call into the project type's pre-generation hook.
$self->pre_generation();
## Fill in all the default values
$self->generate_defaults();
## Perform any additions, subtractions
## or overrides for the project values.
my $addproj = $self->get_addproj();
foreach my $ap (keys %$addproj) {
if (defined $self->{'valid_names'}->{$ap}) {
foreach my $val (@{$$addproj{$ap}}) {
if ($$val[0] > 0) {
$self->process_assignment_add($ap, $$val[1]);
}
elsif ($$val[0] < 0) {
$self->process_assignment_sub($ap, $$val[1]);
}
else {
$self->process_assignment($ap, $$val[1]);
}
}
}
else {
$errorString = 'Invalid ' .
"assignment modification name: $ap";
$status = 0;
}
}
if ($status) {
## Generate default target names after all source files are added
## and after we've added in all of the options from the
## command line. If the user set exename on the command line
## and no "main" is found, sharedname will be set too and
## most templates do not handle that well.
$self->generate_default_target_names();
## End of project; Write out the file.
($status, $errorString) = $self->write_project();
## write_project() can return 0 for error, 1 for project
## was written and 2 for project was skipped
if ($status == 1) {
## Save the library name and location
foreach my $name ('sharedname', 'staticname') {
my $val = $self->get_assignment($name);
if (defined $val) {
my $cwd = $self->getcwd();
my $start = $self->getstartdir();
my $amount = 0;
if ($cwd eq $start) {
$amount = length($start);
}
elsif (index($cwd, $start) == 0) {
$amount = length($start) + 1;
}
if ($self->{'pid'} eq 'child') {
$self->{'lib_locations'}->{$val} =
++$self->{'llctr'} . '|' .
substr($cwd, $amount);
}
else {
$self->{'lib_locations'}->{$val} =
substr($cwd, $amount);
}
last;
}
}
## Check for unused verbatim markers
foreach my $key (keys %{$self->{'verbatim'}}) {
if (defined $self->{'verbatim_accessed'}->{$key}) {
foreach my $ikey (keys %{$self->{'verbatim'}->{$key}}) {
if (!defined $self->{'verbatim_accessed'}->{$key}->{$ikey}) {
$self->warning("Marker $ikey does not exist.");
}
}
}
}
}
## Reset all of the project specific data. I am explicitly
## not resetting dependency_attributes. It is necessary that
## this information stay for the life of the ProjectCreator
## object so that the WorkspaceCreator can have access to the
## information.
foreach my $key (keys %{$self->{'valid_components'}}) {
delete $self->{$key};
delete $self->{'defaulted'}->{$key};
}
if (defined $self->{'addtemp_state'}) {
$self->restore_state($self->{'addtemp_state'}, 'addtemp');
$self->{'addtemp_state'} = undef;
}
$self->{'assign'} = {};
$self->{'verbatim'} = {};
$self->{'verbatim_accessed'} = {$self->{'pctype'} => {}};
$self->{'special_supplied'} = {};
$self->{'flag_overrides'} = {};
$self->{'parents_read'} = {};
$self->{'inheritance_tree'} = {};
$self->{'remove_files'} = {};
$self->{'custom_special_output'} = {};
$self->{'custom_special_depend'} = {};
$self->{'expanded'} = {};
$self->reset_generating_types();
}
}
$self->{$typecheck} = 0;
}
else {
## Project Beginning
($status, $errorString) = $self->begin_project($values[2]);
## Set up the default project name
if ($status) {
if (defined $name) {
if ($self->valid_project_name($name)) {
## We should only set the project name if we are not
## reading in a parent project.
if (!defined $self->{'reading_parent'}->[0]) {
$name =~ s/^\(\s*//;
$name =~ s/\s*\)$//;
$name = $self->transform_file_name($name);
## Replace any *'s with the default name
if (index($name, '*') >= 0) {
$name = $self->fill_type_name(
$name,
$self->get_default_project_name());
}
$self->set_project_name($name);
}
else {
$self->warning("Ignoring project name " .
"$name in a base project.");
}
}
else {
$status = 0;
$errorString = 'Projects can not have the following in ' .
'the name: / \\ = ? : & " < > | # %';
}
}
}
## Signify that we have a valid project
$self->{$typecheck} = 1 if ($status);
}
}
elsif ($values[0] eq '0') {
## $values[1] = name; $values[2] = value
if (defined $self->{'valid_names'}->{$values[1]}) {
$self->process_assignment($values[1], $values[2]);
}
else {
$errorString = "Invalid assignment name: '$values[1]'";
$status = 0;
}
}