Skip to content

Commit

Permalink
First working Makefile generation
Browse files Browse the repository at this point in the history
t/samples/01 now runs if you do

    ./runhopen --fresh && ./runhopen && (cd built && make)

General:
- Hard-code the BH::Conventions URL in README.md since I don't
  have a non-TRIAL release on MetaCPAN yet.
- Slightly expand BH::Conventions
- Bump version

Scope:
- Use the name "context" to represent the outer scope
- Split run() into Scope::run() and <subclass>::_run()

DAG:
- Clean up DAG::_run()
- Run Links in series, not parallel
- Don't create Link if we don't need one

G:
- Change PassthroughOp to more flexible CollectOp, e.g., for use in t/021.

T and Gen:
- Regularize the use of `work`
- Use the right paths for the source and EXE files

App:
- Add --verbose option

Tests:
- Small updates based on changes above
- 006: Add test of local on G::PassthroughOp
- 006, 021: add levels

Prereqs:
- Bump File::Glob minimum version, since I was seeing failures on 5.14.x
  due to lack of `:bsd_glob`.  perl5160delta says 5.16 used File::Glob 1.17,
  so that's the new minimum requirement.
  • Loading branch information
Chris White committed Feb 8, 2019
1 parent 9c7af71 commit 7abdaf1
Show file tree
Hide file tree
Showing 48 changed files with 508 additions and 311 deletions.
4 changes: 2 additions & 2 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lib/Build/Hopen/Base.pm
lib/Build/Hopen/BuildSystemGlobals.pm
lib/Build/Hopen/Conventions.pod
lib/Build/Hopen/G.pod
lib/Build/Hopen/G/CollectOp.pm
lib/Build/Hopen/G/DAG.pm
lib/Build/Hopen/G/Entity.pm
lib/Build/Hopen/G/FilesOp.pm
Expand All @@ -16,7 +17,6 @@ lib/Build/Hopen/G/GraphBuilder.pm
lib/Build/Hopen/G/Link.pm
lib/Build/Hopen/G/Node.pm
lib/Build/Hopen/G/Op.pm
lib/Build/Hopen/G/PassthroughOp.pm
lib/Build/Hopen/G/Runnable.pm
lib/Build/Hopen/Gen.pm
lib/Build/Hopen/Gen/Make.pm
Expand Down Expand Up @@ -51,7 +51,7 @@ t/002-link.t
t/003-node.t
t/004-goal.t
t/005-op.t
t/006-passthrough-op.t
t/006-collect-op.t
t/007-hnew.t
t/008-nameset.t
t/009-hopen-constants.t
Expand Down
11 changes: 8 additions & 3 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# MIscellaneous
^\.editorconfig
^\.[^\\\/]*\.yml
\.swp$
~$
^~
\bfoo\b.*
t/.*\.out$
lua$
Expand All @@ -12,8 +10,15 @@ TODO
\brunhopen$
\.stackdump$

# Backup files
\.swp$
~$
^~

# Things we generate
\bbuilt[\\/]
\.o(bj)?$
\.exe$

#modified included
# Avoid version control files.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ my %opts = (
'Exporter' => '0',
'feature' => '0',
# 'File::Find::Rule' => '0', # - might be nice for finding files
'File::Glob' => '0',
'File::Glob' => '1.17', # For :bsd_glob - see perl5160delta.
#'File::Globstar' => '0.5', # Fewer dependencies
'File::Path::Tiny' => '0.9',
'File::Spec' => '0',
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build scripts (specifically, Perl 5.14+)
- Context-sensitivity. Your users can tweak their own builds for their own
platforms without affecting your project.

