📄 projectcreator.pm
字号:
my($created) = "$file$1";
$created =~ s/\\//g;
if (!$self->already_added($array, $created)) {
if (defined $ofile) {
$created = $self->prepend_gendir($created, $ofile, $gentype);
}
push(@$array, $created);
}
last;
}
}
}
}
}
}
sub add_corresponding_component_files {
my($self) = shift;
my($ftags) = shift;
my($tag) = shift;
my(@all) = ();
my($names) = undef;
foreach my $filetag (@$ftags) {
$names = $self->{$filetag};
foreach my $name (keys %$names) {
foreach my $comp (keys %{$$names{$name}}) {
foreach my $sfile (@{$$names{$name}->{$comp}}) {
push(@all, $sfile);
$all[$#all] =~ s/\.[^\.]+$//;
}
}
}
}
my(@exts) = ();
foreach my $ext (@{$self->{'valid_components'}->{$tag}}) {
push(@exts, $ext);
$exts[$#exts] =~ s/\\//g;
}
$names = $self->{$tag};
foreach my $name (keys %$names) {
foreach my $comp (keys %{$$names{$name}}) {
my($array) = $$names{$name}->{$comp};
my(%scfiles) = ();
@scfiles{@$array} = ();
foreach my $sfile (@all) {
my($found) = 0;
foreach my $ext (@exts) {
if (exists $scfiles{"$sfile$ext"}) {
$found = 1;
last;
}
}
if (!$found) {
foreach my $ext (@exts) {
if (-r "$sfile$ext") {
push(@$array, "$sfile$ext");
$found = 1;
last;
}
}
if (!$found) {
foreach my $gentype (keys %{$self->{'generated_exts'}}) {
$self->list_generated_file($gentype, $tag, $array, $sfile);
}
}
}
}
}
}
}
sub get_default_project_name {
my($self) = shift;
my($name) = $self->{'current_input'};
if ($name eq '') {
$name = $self->transform_file_name($self->base_directory());
}
else {
## Since files on UNIX can have back slashes, we transform them
## into underscores.
$name =~ s/\\/_/g;
## Convert then name to a usable name
$name = $self->transform_file_name($name);
## Take off the extension
$name =~ s/\.[^\.]+$//;
}
return $name;
}
sub generate_defaults {
my($self) = shift;
## Generate default project name
if (!defined $self->get_assignment('project_name')) {
$self->set_project_name($self->get_default_project_name());
}
## Generate the default pch file names (if needed)
my(@files) = $self->generate_default_file_list('.', $self->{'exclude'});
$self->generate_default_pch_filenames(\@files);
## If the pch file names are empty strings then we need to fix that
$self->fix_pch_filenames();
## Generate default components, but %specialComponents
## are skipped in the initial default components generation
$self->generate_default_components(\@files);
## Remove source files that are also listed in the template files
## If we do not do this, then generated projects can be invalid.
$self->remove_duplicated_files('source_files', 'template_files');
## If pch files are listed in header_files or source_files more than
## once, we need to remove the extras
$self->remove_extra_pch_listings();
## Generate the default generated list of source files
## only if we defaulted the generated file list
foreach my $gentype (keys %{$self->{'generated_exts'}}) {
$self->list_default_generated($gentype, ['source_files']);
}
## Add %specialComponents files based on the
## source_components (i.e. .h and .i or .inl based on .cpp)
foreach my $tag (keys %specialComponents) {
$self->add_corresponding_component_files(['source_files',
'template_files'], $tag);
}
## Now, if the %specialComponents are still empty
## then take any file that matches the components extension
foreach my $tag (keys %specialComponents) {
if (!$self->{'special_supplied'}->{$tag}) {
my($names) = $self->{$tag};
if (defined $names) {
foreach my $name (keys %$names) {
my($comps) = $$names{$name};
foreach my $comp (keys %$comps) {
my($array) = $$comps{$comp};
if (!defined $$array[0] ||
$self->{'defaulted'}->{'source_files'}) {
$self->generate_default_components(\@files, $tag);
}
}
}
}
}
}
## Generate default target names after all source files are added
$self->generate_default_target_names();
}
sub set_project_name {
my($self) = shift;
my($name) = shift;
if ($self->get_apply_project()) {
my($nmod) = $self->get_name_modifier();
if (defined $nmod) {
$nmod =~ s/\*/$name/g;
$name = $nmod;
}
}
$self->process_assignment('project_name', $name);
}
sub project_name {
my($self) = shift;
return $self->get_assignment('project_name');
}
sub lib_target {
my($self) = shift;
return (defined $self->get_assignment('sharedname') ||
defined $self->get_assignment('staticname'));
}
sub exe_target {
my($self) = shift;
return (defined $self->get_assignment('exename'));
}
sub get_component_list {
my($self) = shift;
my($tag) = shift;
my($noconvert) = shift;
my($names) = $self->{$tag};
my(@list) = ();
foreach my $name (keys %$names) {
foreach my $key (keys %{$$names{$name}}) {
push(@list, @{$$names{$name}->{$key}});
}
}
## By default, if 'convert_slashes' is true, then we convert slashes
## to backslashes. There are cases where we do not want to convert
## the slashes, in that case get_component_list() was called with
## an additional parameter indicating this.
if (!$noconvert && $self->{'convert_slashes'}) {
for(my $i = 0; $i <= $#list; $i++) {
$list[$i] = $self->slash_to_backslash($list[$i]);
}
}
if ($self->{'sort_files'}) {
@list = sort { $self->file_sorter($a, $b) } @list;
}
return @list;
}
sub check_custom_output {
my($self) = shift;
my($based) = shift;
my($pf) = shift;
my($cinput) = shift;
my($type) = shift;
my($comps) = shift;
my(@outputs) = ();
my($gen) = $self->{'generated_exts'}->{$based};
if (defined $gen->{$type}) {
foreach my $pe (@{$gen->{'pre_extension'}}) {
foreach my $ext (@{$gen->{$type}}) {
my($ge) = "$pe$ext";
$ge =~ s/\\//g;
my($built) = "$pf$cinput$ge";
if (@$comps == 0) {
push(@outputs, $built);
last;
}
elsif (defined $specialComponents{$type} &&
!$self->{'special_supplied'}->{$type}) {
push(@outputs, $built);
last;
}
else {
my($base) = $built;
if ($self->{'convert_slashes'}) {
$base =~ s/\\/\//g;
}
my($re) = $self->escape_regex_special(basename($base));
foreach my $c (@$comps) {
## We only match if the built file name matches from
## beginning to end or from a slash to the end.
if ($c =~ /^$re$/ || $c =~ /[\/\\]$re$/) {
push(@outputs, $built);
last;
}
}
}
}
}
}
return @outputs;
}
sub get_special_value {
my($self) = shift;
my($type) = shift;
my($cmd) = shift;
my($based) = shift;
if ($type =~ /^custom_type/) {
return $self->get_custom_value($cmd, $based);
}
elsif ($type =~ /^grouped_/) {
return $self->get_grouped_value($type, $cmd, $based);
}
return undef;
}
sub get_grouped_value {
my($self) = shift;
my($type) = shift;
my($cmd) = shift;
my($based) = shift;
my($value) = undef;
## Make it all lowercase
$type = lc($type);
## Remove the grouped_ part
$type =~ s/^$grouped_key//;
## Add the s if it isn't there
if ($type !~ /s$/) {
$type .= 's';
}
my($names) = $self->{$type};
if ($cmd eq 'files') {
foreach my $name (keys %$names) {
my($comps) = $$names{$name};
foreach my $comp (keys %$comps) {
if ($comp eq $based) {
$value = $$comps{$comp};
last;
}
}
}
}
elsif ($cmd eq 'component_name') {
## If there is more than one name, then we will need
## to deal with that at a later time.
foreach my $name (keys %$names) {
$value = $name;
}
}
return $value;
}
sub get_custom_value {
my($self) = shift;
my($cmd) = shift;
my($based) = shift;
my($value) = undef;
if ($cmd eq 'input_files') {
my($generic) = 'generic_files'; ## Matches with generic_outputext
my(@array) = $self->get_component_list($based);
$value = \@array;
$self->{'custom_output_files'} = {};
my(%vcomps) = ();
foreach my $vc (keys %{$self->{'valid_components'}}, $generic) {
my(@comps) = $self->get_component_list($vc);
$vcomps{$vc} = \@comps;
}
foreach my $input (@array) {
my(@outputs) = ();
my($cinput) = $input;
$cinput =~ s/\.[^\.]+$//;
foreach my $pf (@{$self->{'generated_exts'}->{$based}->{'pre_filename'}}) {
foreach my $vc (keys %{$self->{'valid_components'}}, $generic) {
push(@outputs,
$self->check_custom_output($based, $pf,
$cinput, $vc, $vcomps{$vc}));
}
}
$self->{'custom_output_files'}->{$input} = \@outputs;
}
}
elsif ($cmd eq 'output_files') {
# Generate output files based on $based
if (defined $self->{'custom_output_files'}) {
$value = $self->{'custom_output_files'}->{$based};
}
}
elsif ($cmd eq 'inputexts') {
my(@array) = @{$self->{'valid_components'}->{$based}};
foreach my $val (@array) {
$val =~ s/\\\.//g;
}
$value = \@array;
}
elsif (defined $custom{$cmd} ||
(defined $customDefined{$cmd} && $customDefined{$cmd} == 1)) {
$value = $self->get_assignment($cmd,
$self->{'generated_exts'}->{$based});
}
return $value;
}
sub check_features {
my($self) = shift;
my($requires) = shift;
my($avoids) = shift;
my($info) = shift;
my($status) = 1;
my($why) = undef;
if (defined $requires) {
foreach my $require (split(/\s+/, $requires)) {
my($fval) = $self->{'feature_parser'}->get_value($require);
## By default, if the feature is not listed, then it is enabled.
if (defined $fval && !$fval) {
$why = "requires $require";
$status = 0;
last;
}
}
}
## If it passes the requires, then check the avoids
if ($status) {
if (defined $avoids) {
foreach my $avoid (split(/\s+/, $avoids)) {
my($fval) = $self->{'feature_parser'}->get_value($avoid);
## By default, if the feature is not listed, then it is enabled.
if (!defined $fval || $fval) {
$why = "avoids $avoid";
$status = 0;
last;
}
}
}
}
if ($info && !$status) {
$self->diagnostic("Skipping " . $self->get_assignment('project_name') .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -