Skip to content

Commit

Permalink
fcm make: allow multiple runs in same directory
Browse files Browse the repository at this point in the history
A make can now be named, so multiple non-overlapping makes can work in
the same directory.
  • Loading branch information
matthewrmshin committed Apr 27, 2015
1 parent cab3b4b commit 77abdf7
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 75 deletions.
6 changes: 3 additions & 3 deletions lib/FCM/CLI/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ our %OPTION_OF = map {
[['jobs' , ], ['j'], OPT_SCAL],
[['list' , ], ['l'], OPT_BOOL],
[['name' , ], ['n'], OPT_SCAL],
[['new' , ], ['n'], OPT_BOOL],
[['new' , ], ['N'], OPT_BOOL],
[['non-interactive' , ], [ ], OPT_BOOL],
[['only' , ], [ ], OPT_LIST],
[['organisation' , ], [ ], OPT_SCAL],
Expand Down Expand Up @@ -163,8 +163,8 @@ our %OPTIONS_FOR = (
}],
'mkpatch' => [@OPTION_OF{qw{exclude organisation revision}}],
'make' => [@OPTION_OF{
qw{ directory ignore-lock jobs config-file config-file-path new quiet
verbose
qw{ directory ignore-lock jobs config-file config-file-path name new
quiet verbose
}
}],
'project-create'=> [@OPTION_OF{
Expand Down
4 changes: 4 additions & 0 deletions lib/FCM/CLI/fcm-make.pod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ will fail. This option can be used to bypass this check.

Specify the number of (child) processes that can be run simultaneously.

=item --name=NAME, -n NAME

Specify the context name of this make.

=item --new

Remove items in the destination created by the previous make, and starts a new
Expand Down
7 changes: 7 additions & 0 deletions lib/FCM/Context/Make.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ __PACKAGE__->class({
dest_lock => '$',
error => {},
inherit_ctx_list => '@',
name => {isa => '$', default => q{}},
option_of => '%',
prev_ctx => __PACKAGE__,
status => {isa => '$', default => ST_UNKNOWN},
Expand Down Expand Up @@ -89,6 +90,12 @@ This should be set to the value of the exception, if this make ends in one.
An ARRAY of contexts inherited by this make.
=item name
The name of the context. This is useful if we need to have multiple (but
non-overlapping) "fcm make" runs in the same destination. (Default is a null
string.)
=item option_of
A HASH to store the options of this make. See L</OPTION> for detail.
Expand Down
48 changes: 24 additions & 24 deletions lib/FCM/System/Make.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,37 +133,33 @@ sub _config_parse {
# Sets up the destination.
sub _dest_init {
my ($attrib_ref, $m_ctx) = @_;
$attrib_ref->{shared_util_of}{dest}->dest_init($m_ctx);
my $DEST_UTIL = $attrib_ref->{shared_util_of}{dest};
$DEST_UTIL->dest_init($m_ctx);

# Move temporary log file to destination
my $now = strftime("%Y%m%dT%H%M%S", gmtime());
my $log = $attrib_ref->{shared_util_of}{dest}->path($m_ctx, 'sys-log');
my $log = $DEST_UTIL->path($m_ctx, 'sys-log');
my $log_actual = sprintf("%s-%s", $log, $now);
_symlink(basename($log_actual), $log);
( close($attrib_ref->{handle_log})
&& copy($attrib_ref->{handle_log}->filename(), $log)
&& open(my $handle_log, '>>', $log)
) || return $E->throw($E->DEST_CREATE, $log, $!);
_symlink(
$FCM::System::Make::Share::Dest::PATH_OF{'sys-log'},
$attrib_ref->{shared_util_of}{dest}->path($m_ctx, 'sys-log-symlink'),
$DEST_UTIL->path({'name' => $m_ctx->get_name()}, 'sys-log'),
$DEST_UTIL->path($m_ctx, 'sys-log-symlink'),
);
my $log_ctx = $attrib_ref->{util}->util_of_report()->get_ctx($m_ctx);
$log_ctx->set_handle($handle_log);

# Saves as parsed config
my $cfg = $attrib_ref->{shared_util_of}{dest}->path(
$m_ctx, 'sys-config-as-parsed',
);
my $cfg = $DEST_UTIL->path($m_ctx, 'sys-config-as-parsed');
( close($attrib_ref->{handle_cfg})
&& copy($attrib_ref->{handle_cfg}->filename(), $cfg)
) || return $E->throw($E->DEST_CREATE, $cfg, $!);
_symlink(
$FCM::System::Make::Share::Dest::PATH_OF{'sys-config-as-parsed'},
$attrib_ref->{shared_util_of}{dest}->path(
$m_ctx,
'sys-config-as-parsed-symlink',
),
$DEST_UTIL->path({'name' => $m_ctx->get_name()}, 'sys-config-as-parsed'),
$DEST_UTIL->path($m_ctx, 'sys-config-as-parsed-symlink'),
);
}

Expand All @@ -181,7 +177,11 @@ sub _main {
}
# Starts the system
my $m_ctx = FCM::Context::Make->new({option_of => $option_hash_ref});
my $T = sub {_timer_wrap($attrib_ref, @_)};
if ($m_ctx->get_option_of('name')) {
$m_ctx->set_name($m_ctx->get_option_of('name'));
}
my $T = sub {_timer_wrap($attrib_ref, $m_ctx, @_)};
my $DEST_UTIL = $attrib_ref->{shared_util_of}{dest};
eval {$T->(
sub {
my %attrib = (
Expand Down Expand Up @@ -224,9 +224,7 @@ sub _main {
$ctx->set_status($m_ctx->ST_INIT);
if ($ctx->can('set_dest')) {
$ctx->set_dest(
$attrib_ref->{shared_util_of}{dest}->path(
$m_ctx, 'target', $ctx->get_id(),
),
$DEST_UTIL->path($m_ctx, 'target', $ctx->get_id()),
);
}
eval {$T->(sub {$impl->main($m_ctx, $ctx)}, $step)};
Expand All @@ -251,17 +249,14 @@ sub _main {
die("\n");
}
$m_ctx->set_status($m_ctx->ST_OK);
$attrib_ref->{shared_util_of}{dest}->save(
$DEST_UTIL->save(
[$attrib_ref->{shared_util_of}{config}->unparse($m_ctx)],
$m_ctx,
'sys-config-on-success',
);
_symlink(
$FCM::System::Make::Share::Dest::PATH_OF{'sys-config-on-success'},
$attrib_ref->{shared_util_of}{dest}->path(
$m_ctx,
'sys-config-on-success-symlink',
),
$DEST_UTIL->path({'name' => $m_ctx->get_name()}, 'sys-config-on-success'),
$DEST_UTIL->path($m_ctx, 'sys-config-on-success-symlink'),
);
_main_finally($attrib_ref, $m_ctx);
return $m_ctx;
Expand Down Expand Up @@ -291,10 +286,15 @@ sub _symlink {

# Wraps a piece of code with timer events.
sub _timer_wrap {
my ($attrib_ref, $code_ref, @names) = @_;
my ($attrib_ref, $m_ctx, $code_ref, @names) = @_;
my @event_args = (
FCM::Context::Event->TIMER,
join(q{ }, $attrib_ref->{name}, @names),
join(
q{ },
$attrib_ref->{name},
($m_ctx->get_name() ? $m_ctx->get_name() : ()),
@names,
),
time(),
);
$attrib_ref->{util}->event(@event_args);
Expand Down
36 changes: 30 additions & 6 deletions lib/FCM/System/Make/Mirror.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ our %CONFIG_PARSER_OF = (

# Default properties
our %PROP_OF = (
'config-file.steps' => [q{}],
'no-config-file' => [q{}],
'config-file.steps' => [q{}],
'no-config-file' => [q{}],
'config-file-ctx-name' => ['2'],
);

# Properties from FCM::Util
Expand Down Expand Up @@ -167,6 +168,7 @@ sub _mirror_config_file {
my ($attrib_ref, $m_ctx, $ctx, $sources_ref) = @_;
my ($target) = _target_and_authority($ctx);
my $mirror_m_ctx = FCM::Context::Make->new({dest => '$HERE'});
$mirror_m_ctx->set_name(_prop($attrib_ref, 'config-file-ctx-name', $ctx));
my %no_inherit_from;
if (@{$m_ctx->get_inherit_ctx_list()}) {
# Inherited destinations
Expand Down Expand Up @@ -237,11 +239,22 @@ sub _mirror_config_file {
# Saves the configuration file
my @lines = map {$_ . "\n"}
$attrib_ref->{shared_util_of}{config}->unparse($mirror_m_ctx);
my $path = $attrib_ref->{shared_util_of}{dest}->path($ctx, 'config');
my $DEST_UTIL = $attrib_ref->{shared_util_of}{dest};
my $path = $DEST_UTIL->path(
{ 'dest' => $ctx->get_dest(),
'name' => _prop($attrib_ref, 'config-file-ctx-name', $ctx),
},
'config',
);
$attrib_ref->{util}->file_save($path, \@lines);
_mirror(
$attrib_ref, $m_ctx, $ctx,
[$path], $attrib_ref->{shared_util_of}{dest}->path($target, 'config'),
[$path], $DEST_UTIL->path(
{ 'dest' => $target,
'name' => _prop($attrib_ref, 'config-file-ctx-name', $ctx),
},
'config',
),
);
}

Expand Down Expand Up @@ -288,13 +301,24 @@ sub _mirror_orig_config_file {
),
map {$_ . "\n"} $attrib_ref->{shared_util_of}{config}->unparse($m_ctx),
);
my $path = $attrib_ref->{shared_util_of}{dest}->path($ctx, 'config-orig');
my $DEST_UTIL = $attrib_ref->{shared_util_of}{dest};
my $path = $DEST_UTIL->path(
{ 'dest' => $ctx->get_dest(),
'name' => _prop($attrib_ref, 'config-file-ctx-name', $ctx),
},
'config-orig',
);
$attrib_ref->{util}->file_save($path, \@lines);
my ($target) = _target_and_authority($ctx);
_mirror(
$attrib_ref, $m_ctx, $ctx,
[$path],
$attrib_ref->{shared_util_of}{dest}->path($target, 'config-orig'),
$DEST_UTIL->path(
{ 'dest' => $target,
'name' => _prop($attrib_ref, 'config-file-ctx-name', $ctx),
},
'config-orig',
),
);
}

Expand Down
31 changes: 16 additions & 15 deletions lib/FCM/System/Make/Share/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ my $E = 'FCM::System::Exception';

# Configuration parser label to action map
my %CONFIG_PARSER_OF = (
'dest' => \&_parse_dest,
'use' => \&_parse_use,
'dest' => sub {$_[1]->set_dest($_[2]->get_value())},
'name' => sub {$_[1]->set_name($_[2]->get_value())},
'step.class' => \&_parse_step_class,
'steps' => \&_parse_steps,
'use' => \&_parse_use,
);

__PACKAGE__->class(
Expand All @@ -51,6 +52,7 @@ __PACKAGE__->class(
# populate the context of the current make.
sub _parse {
my ($attrib_ref, $entry_callback_ref, $m_ctx, @args) = @_;
my $DEST_UTIL = $attrib_ref->{shared_util_of}{dest};
my $dir = $m_ctx->get_option_of('directory')
? $m_ctx->get_option_of('directory') : cwd();
my $dir_locator = FCM::Context::Locator->new($dir);
Expand All @@ -64,8 +66,8 @@ sub _parse {
for my $config_file_name (@config_file_names) {
my $is_specified_name = 1;
if (!defined($config_file_name)) {
$config_file_name
= $attrib_ref->{shared_util_of}{dest}->path_of('config');
$config_file_name = $DEST_UTIL->path(
{'name' => $m_ctx->get_name()}, 'config');
$is_specified_name = 0;
}
if ( $attrib_ref->{util}->uri_match($config_file_name)
Expand Down Expand Up @@ -98,8 +100,9 @@ sub _parse {
}
}
if (!@config_reader_refs) {
my $config_file_name = $attrib_ref->{shared_util_of}{dest}->path(
$dir_locator->get_value(), 'config',
my $config_file_name = $DEST_UTIL->path(
{'dest' => $dir_locator->get_value(), 'name' => $m_ctx->get_name()},
'config',
);
if (-f $config_file_name) {
push(@config_reader_refs, _get_config_reader(
Expand Down Expand Up @@ -202,12 +205,6 @@ sub _get_config_reader {
);
}

# Reads the dest declaration.
sub _parse_dest {
my ($attrib_ref, $m_ctx, $entry) = @_;
$m_ctx->set_dest($entry->get_value());
}

# Reads the step.class declaration from a config entry.
sub _parse_step_class {
my ($attrib_ref, $m_ctx, $entry) = @_;
Expand Down Expand Up @@ -248,7 +245,10 @@ sub _parse_use {
$value = $attrib_ref->{util}->file_tilde_expand($value);
my $i_m_ctx = eval {
$DEST->ctx_load(
$DEST->path($value, 'sys-ctx'),
$DEST->path(
{'dest' => $value, 'name' => $m_ctx->get_name()},
'sys-ctx',
),
blessed($m_ctx),
);
};
Expand Down Expand Up @@ -306,8 +306,9 @@ sub _unparse {
: ()
;
}
( [\&_unparse_use , 'use' ],
[\&_unparse_steps , 'steps'],
( [sub {$m_ctx->get_name()}, 'name' ],
[\&_unparse_use , 'use' ],
[\&_unparse_steps , 'steps'],
[sub {$m_ctx->get_dest()}, 'dest' ],
),
),
Expand Down
Loading

0 comments on commit 77abdf7

Please sign in to comment.