See [Build::Hopen::Conventions](https://metacpan.org/pod/Build::Hopen::Conventions) for details of the input format.
See [Build::Hopen::Conventions](https://metacpan.org/pod/release/CXW/Build-Hopen-0.000006-TRIAL/lib/Build/Hopen/Conventions.pod) for details of the input format.

Why Perl? Because (1) you probably already have it installed, and
(2) it is the original write-once, run-everywhere language!
Expand Down
2 changes: 1 addition & 1 deletion lib/Build/Hopen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BEGIN {
use Build::Hopen::Util::NameSet;
use Storable ();

our $VERSION = '0.000006'; # TRIAL
our $VERSION = '0.000007'; # TRIAL

# Docs {{{1

Expand Down
50 changes: 38 additions & 12 deletions lib/Build/Hopen/App.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build::Hopen::App: hopen(1) program
package Build::Hopen::App;
our $VERSION = '0.000006'; # TRIAL
our $VERSION = '0.000007'; # TRIAL

# Imports {{{1
use Build::Hopen::Base;
Expand All @@ -18,6 +18,7 @@ use File::stat ();
use Getopt::Long qw(GetOptionsFromArray :config gnu_getopt);
use Hash::Merge;
use Path::Class;
use Scalar::Util qw(looks_like_number);

# }}}1
# Constants {{{1
Expand Down Expand Up @@ -109,6 +110,7 @@ my %CMDLINE_OPTS = (
# --usage reserved
PRINT_VERSION => ['version','', false],
VERBOSE => ['v','+', 0],
VERBOSE2 => ['verbose',':s'], # --verbose=<n>
# -? reserved

);
Expand Down Expand Up @@ -190,8 +192,12 @@ values from the command line, keyed by the keys in L</%CMDLINE_OPTS>.
$hrOptsOut->{DEST_DIR} //= $params{from}->[0] if @{$params{from}};
$hrOptsOut->{PROJ_DIR} //= $params{from}->[1] if @{$params{from}}>1;

# Option overrides: -q beats -v
$hrOptsOut->{VERBOSE} = 0 if $hrOptsOut->{QUIET};
# Sanity check VERBOSE2, and give it a default of 0
my $v2 = $hrOptsOut->{VERBOSE2} // 0;
$v2 = 1 if $v2 eq ''; # --verbose without value === --verbose=1
die "--verbose requires a positive numeric argument"
if (defined $v2) && ( !looks_like_number($v2) || (int($v2) < 0) );
$hrOptsOut->{VERBOSE2} = int($v2 // 0);

} #_parse_command_line() }}}2

Expand Down Expand Up @@ -390,17 +396,22 @@ EOT
return \$__R_retval;
} #__Rsub_$pkg_name
return __Rsub_$pkg_name(\$Build::Hopen::App::_hrData);
our \$hrNewData = __Rsub_$pkg_name(\$Build::Hopen::App::_hrData);
} #package
EOT
# Put the result in a package variable because that way I don't have
# to remember the rules for the return value of eval().

hlog { "Source for $fn\n", $src, "\n" } 3;

# == Run the package ==

my $hrAddlData = eval($src);
eval($src);
die "Error in $friendly_name: $@" if $@;

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

hlog { 'old data', Dumper($_hrData) } 3;
hlog { 'new data', Dumper($hrAddlData) } 2;

Expand Down Expand Up @@ -446,6 +457,7 @@ be run if it is empty.
$Phase = $opts{phase} if $opts{phase};
my $lrHopenFiles = $opts{files};
croak 'Need files=>[...]' unless ref $lrHopenFiles eq 'ARRAY';
hlog { Phase => $Phase, Running => Dumper($lrHopenFiles) };

# = Process the files ======================================

Expand All @@ -458,7 +470,7 @@ be run if it is empty.
hlog { 'Graph is', ($Build->empty ? 'empty.' : 'not empty.'),
' Final data is', Dumper($_hrData) } 2;

hlog { Data::Dumper->new([$Build], ['$Build'])->Indent(1)->Dump } 4;
hlog { Data::Dumper->new([$Build], ['$Build'])->Indent(1)->Dump } 5;

# If there is no build graph, just return the data. This is useful
# enough for debugging that I am making it documented behaviour.
Expand All @@ -473,7 +485,7 @@ be run if it is empty.
$scope->adopt_hash($_hrData);

# Run the DAG
my $result_data = $Build->run(-scope => $scope, -phase => $Phase,
my $result_data = $Build->run(-context => $scope, -phase => $Phase,
-generator => $Generator);
hlog { Data::Dumper->new([$result_data], ['Build graph result data'])->Indent(1)->Dump } 2;
return $result_data;
Expand Down Expand Up @@ -511,6 +523,7 @@ translates the die() into a print and error return.

# Get the project dir
my $proj_dir = $opts{PROJ_DIR} ? dir($opts{PROJ_DIR}) : dir; #default=cwd
$ProjDir = $proj_dir;

# Get the destination dir
my $dest_dir;
Expand All @@ -519,6 +532,7 @@ translates the die() into a print and error return.
} else {
$dest_dir = $proj_dir->subdir('built');
}
$DestDir = $dest_dir;

# Prohibit in-source builds
die <<EOT if $proj_dir eq $dest_dir;
Expand Down Expand Up @@ -682,9 +696,18 @@ Command-line runner. Call as C<< Build::Hopen::App::Main(\@ARGV) >>.

my %opts;
_parse_command_line(from => $lrArgs, into => \%opts);

# Verbosity is the max of -v and --verbose
$opts{VERBOSE} = $opts{VERBOSE2} if $opts{VERBOSE2} > $opts{VERBOSE};

# Option overrides: -q beats -v
$opts{VERBOSE} = 0 if $opts{QUIET};
$QUIET = $opts{QUIET} // false;
if(!$QUIET && $opts{VERBOSE}) { # Verbosity first
$Build::Hopen::VERBOSE += $opts{VERBOSE};

# Implement verbosity
if(!$QUIET && $opts{VERBOSE}) {
$VERBOSE += $opts{VERBOSE};
#hlog { Verbosity => $VERBOSE };

# Under -v, keep stdout and stderr lines in order.
use IO::Handle;
Expand All @@ -694,7 +717,9 @@ Command-line runner. Call as C<< Build::Hopen::App::Main(\@ARGV) >>.

# Don't print the source of an eval'ed hopen file unless -vvv or higher.
# Need 3 for the "..." that Carp prints when truncating.
$Carp::MaxEvalLen = 3 unless $Build::Hopen::VERBOSE >= 3;
$Carp::MaxEvalLen = 3 unless $VERBOSE >= 3;

# = Do it, Rockapella! ==================================================

eval { _inner(%opts); };
my $msg = $@;
Expand Down Expand Up @@ -766,9 +791,10 @@ terminate if a file attempts to do so.
Produce no output (quiet). Overrides C<-v>.
=item -v
=item -v, --verbose=n
Verbose. Specify more C<v>'s for more verbosity. At present, C<-vv> gives
Verbose. Specify more C<v>'s for more verbosity. At present, C<-vv>
(equivalently, C<--verbose=2>) gives
you detailed traces of the data, and C<-vvv> gives you more detailed
code tracebacks on error.
Expand Down
2 changes: 1 addition & 1 deletion lib/Build/Hopen/AppUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Build::Hopen qw(:default isMYH MYH);
use Build::Hopen::Base;
use parent 'Exporter';

our $VERSION = '0.000006'; # TRIAL
our $VERSION = '0.000007'; # TRIAL

our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
BEGIN {
Expand Down
4 changes: 2 additions & 2 deletions lib/Build/Hopen/Arrrgs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ our @ISA = qw(Exporter);

our @EXPORT = qw( parameters );

our $VERSION = '0.000006'; # TRIAL
our $VERSION = '0.000007'; # TRIAL

=head1 NAME
Build::Hopen::Arrrgs - Perl extension allowing subs to handle mixed parameter lists
=head1 SYNOPSIS
This is a tweaked version of L<Build::Hopen::Arrrgs>. See
This is a tweaked version of L<Getargs::Mixed>. See
L<https://rt.cpan.org/Ticket/Display.html?id=128428>.
use Build::Hopen::Arrrgs;
Expand Down
6 changes: 2 additions & 4 deletions lib/Build/Hopen/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package Build::Hopen::Base;
use parent 'Exporter';
use Import::Into;

our $VERSION = '0.000006'; # TRIAL
our $VERSION = '0.000007'; # TRIAL

# Pragmas
use 5.014;
Expand Down Expand Up @@ -48,9 +48,7 @@ sub import {

# Re-export pragmas
feature->import::into($target, qw(:5.14));
foreach my $pragma (qw(strict warnings)) {
${pragma}->import::into($target);
};
"$_"->import::into($target) foreach qw(strict warnings);

# Re-export packages
Data::Dumper->import::into($target);
Expand Down
14 changes: 11 additions & 3 deletions lib/Build/Hopen/BuildSystemGlobals.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package Build::Hopen::BuildSystemGlobals;
use Build::Hopen;
use Build::Hopen::Base;

our $VERSION = '0.000006'; # TRIAL
our $VERSION = '0.000007'; # TRIAL

use parent 'Exporter';
our @EXPORT;
BEGIN { @EXPORT = qw(*Generator *Toolset *Build *Phase); }
BEGIN { @EXPORT = qw(*Generator *Toolset *Build *Phase *ProjDir *DestDir); }
# export with `*` => `local` will work.

=head1 NAME
Expand Down Expand Up @@ -41,9 +41,17 @@ generated C<Makefile>.
Which phase we're in (string).
=head2 $ProjDir
A L<Path::Class::Dir> instance representing the project directory.
=head2 $DestDir
A L<Path::Class::Dir> instance representing the destination directory.
=cut

our ($Generator, $Toolset, $Build, $Phase);
our ($Generator, $Toolset, $Build, $Phase, $ProjDir, $DestDir);

1;
__END__
Expand Down
23 changes: 13 additions & 10 deletions lib/Build/Hopen/Conventions.pod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ requires its components to follow the conventions described in this document.
These conventions are generally implemented/enforced in L<Build::Hopen::App>
and L<Build::Hopen::AppUtil>.

=head2 Components used by the build system
Note: everything in this document is subject to change since Build::Hopen
is currently under active development.

=head1 COMPONENTS USED BY THE BUILD SYSTEM

=over

Expand Down Expand Up @@ -83,9 +86,9 @@ After C<MY.hopen.pl> runs, the generator and toolset are loaded.

The last-sorting C<.hopen.pl> or C<*.hopen.pl> file in the project directory.
You can name your project file whatever you want --- only the extension
has to match. That way you can call your build file C<.hopen> if
you want it hidden, or C<z.hopen> if you want it to sort below all your other
files. Sort order is Perl's default, which is by byte value.
has to match. That way you can call your build file C<.hopen.pl> if
you want it hidden, or C<z.hopen.pl> if you want it to sort below all your
other files. Sort order is Perl's default, which is by byte value.

=item * Context file

Expand Down Expand Up @@ -128,13 +131,13 @@ packages loaded (via L<Build::Hopen::HopenFileKit>):

=over

=item L<Build::Hopen>
=item * L<Build::Hopen>

=item L<Build::Hopen::Base>
=item * L<Build::Hopen::Base>

=item L<Build::Hopen::Phases>
=item * L<Build::Hopen::Phases>

=item L<Path::Class>
=item * L<Path::Class>

=back

Expand Down Expand Up @@ -194,8 +197,8 @@ You can do this by running C<hopen --build>, if you wish.

=head2 The build graph

Each operation (L<Build::Hopen::G::Op> subclass) returns or adds to a C<work>
arrayref. For example:
Each operation (L<Build::Hopen::G::Op> subclass) returns, or adds to
the beginning of, a C<work> arrayref. For example:

{
work => [
Expand Down
10 changes: 4 additions & 6 deletions lib/Build/Hopen/G.pod
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ tools used in the hopen build system are under L<Build::Hopen::Tool>.

=head2 C<Build::Hopen::G::Op>

An operation. Operations should, generally speaking, invoke a generator
routine (L<Build::Hopen::Gen>) based on their inputs. Operations should
output values representing the generator action they took.

B<TODO> Should operations pass through all inputs they don't use or transform?
I am inclined to think they should, but this needs testing.
An operation. Operations can, e.g., transform their inputs or invoke a
generator routine (L<Build::Hopen::Gen>) based on their inputs. Operations
can output values representing the generator action they took, or that will
later be used by the generator or downstream nodes.

=head2 C<Build::Hopen::G::Link>

Expand Down
Loading

0 comments on commit 7abdaf1

Please sign in to comment.