Skip to content

Commit

Permalink
Fix relative paths in Makefile
Browse files Browse the repository at this point in the history
Also:
- Add Phases::curr_phase_idx
- Update hopen-file execution environment in A::h and in Conventions.
  Hopen files now may only return hashrefs.
  • Loading branch information
Chris White committed Feb 25, 2019
1 parent f6c4a85 commit d6c0de8
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 53 deletions.
31 changes: 25 additions & 6 deletions lib/App/hopen.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# App::hopen: Implementation of the hopen(1) program
package App::hopen;
our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

# Imports {{{1
use Data::Hopen::Base;
Expand All @@ -20,6 +20,8 @@ use Hash::Merge;
use Path::Class;
use Scalar::Util qw(looks_like_number);

BEGIN { $Data::Dumper::Indent = 1; } # DEBUG

# }}}1
# Constants {{{1

Expand Down Expand Up @@ -406,15 +408,20 @@ EOT
EOT
}

# Run the code given in the hopen file. Wrap it in a named BLOCK so that
# Phases::on() will work, but don't rely on the return value of that
# BLOCK (per perlsyn).

$src .= <<EOT;
sub __Rsub_$pkg_name {
my \$__R_retval = do { # return statements in here will exit the Rsub
__R_DO: {
my \$__R_retval;
__R_DO: {
\$__R_retval = do { # return statements in here will exit the Rsub
#line 1 "$friendly_name"
$file_text
} #__R_DO
}; # do{}
}; # do{}
} #__R_DO
EOT

# If the file_text did not expressly return(), control will reach the
Expand All @@ -423,15 +430,27 @@ EOT
# via Phases::on(), we have a defined __R_on_result. If either of those
# is defined, make sure it's not a DAG or GraphBuilder. Those should not
# be put into the return data.
#
# Also, any defined, non-hash

$src .= <<EOT;
\$__R_retval //= \$__R_on_result;
## hlog { '__Rpkg_$pkg_name retval before checks',
## ref \$__R_retval, Dumper \$__R_retval} 3;
if(defined(\$__R_retval) && ref(\$__R_retval)) {
die 'Hopen files may not return graphs'
if eval { \$__R_retval->DOES('Data::Hopen::G::DAG') };
die 'Hopen files may not return graph builders (is a ->goal or ->default_goal missing?)'
if eval { \$__R_retval->DOES('Data::Hopen::G::GraphBuilder') };
}
if(defined(\$__R_retval) and ref \$__R_retval ne 'HASH') {
warn ('Hopen files must return hashrefs; ignoring ' .
lc(ref(\$__R_retval) || 'scalar')) unless \$QUIET;
\$__R_retval = undef;
}
return \$__R_retval;
Expand All @@ -451,7 +470,7 @@ EOT
die "Error in $friendly_name: $@" if $@;

# Get the data from the package we just ran
my $hrAddlData = eval ("\$__Rpkg_${pkg_name}" . '::hrNewData');
my $hrAddlData = eval ("\$__Rpkg_$pkg_name" . '::hrNewData');

hlog { 'old data', Dumper($_hrData) } 3;
hlog { 'new data', Dumper($hrAddlData) } 2;
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/AppUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Data::Hopen qw(:default isMYH MYH);
use Data::Hopen::Base;
use parent 'Exporter';

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
BEGIN {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/BuildSystemGlobals.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package App::hopen::BuildSystemGlobals;
use Data::Hopen;
use Data::Hopen::Base;

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

use parent 'Exporter';
our @EXPORT;
Expand Down
19 changes: 14 additions & 5 deletions lib/App/hopen/Conventions.pod
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,19 @@ option is executed as if it were its own hopen file on disk, and any
hopen file referenced by a C<-f> option is executed. C<-e> and C<-f> options
are processed in the order given on the command line.

The hopen files are run in order to build up a hashref that will be the
input to the build graph. The hopen files, while they run, also
populate the build graph.

=head2 Execution environment of a hopen file

Each hopen file is the body of a subroutine that may return a hashref (C<{}>).
That hashref is provided as input to the build graph. Each hopen file's output
hashref, if any, is appended to the input hashref (using L<Hash::Merge> with
retainment precedent). Therefore, to leave the input unchanged, return
C<{}>, not C<$_[0]>.
Each hopen file is the body of a subroutine that receives a hashref from the
last-run hopen file and may return a hashref (C<{...}>) or C<undef>. Each
hopen file's output hashref, if any, is appended to the input hashref (using
L<Hash::Merge> with retainment precedent). Therefore, to leave the input
unchanged, return C<{}>, not C<$_[0]>.

Any return value that is not a hashref will be ignored.

Elements of the hashref starting with C<__R> are reserved. Please don't read
or write those elements if you want hopen to work! :) Similarly, all variables
Expand All @@ -135,6 +141,9 @@ packages loaded (via L<App::hopen::HopenFileKit>):

