Kaydet (Commit) 5451a1f7 authored tarafından Vladimir Glazunov's avatar Vladimir Glazunov

CWS-TOOLING: integrate CWS buildtool09

...@@ -342,102 +342,19 @@ sub rename_file { ...@@ -342,102 +342,19 @@ sub rename_file {
}; };
sub generate_config_file { sub generate_config_file {
my $source_config = SourceConfig -> new(); my $source_config = SourceConfig->new();
$source_config_file = $source_config->get_config_file_path(); $source_config->add_active_modules([keys %add_to_config], 1) if (scalar %add_to_config);
my $temp_config_file = File::Temp::tmpnam($ENV{TMP}); $source_config->remove_activated_modules([keys %remove_from_config], 1) if (scalar %remove_from_config);
my @config_content_new = (); $source_config->remove_all_activated_modules() if ($clear_config);
my $addition_message;
my $removal_message;
my %present_modules = ();
if ($source_config_file) {
open(SOURCE_CONFIG_FILE, $source_config_file);
my @config_content = <SOURCE_CONFIG_FILE>;
close SOURCE_CONFIG_FILE;
my ($module_section, $repository_section);
foreach (@config_content) {
if ((!/^\S+/)||(/^\s*#+/)) {
push(@config_content_new, $_);
next;
}
if (/^\[repositories\]\s*(\s+#)*/) {
if ($module_section) {
$addition_message = add_modules_to_source_config(\%add_to_config, \@config_content_new);
};
$module_section = 0;
$repository_section = 1;
push(@config_content_new, $_);
next;
};
if (/^\[modules\]\s*(\s+#)*/) {
$module_section = 1;
$repository_section = 0;
push(@config_content_new, $_);
next;
};
if ($module_section && /\s*(\S+)=active\s*(\s+#)*/) {
if ($clear_config || defined $remove_from_config{$1}) {
delete $remove_from_config{$1};
$removal_message .= "$1 ";
} else {
push(@config_content_new, $_);
if (defined $add_to_config{$1} && !$prepare) {
push(@warnings, "Module $1 already activated in $source_config_file\n");
delete $add_to_config{$1};
}
};
} else {
push(@config_content_new, $_);
};
};
if (keys %add_to_config) {
if (!$module_section) {
push(@config_content_new, "[modules]\n");
};
$addition_message = add_modules_to_source_config(\%add_to_config, \@config_content_new);
};
} else {
if ($clear_config || scalar %remove_from_config) {
print_error('No source config file found');
};
$source_config_file = $source_config->get_config_file_default_path();
push(@config_content_new, "[modules]\n");
$addition_message = add_modules_to_source_config(\%add_to_config, \@config_content_new);
};
die("Cannot open $temp_config_file") if (!open(NEW_CONFIG, ">$temp_config_file"));
print NEW_CONFIG $_ foreach (@config_content_new);
close NEW_CONFIG;
rename_file($temp_config_file, $source_config_file, 1);
foreach (keys %remove_from_config) {
push(@warnings, "Module(s) $_ not found in " . $source_config_file . "\n");
};
print_warnings();
print $addition_message if ($addition_message);
print "Module(s):\n$removal_message\nremoved from $source_config_file\n" if ($removal_message);
}; };
#
# Add modules from the passed hash to the array of config strigns
#
sub add_modules_to_source_config {
my ($modules_hash_ref, $config_content_new) = @_;
my $message;
foreach (keys %$modules_hash_ref) {
push(@$config_content_new, "$_=active\n");
$message .= "$_ ";
};
if ($message) {
return "Module(s):\n" .$message . "\nare added to the " . $source_config_file . "\n\n";
} else {
return '';
};
};
sub start_interactive { sub start_interactive {
$pid = open(HTML_PIPE, "-|"); $pid = open(HTML_PIPE, "-|");
print "Pipe is open\n"; print "Pipe is open\n";
if ($pid) { # parent if ($pid) { # parent
# make file handle non-bloking # make file handle non-blocking
my $flags = ''; my $flags = '';
fcntl(HTML_PIPE, F_GETFL, $flags); fcntl(HTML_PIPE, F_GETFL, $flags);
$flags |= O_NONBLOCK; $flags |= O_NONBLOCK;
...@@ -1675,7 +1592,7 @@ sub get_options { ...@@ -1675,7 +1592,7 @@ sub get_options {
}; };
sub get_module_and_buildlist_paths { sub get_module_and_buildlist_paths {
if ($build_all_parents) { if ($build_all_parents || $checkparents) {
my $source_config = SourceConfig -> new($StandDir); my $source_config = SourceConfig -> new($StandDir);
$source_config_file = $source_config->get_config_file_path(); $source_config_file = $source_config->get_config_file_path();
$active_modules{$_}++ foreach ($source_config->get_active_modules()); $active_modules{$_}++ foreach ($source_config->get_active_modules());
...@@ -2371,7 +2288,9 @@ sub prepare_incompatible_build { ...@@ -2371,7 +2288,9 @@ sub prepare_incompatible_build {
@modules_built = keys %$deps_hash; @modules_built = keys %$deps_hash;
%add_to_config = %$deps_hash; %add_to_config = %$deps_hash;
if ($prepare) { if ($prepare) {
generate_config_file() if ((!defined $ENV{UPDATER}) || (defined $ENV{CWS_WORK_STAMP})); if ((!defined $ENV{UPDATER}) || (defined $ENV{CWS_WORK_STAMP})) {
SourceConfig->new()->add_active_modules([keys %add_to_config], 0);
}
clear_delivered(); clear_delivered();
} }
my $old_output_tree = ''; my $old_output_tree = '';
......
...@@ -38,10 +38,12 @@ package SourceConfig; ...@@ -38,10 +38,12 @@ package SourceConfig;
use strict; use strict;
use constant SOURCE_CONFIG_FILE_NAME => 'source_config'; use constant SOURCE_CONFIG_FILE_NAME => 'source_config';
use constant SOURCE_CONFIG_VERSION => 2;
use Carp; use Carp;
use Cwd; use Cwd;
use File::Basename; use File::Basename;
use File::Temp qw(tmpnam);
my $debug = 0; my $debug = 0;
...@@ -62,20 +64,28 @@ sub new { ...@@ -62,20 +64,28 @@ sub new {
} else { } else {
$source_root = $ENV{SOURCE_ROOT_DIR}; $source_root = $ENV{SOURCE_ROOT_DIR};
}; };
$source_root = Cwd::realpath($source_root); $self->{SOURCE_ROOT} = Cwd::realpath($source_root);
$self->{DEBUG} = 0; $self->{DEBUG} = 0;
$self->{SOURCE_ROOT} = $source_root; $self->{VERBOSE} = 0;
$self->{REPOSITORIES} = {}; $self->{REPOSITORIES} = {};
$self->{ACTIVATED_REPOSITORIES} = {};
$self->{MODULE_PATHS} = {}; $self->{MODULE_PATHS} = {};
$self->{MODULE_BUILD_LIST_PATHS} = {}; $self->{MODULE_BUILD_LIST_PATHS} = {};
$self->{ACTIVATED_MODULES} = {}; $self->{ACTIVATED_MODULES} = {};
$self->{MODULE_REPOSITORY} = {}; $self->{MODULE_REPOSITORY} = {};
$self->{REAL_MODULES} = {}; $self->{REAL_MODULES} = {};
$self->{NEW_MODULES} = [];
$self->{REMOVE_MODULES} = {};
$self->{REMOVE_REPOSITORIES} = {};
$self->{NEW_REPOSITORIES} = [];
$self->{WARNINGS} = [];
$self->{REPORT_MESSAGES} = [];
$self->{CONFIG_FILE_CONTENT} = [];
if (defined $self->{USER_SOURCE_ROOT}) { if (defined $self->{USER_SOURCE_ROOT}) {
${$self->{REPOSITORIES}}{File::Basename::basename($self->{USER_SOURCE_ROOT})} = $self->{USER_SOURCE_ROOT}; ${$self->{REPOSITORIES}}{File::Basename::basename($self->{USER_SOURCE_ROOT})} = $self->{USER_SOURCE_ROOT};
}; };
$self->{SOURCE_CONFIG_FILE} = get_config_file($source_root); $self->{SOURCE_CONFIG_FILE} = get_config_file($self->{SOURCE_ROOT});
$self->{SOURCE_CONFIG_DEFAULT} = $source_root .'/'.SOURCE_CONFIG_FILE_NAME; $self->{SOURCE_CONFIG_DEFAULT} = $self->{SOURCE_ROOT} .'/'.SOURCE_CONFIG_FILE_NAME;
read_config_file($self); read_config_file($self);
bless($self, $class); bless($self, $class);
return $self; return $self;
...@@ -83,6 +93,10 @@ sub new { ...@@ -83,6 +93,10 @@ sub new {
##### methods ##### ##### methods #####
sub get_version {
return SOURCE_CONFIG_VERSION;
};
sub get_repositories sub get_repositories
{ {
my $self = shift; my $self = shift;
...@@ -249,8 +263,11 @@ sub read_config_file { ...@@ -249,8 +263,11 @@ sub read_config_file {
my $repository_section = 0; my $repository_section = 0;
my $module_section = 0; my $module_section = 0;
my $line = 0; my $line = 0;
my @file_content = ();
if (open(SOURCE_CONFIG_FILE, $self->{SOURCE_CONFIG_FILE})) { if (open(SOURCE_CONFIG_FILE, $self->{SOURCE_CONFIG_FILE})) {
foreach (<SOURCE_CONFIG_FILE>) { foreach (<SOURCE_CONFIG_FILE>) {
push (@{$self->{CONFIG_FILE_CONTENT}}, $_);
$line++; $line++;
chomp; chomp;
next if (!/^\S+/); next if (!/^\S+/);
...@@ -270,6 +287,10 @@ sub read_config_file { ...@@ -270,6 +287,10 @@ sub read_config_file {
if (/\s*(\S+)=active\s*(\s+#)*/) { if (/\s*(\S+)=active\s*(\s+#)*/) {
if ($repository_section) { if ($repository_section) {
${$self->{REPOSITORIES}}{$1} = $self->{SOURCE_ROOT} . "/$1"; ${$self->{REPOSITORIES}}{$1} = $self->{SOURCE_ROOT} . "/$1";
${$self->{ACTIVATED_REPOSITORIES}}{$1}++;
if (defined $ENV{UPDMINOREXT}) {
${$self->{REPOSITORIES}}{$1} .= $ENV{UPDMINOREXT};
};
next; next;
} }
if ($module_section) { if ($module_section) {
...@@ -290,6 +311,187 @@ sub read_config_file { ...@@ -290,6 +311,187 @@ sub read_config_file {
}; };
}; };
sub remove_all_activated_repositories {
my $self = shift;
$self->remove_activated_repositories([keys %{$self->{ACTIVATED_REPOSITORIES}}]);
};
sub remove_activated_repositories {
my $self = shift;
my $new_repositories_ref = shift;
push(@{$self->{WARNINGS}}, "\nWARNING: Empty repository list passed for removing from source_config\n") if (!scalar @$new_repositories_ref);
$self->{VERBOSE} = shift;
$self->{REMOVE_REPOSITORIES} = {};
foreach (@$new_repositories_ref) {
if (!defined ${$self->{ACTIVATED_REPOSITORIES}}{$_}) {
push (@{$self->{WARNINGS}}, "\nWARNING: repository $_ is not activated in ". $self->get_config_file_default_path()."\n");
} else {
${$self->{REMOVE_REPOSITORIES}}{$_}++;
delete ${$self->{ACTIVATED_REPOSITORIES}}{$_};
};
};
generate_config_file($self);
};
sub remove_all_activated_modules {
my $self = shift;
$self->remove_activated_modules([keys %{$self->{ACTIVATED_MODULES}}]);
};
sub remove_activated_modules {
my $self = shift;
my $new_modules_ref = shift;
push(@{$self->{WARNINGS}}, "\nWARNING: Empty module list passed for removing from source_config\n") if (!scalar @$new_modules_ref);
$self->{VERBOSE} = shift;
$self->{REMOVE_MODULES} = {};
foreach (@$new_modules_ref) {
if (!defined ${$self->{ACTIVATED_MODULES}}{$_}) {
push (@{$self->{WARNINGS}}, "\nWARNING: module $_ is not activated in ". $self->get_config_file_default_path()."\n");
} else {
${$self->{REMOVE_MODULES}}{$_}++;
delete ${$self->{ACTIVATED_MODULES}}{$_};
};
};
generate_config_file($self);
};
sub add_active_repositories {
my $self = shift;
$self->{NEW_REPOSITORIES} = shift;
croak('Empty module list passed for adding to source_config') if (!scalar @{$self->{NEW_REPOSITORIES}});
$self->{VERBOSE} = shift;
generate_config_file($self);
};
sub add_active_modules {
my $self = shift;
$self->{NEW_MODULES} = shift;
croak('Empty module list passed for adding to source_config') if (!scalar @{$self->{NEW_MODULES}});
$self->{VERBOSE} = shift;
generate_config_file($self);
};
sub add_content {
my $self = shift;
my $content = shift;
my $entries_to_add = shift;
return if (!scalar @$entries_to_add);
my $message;
my $message_part1;
my $warning_message;
my $activated_entries;
if ($entries_to_add == $self->{NEW_MODULES}) {
$self->{NEW_MODULES} = [];
$message_part1 = "Module(s):\n";
$activated_entries = $self->{ACTIVATED_MODULES};
} elsif ($entries_to_add == $self->{NEW_REPOSITORIES}) {
$self->{NEW_REPOSITORIES} = [];
$message_part1 = "Repositories:\n";
$activated_entries = $self->{ACTIVATED_REPOSITORIES};
};
foreach my $entry (@$entries_to_add) {
if (defined $$activated_entries{$entry}) {
$warning_message .= "$entry "
} else {
push(@$content, "$entry=active\n");
${$activated_entries}{$entry}++;
$message .= "$entry "
};
};
push(@{$self->{REPORT_MESSAGES}}, "\n$message_part1 $message\nhave been added to the ". $self->get_config_file_default_path()."\n") if ($message);
push (@{$self->{WARNINGS}}, "\nWARNING: $message_part1 $warning_message\nare already added to the ". $self->get_config_file_default_path()."\n") if ($warning_message);
};
sub generate_config_file {
my $self = shift;
my @config_content_new = ();
my ($module_section, $repository_section);
my %removed_modules = ();
my %removed_repositories = ();
foreach (@{$self->{CONFIG_FILE_CONTENT}}) {
if (/^\[repositories\]\s*(\s+#)*/) {
if ($module_section) {
$self->add_content(\@config_content_new, $self->{NEW_MODULES});
};
$module_section = 0;
$repository_section = 1;
};
if (/^\[modules\]\s*(\s+#)*/) {
if ($repository_section) {
$self->add_content(\@config_content_new, $self->{NEW_REPOSITORIES});
};
$module_section = 1;
$repository_section = 0;
};
if ($module_section && /\s*(\S+)=active\s*(\s+#)*/) {
if (defined ${$self->{REMOVE_MODULES}}{$1}) {
$removed_modules{$1}++;
next;
};
}
if ($repository_section && /\s*(\S+)=active\s*(\s+#)*/) {
if (defined ${$self->{REMOVE_REPOSITORIES}}{$1}) {
$removed_repositories{$1}++;
next;
};
}
push(@config_content_new, $_);
};
if (scalar @{$self->{NEW_MODULES}}) {
push(@config_content_new, "[modules]\n") if (!$module_section);
$self->add_content(\@config_content_new, $self->{NEW_MODULES});
};
if (scalar @{$self->{NEW_REPOSITORIES}}) {
push(@config_content_new, "[repositories]\n") if (!$repository_section);
$self->add_content(\@config_content_new, $self->{NEW_REPOSITORIES});
};
if (scalar keys %removed_modules) {
my @deleted_modules = keys %removed_modules;
push(@{$self->{REPORT_MESSAGES}}, "\nModules: @deleted_modules\nhave been removed from the ". $self->get_config_file_default_path()."\n");
};
if (scalar keys %removed_repositories) {
my @deleted_repositories = keys %removed_repositories;
push(@{$self->{REPORT_MESSAGES}}, "\nRepositories: @deleted_repositories\nhave been removed from the ". $self->get_config_file_default_path()."\n");
};
# Writing file, printing warnings and reports
#check if we need to write a new file
my $write_needed = 0;
if ((scalar @{$self->{CONFIG_FILE_CONTENT}}) != (scalar @config_content_new)) {
$write_needed++;
} else {
foreach my $i (0 .. $#{$self->{CONFIG_FILE_CONTENT}}) {
if (${$self->{CONFIG_FILE_CONTENT}}[$i] ne $config_content_new[$i]) {
$write_needed++;
last;
};
};
};
if ($write_needed) {
my $temp_config_file = File::Temp::tmpnam($ENV{TMP});
die("Cannot open $temp_config_file") if (!open(NEW_CONFIG, ">$temp_config_file"));
print NEW_CONFIG $_ foreach (@config_content_new);
close NEW_CONFIG;
rename($temp_config_file, $self->get_config_file_default_path()) or system("mv", $temp_config_file, $self->get_config_file_default_path());
if (-e $temp_config_file) {
system("rm -rf $temp_config_file") if (!unlink $temp_config_file);
};
$self->{CONFIG_FILE_CONTENT} = \@config_content_new;
};
if ($self->{VERBOSE}) {
print $_ foreach (@{$self->{WARNINGS}});
$self->{VERBOSE} = 0;
};
$self->{WARNINGS} = [];
print $_ foreach (@{$self->{REPORT_MESSAGES}});
$self->{REPORT_MESSAGES} = [];
};
##### finish ##### ##### finish #####
1; # needed by use or require 1; # needed by use or require
...@@ -325,6 +527,10 @@ SourceConfig::new() ...@@ -325,6 +527,10 @@ SourceConfig::new()
Creates a new instance of SourceConfig. Can't fail. Creates a new instance of SourceConfig. Can't fail.
SourceConfig::get_version()
Returns version number of the module. Can't fail.
SourceConfig::get_repositories() SourceConfig::get_repositories()
...@@ -364,9 +570,35 @@ SourceConfig::is_active() ...@@ -364,9 +570,35 @@ SourceConfig::is_active()
Returns 1 (TRUE) if a module is active Returns 1 (TRUE) if a module is active
Returns 0 (FALSE) if a module is not active Returns 0 (FALSE) if a module is not active
SourceConfig::add_active_modules($module_array_ref)
Adds modules from the @$module_array_ref as active to the source_config file
SourceConfig::add_active_repositories($repository_array_ref)
Adds repositories from the @$repository_array_ref as active to the source_config file
SourceConfig::remove_activated_modules($module_array_ref)
Removes modules from the @$module_array_ref from the source_config file
SourceConfig::remove_all_activated_modules()
Removes all activated modules from the source_config file
SourceConfig::remove_activated_repositories($repository_array_ref)
Removes repositories from the @$repository_array_ref from the source_config file
SourceConfig::remove_all_activated_repositories()
Removes all activated repositories from the source_config file
=head2 EXPORT =head2 EXPORT
SourceConfig::new() SourceConfig::new()
SourceConfig::get_version()
SourceConfig::get_repositories() SourceConfig::get_repositories()
SourceConfig::get_active_modules() SourceConfig::get_active_modules()
SourceConfig::get_all_modules() SourceConfig::get_all_modules()
...@@ -376,6 +608,12 @@ SourceConfig::get_module_repository($module) ...@@ -376,6 +608,12 @@ SourceConfig::get_module_repository($module)
SourceConfig::get_config_file_path() SourceConfig::get_config_file_path()
SourceConfig::get_config_file_default_path() SourceConfig::get_config_file_default_path()
SourceConfig::is_active($module) SourceConfig::is_active($module)
SourceConfig::add_active_modules($module_array_ref)
SourceConfig::add_active_repositories($repository_array_ref)
SourceConfig::remove_activated_modules($module_array_ref)
SourceConfig::remove_all_activated_modules()
SourceConfig::remove_activated_repositories($repository_array_ref)
SourceConfig::remove_all_activated_repositories()
=head1 AUTHOR =head1 AUTHOR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment