Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions Build.PL
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
use Dist::Build;
Build_PL(\@ARGV, \%ENV);

# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v6.032.
use strict;
use warnings;

use Module::Build 0.28;
use lib qw{inc}; use MyBuilder;

my %module_build_args = (
"build_requires" => {
"Module::Build" => "0.28"
},
"configure_requires" => {
"IPC::Run3" => 0,
"Module::Build" => "0.4205",
"perl" => "v5.20.0"
},
"dist_abstract" => "call clonefile system call",
"dist_author" => [
"Shoichi Kaji <skaji\@cpan.org>"
],
"dist_name" => "File-Copy-clonefile",
"dist_version" => "v0.0.9",
"license" => "perl",
"module_name" => "File::Copy::clonefile",
"recursive_test_files" => 1,
"requires" => {
"perl" => "v5.20.0"
},
"test_requires" => {
"Test::LeakTrace" => 0
}
);


my %fallback_build_requires = (
"Module::Build" => "0.28",
"Test::LeakTrace" => 0
);


unless ( eval { Module::Build->VERSION(0.4004) } ) {
delete $module_build_args{test_requires};
$module_build_args{build_requires} = \%fallback_build_requires;
}

my $build = MyBuilder->new(%module_build_args);


$build->create_build_script;
12 changes: 9 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
},
"name" : "File-Copy-clonefile",
"prereqs" : {
"build" : {
"requires" : {
"Module::Build" : "0.28"
}
},
"configure" : {
"requires" : {
"Dist::Build" : "0.015",
"IPC::Run3" : "0",
"Module::Build" : "0.4205",
"perl" : "v5.20.0"
}
},
Expand Down Expand Up @@ -53,8 +59,8 @@
"x_contributors" : [
"Leon Timmermans <fawaka@gmail.com>"
],
"x_generated_by_perl" : "v5.40.0",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.38",
"x_generated_by_perl" : "v5.40.2",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.39",
"x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later"
}

11 changes: 0 additions & 11 deletions cpm.yml

This file was deleted.

21 changes: 18 additions & 3 deletions dist.pl
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
my @prereq = (
[ Prereqs => 'ConfigureRequires' ] => [
'IPC::Run3' => '0',
'Module::Build' => '0.4205',
'perl' => 'v5.20',
],
[ Prereqs => 'RuntimeRequires' ] => [
'perl' => 'v5.20',
],
[ Prereqs => 'TestRequires' ] => [
'Test::LeakTrace' => '0',
],
);

my @config = (
name => 'File-Copy-clonefile',

[
'Git::GatherDir' => [ exclude_filename => 'META.json', exclude_filename => 'LICENSE' ],
'CopyFilesFromBuild' => [ copy => 'META.json', copy => 'LICENSE' ],
@prereq,
'Git::GatherDir' => [ exclude_filename => 'META.json', exclude_filename => 'LICENSE', exclude_filename => 'Build.PL' ],
'CopyFilesFromBuild' => [ copy => 'META.json', copy => 'LICENSE', copy => 'Build.PL' ],
'VersionFromMainModule' => [],
'LicenseFromModule' => [ override_author => 1 ],
'ReversionOnRelease' => [ prompt => 1 ],
Expand All @@ -14,7 +29,7 @@
'MetaProvides::Package' => [ inherit_version => 0, inherit_missing => 0 ],
'PruneFiles' => [ filename => 'dist.pl', filename => 'cpm.yml', filename => 'README.md', match => '^(xt|author|maint|example|eg)/' ],
'GitHubREADME::Badge' => [ badges => 'github_actions/test.yml' ],
'Prereqs::From::cpmfile' => [],
'ModuleBuild' => [ mb_class => 'MyBuilder' ],
'MetaJSON' => [],
'Git::Contributors' => [],
'License' => [],
Expand Down
80 changes: 80 additions & 0 deletions inc/MyBuilder.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package MyBuilder;
use v5.20;
use warnings;
use experimental 'signatures';

package MyCBuilder {
use parent 'ExtUtils::CBuilder';
use IPC::Run3 ();

sub do_system ($self, @cmd) {
if (!$self->{quiet}) {
my $full = join ' ', map $self->quote_literal($_), @cmd;
print $full . "\n";
}
IPC::Run3::run3( \@cmd, undef, \my $out, \my $err, { return_if_system_error => 1 } );
my $exit = $?;
if (!$self->{quiet}) {
print {\*STDOUT} $out if $out;
print {\*STDERR} $err if $err;
}
return $exit == 0;
}
}

use parent 'Module::Build';
use ExtUtils::Constant ();
use File::Spec;
use File::Temp ();

my $_clonefile = <<'EOF';
#include <sys/attr.h>
#include <sys/clonefile.h>
int main() {
(void)clonefile("", "", 0);
return 0;
}
EOF

sub new ($class, %argv) {
my $self = $class->SUPER::new(
%argv,
needs_compiler => 1,
-d ".git" ? ( extra_compiler_flags => ['-Wall', '-Wextra', '-Werror'] ) : (),
);
$self->_try_compile_run($_clonefile)
or die "This module only supports platforms that have clonefile system call, such as macos.\n";
$self->_write_constants;
$self;
}

sub _try_compile_run ($self, $source) {
my $cbuilder = MyCBuilder->new(config => $self->config, quiet => !$self->verbose);
my $tempdir = File::Temp->newdir;

my $c_file = File::Spec->catfile($tempdir, "try_compile_run.c");
{ open my $fh, ">", $c_file or die; print {$fh} $source; }
my $obj_file = eval { $cbuilder->compile(source => $c_file) };
if ($@) {
$self->log_verbose($@);
return;
}
my $exe_file = eval { $cbuilder->link_executable(objects => [$obj_file]) };
if ($@) {
$self->log_verbose($@);
return;
}
return $cbuilder->do_system($exe_file);
}

sub _write_constants ($self) {
ExtUtils::Constant::WriteConstants(
NAME => $self->module_name,
NAMES => [qw(CLONE_NOFOLLOW CLONE_NOOWNERCOPY CLONE_ACL)],
PROXYSUBS => { autoload => 1 },
C_FILE => 'lib/File/Copy/const-c.inc',
XS_FILE => 'lib/File/Copy/const-xs.inc',
);
}

1;
30 changes: 0 additions & 30 deletions planner/planner.pl

This file was deleted.