=item * L<App::hopen::Phases>

With both C<:all> and C<:hopenfile> specified, so you get, e.g.,
L<App::hopen::Phases/on>.

=item * L<App::hopen::Util::BasedPath>

=item * L<Data::Hopen>
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/G/FilesOp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package App::hopen::G::FilesOp;
#use Data::Hopen;
use Data::Hopen::Base;

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

use parent 'Data::Hopen::G::Op';
use Class::Tiny {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/Gen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package App::hopen::Gen;
use Data::Hopen;
use Data::Hopen::Base;

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

use Class::Tiny qw(proj_dir dest_dir), {
architecture => '',
Expand Down
17 changes: 5 additions & 12 deletions lib/App/hopen/Gen/Make.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
package App::hopen::Gen::Make;
use Data::Hopen::Base;

BEGIN { $Data::Dumper::Indent = 1; } # DEBUG

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

use parent 'App::hopen::Gen';
use Class::Tiny {
Expand Down Expand Up @@ -103,16 +101,12 @@ EOT
foreach(@{$item->{from}}) {
hlog { 'Work item', Dumper($_) } 3;
next unless $_;
push @sources, $_->path_on($ProjDir)->relative($DestDir);
# TODO FIXME this isn't right --- sources may be in the
# project dir or the destination dir.
# Move this logic to the toolchain?
push @sources, $_->orig->relative($DestDir);
}

my $dest = $item->{to}->[0];
$dest = $dest->path_on($DestDir)->relative($DestDir)
$dest = $dest->orig->relative($DestDir)
if $dest->DOES('App::hopen::Util::BasedPath');
# TODO is this right?

say $fh $dest, ': ', join(' ', @sources);
say $fh (_expand($item) =~ s/^/\t/gmr);
Expand Down Expand Up @@ -147,13 +141,12 @@ sub _expand {
my $retval = $item->{how} or return ''; # no `how` => no output; not an error
$retval = $retval->[0] if ref $retval eq 'ARRAY';

# TODO FIXME HACK --- this isn't right, but it's a start.
my $first = $item->{from}->[0];
$first = $first->path_on($DestDir)->relative($DestDir)
$first = $first->orig->relative($DestDir)
if $first->DOES('App::hopen::Util::BasedPath');

my $out = $item->{to}->[0];
$out = $out->path_on($DestDir)->relative($DestDir)
$out = $out->orig->relative($DestDir)
if $out->DOES('App::hopen::Util::BasedPath');

$retval =~ s{#first\b}{$first // ''}ge; # first input
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/H.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package App::hopen::H;
use Data::Hopen::Base;

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

use parent 'Exporter';
our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/HopenFileKit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use App::hopen::Phases ();
use Data::Hopen qw(:default loadfrom);


our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

use parent 'Exporter'; # Exporter-exported symbols {{{1
our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/Phase/Check.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Data::Hopen;
use Data::Hopen::Base;
use parent 'Exporter';

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
BEGIN {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/hopen/Phase/Gen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Data::Hopen;
use Data::Hopen::Base;
#use parent 'Exporter';

our $VERSION = '0.000009'; # TRIAL
our $VERSION = '0.000010'; # TRIAL

#use Class::Tiny ;#qw(TODO);

Expand Down
Loading

0 comments on commit d6c0de8

Please sign in to comment.