summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelliott_c <ocielliottc@users.noreply.github.com>2003-04-02 16:19:47 +0000
committerelliott_c <ocielliottc@users.noreply.github.com>2003-04-02 16:19:47 +0000
commitcab47b77feabc39e2334024a6ca55a8a8227ecc8 (patch)
treef178cdd2038673b6501e452c81edaf6133ce5a49
parent1665894bc14357c16fddaa26b5313c9ccbe2c206 (diff)
downloadMPC-cab47b77feabc39e2334024a6ca55a8a8227ecc8.tar.gz
ChangeLogTag: Wed Apr 2 10:17:59 2003 Chad Elliott <elliott_c@ociweb.com>
-rw-r--r--modules/Creator.pm16
-rw-r--r--modules/Options.pm23
-rw-r--r--modules/ProjectCreator.pm11
-rw-r--r--modules/WorkspaceCreator.pm205
4 files changed, 166 insertions, 89 deletions
diff --git a/modules/Creator.pm b/modules/Creator.pm
index a9905bff..a9b0170d 100644
--- a/modules/Creator.pm
+++ b/modules/Creator.pm
@@ -29,6 +29,8 @@ sub new {
my($inc) = shift;
my($template) = shift;
my($ti) = shift;
+ my($dynamic) = shift;
+ my($static) = shift;
my($relative) = shift;
my($addtemp) = shift;
my($addproj) = shift;
@@ -56,6 +58,8 @@ sub new {
$self->{'global_assign'} = {};
$self->{'assign'} = {};
$self->{'baseprojs'} = $baseprojs;
+ $self->{'dynamic'} = $dynamic;
+ $self->{'static'} = $static;
return $self;
}
@@ -522,6 +526,18 @@ sub get_baseprojs {
return $self->{'baseprojs'};
}
+
+sub get_dynamic {
+ my($self) = shift;
+ return $self->{'dynamic'};
+}
+
+
+sub get_static {
+ my($self) = shift;
+ return $self->{'static'};
+}
+
# ************************************************************
# Virtual Methods To Be Overridden
# ************************************************************
diff --git a/modules/Options.pm b/modules/Options.pm
index 2b990657..db3295ba 100644
--- a/modules/Options.pm
+++ b/modules/Options.pm
@@ -271,4 +271,27 @@ sub options {
}
+sub is_set {
+ my($self) = shift;
+ my($key) = shift;
+ my($options) = shift;
+
+ if (UNIVERSAL::isa($options->{$key}, 'ARRAY')) {
+ if (defined $options->{$key}->[0]) {
+ return 'ARRAY';
+ }
+ }
+ elsif (UNIVERSAL::isa($options->{$key}, 'HASH')) {
+ my(@keys) = keys %{$options->{$key}};
+ if (defined $keys[0]) {
+ return 'HASH';
+ }
+ }
+ elsif (defined $options->{$key}) {
+ return 'SCALAR';
+ }
+
+ return undef;
+}
+
1;
diff --git a/modules/ProjectCreator.pm b/modules/ProjectCreator.pm
index f04353b4..3e784b89 100644
--- a/modules/ProjectCreator.pm
+++ b/modules/ProjectCreator.pm
@@ -86,8 +86,8 @@ sub new {
my($toplevel) = shift;
my($baseprojs) = shift;
my($self) = Creator::new($class, $global, $inc,
- $template, $ti, $relative,
- $addtemp, $addproj,
+ $template, $ti, $dynamic, $static,
+ $relative, $addtemp, $addproj,
$progress, $toplevel, $baseprojs,
'project');
@@ -101,8 +101,6 @@ sub new {
$self->{'idl_defaulted'} = 0;
$self->{'source_defaulted'} = 0;
$self->{'writing_type'} = 0;
- $self->{'want_dynamic_projects'} = $dynamic;
- $self->{'want_static_projects'} = $static;
$self->{'flag_overrides'} = {};
$self->{'special_supplied'} = {};
@@ -1365,15 +1363,14 @@ sub write_project {
if ($self->need_to_write_project()) {
## Writing the non-static file so set it to 0
- if ($self->{'want_dynamic_projects'}) {
+ if ($self->get_dynamic()) {
$self->{'writing_type'} = 0;
$self->process_assignment('project_name',
$prjname . $self->get_type_append());
($status, $error) = $self->write_output_file($name);
}
- if ($status && $self->{'want_static_projects'} &&
- $self->separate_static_project()) {
+ if ($status && $self->get_static() && $self->separate_static_project()) {
## Set the project name back to what it originally was
$self->process_assignment('project_name', $prjname);
$name = $self->transform_file_name($self->static_project_file_name());
diff --git a/modules/WorkspaceCreator.pm b/modules/WorkspaceCreator.pm
index 232bc2af..242ba847 100644
--- a/modules/WorkspaceCreator.pm
+++ b/modules/WorkspaceCreator.pm
@@ -25,13 +25,18 @@ use vars qw(@ISA);
# Data Section
# ************************************************************
-my($wsext) = 'mwc';
+my($wsext) = 'mwc';
+my($wsbase) = 'mwb';
## Valid names for assignments within a workspace
my(%validNames) = ('cmdline' => 1,
'implicit' => 1,
);
+## Singleton hash maps of project information
+my(%allprinfo) = ();
+my(%allprojects) = ();
+
# ************************************************************
# Subroutine Section
# ************************************************************
@@ -51,8 +56,8 @@ sub new {
my($toplevel) = shift;
my($baseprojs) = shift;
my($self) = Creator::new($class, $global, $inc,
- $template, $ti, $relative,
- $addtemp, $addproj,
+ $template, $ti, $dynamic, $static,
+ $relative, $addtemp, $addproj,
$progress, $toplevel, $baseprojs,
'workspace');
my($typecheck) = $self->{'type_check'};
@@ -63,8 +68,7 @@ sub new {
$self->{'project_info'} = {};
$self->{'reading_parent'} = [];
$self->{'project_files'} = [];
- $self->{'dynamic'} = $dynamic;
- $self->{'static'} = $static;
+ $self->{'cacheok'} = 1;
return $self;
}
@@ -89,7 +93,7 @@ sub parse_line {
## Fill in all the default values
$self->generate_defaults();
- ## End of project; Have subclass write out the file
+ ## End of workspace; Have subclass write out the file
## Generate the project files
my($gstat, $generator) = $self->generate_project_files();
if ($gstat) {
@@ -116,12 +120,15 @@ sub parse_line {
if (defined $parents) {
foreach my $parent (@$parents) {
## Read in the parent onto ourself
- my($file) = $self->search_include_path("$parent.$wsext");
+ my($file) = $self->search_include_path("$parent.$wsbase");
+ if (!defined $file) {
+ $file = $self->search_include_path("$parent.$wsext");
+ }
if (defined $file) {
my($rp) = $self->{'reading_parent'};
push(@$rp, 1);
- $self->parse_file("$parent.$wsext");
+ $self->parse_file($file);
pop(@$rp);
if (!$status) {
$errorString = "ERROR: Invalid parent: $parent";
@@ -316,26 +323,32 @@ sub write_workspace {
my($status) = 1;
if ($self->get_toplevel()) {
- my($fh) = new FileHandle();
my($name) = $self->transform_file_name($self->workspace_file_name());
- my($dir) = dirname($name);
+ if (defined $self->{'projects'}->[0]) {
+ my($fh) = new FileHandle();
+ my($dir) = dirname($name);
- if ($dir ne '.') {
- mkpath($dir, 0, 0777);
- }
- if (open($fh, ">$name")) {
- $self->pre_workspace($fh);
- $self->write_comps($fh, $generator);
- $self->post_workspace($fh);
- close($fh);
-
- if ($addfile) {
- $self->add_file_written($name);
+ if ($dir ne '.') {
+ mkpath($dir, 0, 0777);
+ }
+ if (open($fh, ">$name")) {
+ $self->pre_workspace($fh);
+ $self->write_comps($fh, $generator);
+ $self->post_workspace($fh);
+ close($fh);
+
+ if ($addfile) {
+ $self->add_file_written($name);
+ }
+ }
+ else {
+ print STDERR "ERROR: Unable to open $name for output\n";
+ $status = 0;
}
}
else {
- print STDERR "ERROR: Unable to open $name for output\n";
- $status = 0;
+ print "WARNING: No projects were created.\n" .
+ " Workspace $name has not been created.\n";
}
}
@@ -351,9 +364,15 @@ sub save_project_info {
my($projects) = shift;
my($pi) = shift;
my($c) = 0;
+
+ ## For each file written
foreach my $pj (@$gen) {
+ ## Save the full path to the project file in the array
my($full) = ($dir ne '.' ? "$dir/" : '') . $pj;
push(@$projects, $full);
+
+ ## Get the corresponding generated project info and save it
+ ## in the hash map keyed on the full project file name
$$pi{$full} = $$gpi[$c];
$c++;
}
@@ -361,57 +380,81 @@ sub save_project_info {
sub generate_project_files {
- my($self) = shift;
- my($status) = 0;
- my(@projects) = ();
- my(%pi) = ();
- my($generator) = $self->project_creator();
- my($cwd) = $self->getcwd();
- my($impl) = $self->get_assignment('implicit');
+ my($self) = shift;
+ my($status) = 0;
+ my(@projects) = ();
+ my(%pi) = ();
+ my($generator) = $self->project_creator();
+ my($cwd) = $self->getcwd();
+ my($impl) = $self->get_assignment('implicit');
+ my($postkey) = $generator->get_dynamic() .
+ $generator->get_static() . "-$self";
+
+ ## Remove the address portion of the $self string
+ $postkey =~ s/=.*//;
foreach my $ofile (@{$self->{'project_files'}}) {
my($file) = $ofile;
my($dir) = dirname($file);
+ ## If we are generating implicit projects and the file is a
+ ## directory, then we set the dir to the file and empty the file
if ($impl && -d $file) {
$dir = $file;
$file = '';
}
+ ## Generate the key for this project file
+ my($prkey) = $self->getcwd() . "/$file-$postkey";
+
## We must change to the subdirectory for
## which this project file is intended
if ($self->cd($dir)) {
- $status = $generator->generate(basename($file));
-
- ## If any one project file fails, then stop
- ## processing altogether.
- if (!$status) {
- return $status, $generator;
+ my($gen) = [];
+ my($gpi) = [];
+ if ($self->{'cacheok'} && defined $allprojects{$prkey}) {
+ $gen = $allprojects{$prkey};
+ $gpi = $allprinfo{$prkey};
+ $status = 1;
}
+ else {
+ $status = $generator->generate(basename($file));
+
+ ## If any one project file fails, then stop
+ ## processing altogether.
+ if (!$status) {
+ return $status, $generator;
+ }
- ## Get the individual project information and
- ## generated file name(s)
- my($gen) = $generator->get_files_written();
- my($gpi) = $generator->get_project_info();
-
- ## If we need to generate a workspace file per project
- ## then we generate a temporary project info and projects
- ## array and call write_project().
- if ($dir ne '.' && defined $$gen[0] && $self->workspace_per_project()) {
- my(%perpi) = ();
- my(@perprojects) = ();
- $self->save_project_info($gen, $gpi, '.', \@perprojects, \%perpi);
-
- ## Set our per project information
- $self->{'projects'} = \@perprojects;
- $self->{'project_info'} = \%perpi;
-
- ## Write our per project workspace
- $self->write_workspace($generator);
-
- ## Reset our project information to empty
- $self->{'projects'} = [];
- $self->{'project_info'} = {};
+ ## Get the individual project information and
+ ## generated file name(s)
+ $gen = $generator->get_files_written();
+ $gpi = $generator->get_project_info();
+
+ ## If we need to generate a workspace file per project
+ ## then we generate a temporary project info and projects
+ ## array and call write_project().
+ if ($dir ne '.' && defined $$gen[0] && $self->workspace_per_project()) {
+ my(%perpi) = ();
+ my(@perprojects) = ();
+ $self->save_project_info($gen, $gpi, '.', \@perprojects, \%perpi);
+
+ ## Set our per project information
+ $self->{'projects'} = \@perprojects;
+ $self->{'project_info'} = \%perpi;
+
+ ## Write our per project workspace
+ $self->write_workspace($generator);
+
+ ## Reset our project information to empty
+ $self->{'projects'} = [];
+ $self->{'project_info'} = {};
+ }
+
+ if ($self->{'cacheok'}) {
+ $allprojects{$prkey} = $gen;
+ $allprinfo{$prkey} = $gpi;
+ }
}
$self->cd($cwd);
$self->save_project_info($gen, $gpi, $dir, \@projects, \%pi);
@@ -441,18 +484,6 @@ sub get_project_info {
}
-sub get_dynamic {
- my($self) = shift;
- return $self->{'dynamic'};
-}
-
-
-sub get_static {
- my($self) = shift;
- return $self->{'static'};
-}
-
-
sub sort_dependencies {
my($self) = shift;
my($projects) = shift;
@@ -514,6 +545,9 @@ sub process_cmdline {
my($self) = shift;
my($parameters) = shift;
+ ## It's ok to use the cache
+ $self->{'cacheok'} = 1;
+
my($cmdline) = $self->get_assignment('cmdline');
if (defined $cmdline && $cmdline ne '') {
my($args) = $self->create_array($cmdline);
@@ -536,20 +570,16 @@ sub process_cmdline {
my($options) = $self->options('MWC', {}, 0, @$args);
if (defined $options) {
foreach my $key (keys %$options) {
- if (UNIVERSAL::isa($options->{$key}, 'ARRAY')) {
- if (defined $options->{$key}->[0]) {
- push(@{$parameters->{$key}}, @{$options->{$key}});
- }
+ my($type) = $self->is_set($key, $options);
+ if ($type eq 'ARRAY') {
+ push(@{$parameters->{$key}}, @{$options->{$key}});
}
- elsif (UNIVERSAL::isa($options->{$key}, 'HASH')) {
- my(@keys) = keys %{$options->{$key}};
- if (defined $keys[0]) {
- foreach my $hk (keys %{$options->{$key}}) {
- $parameters->{$key}->{$hk} = $options->{$key}->{$hk};
- }
+ elsif ($type eq 'HASH') {
+ foreach my $hk (keys %{$options->{$key}}) {
+ $parameters->{$key}->{$hk} = $options->{$key}->{$hk};
}
}
- elsif (defined $options->{$key}) {
+ elsif ($type eq 'SCALAR') {
$parameters->{$key} = $options->{$key};
}
}
@@ -565,6 +595,17 @@ sub process_cmdline {
$self->optionError('Command line files ' .
'specified in a workspace are ignored');
}
+
+ ## Determine if it's ok to use the cache
+ my(@cacheInvalidating) = ('global', 'include', 'baseprojs',
+ 'template', 'ti', 'relative',
+ 'addtemp', 'addproj');
+ foreach my $key (@cacheInvalidating) {
+ if ($self->is_set($key, $options)) {
+ $self->{'cacheok'} = 0;
+ last;
+ }
+ }
}
}
}