Skip to content
This repository

Add $meta{prereqs}{test} to MYMETA.json and META.json #14

Closed
wants to merge 1 commit into from

5 participants

Masahiro Nagano Leon Timmermans Tatsuhiko Miyagawa Karen Etheridge David Golden
Masahiro Nagano

Module::Build 0.4004 supports test_configure. But MYMETA.json and META.json (generated by perl ./Build.PL and ./Build distmeta) does not have $meta{prereqs}{test}. They have x_test_requires.

After ./Build distmata, When I run perl ./Build.PL again. I got $meta{prereqs}{test} in MYMETA.json.
It is enough for installing prereqs modules, but confusing. I want to get $meta{prereqs}{test} in first perl ./Build.PL

This patch upgrades a metadata that created by get_metadata() to spec-2 before write meta files.

Leon Timmermans
Owner
Leont commented April 02, 2013

I don't think deleting x_test_requires is the right solution. We should add it correctly in the first place so it won't be added like that at all.

Something goes wrong between CPAN::Meta::Convert and Module::Build, not entirely sure what the solution is yet.

Tatsuhiko Miyagawa
Collaborator

META spec 1.4 doesn't support test_requires, does it?
http://module-build.sourceforge.net/META-spec-v1.4.html

Leon Timmermans
Owner
Leont commented April 04, 2013

META spec 1.4 doesn't support test_requires, does it?
Indeed, but M::B seems to be inserting all prereqs into it regardless.

The core problem is that Module::Build (like MakeMaker) is Meta 1.4 on the inside. Fixing this is non-trivial.

Karen Etheridge
Collaborator
Tatsuhiko Miyagawa
Collaborator

If anyone can fix the root cause for that at QAH would be great, but @kazeburo's patch upgrades to 2.0 in-place and it works better than what we have today nonetheless.

David Golden
Owner

I think test_requires should get folded into build_requires, just like Module::Install did (or does?). We want to let people specify that they mean "test" for the future should META v2 ever be supported.

Leon Timmermans
Owner

Please test 0.40_09, it should fix this issue.

Leon Timmermans
Owner

Closed, as this this has been fixed in the 0.420X series of releases.

Leon Timmermans Leont closed this January 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 02, 2013
Masahiro Nagano upgrade meta to spec-2 in _get_meta_object. For generating prereqs->{…
…types} in MYMETA.json and META.json
dce6d40
This page is out of date. Refresh to see the latest.
59  lib/Module/Build/Base.pm
@@ -1912,29 +1912,7 @@ sub create_mymeta {
1912 1912
   # if we have metadata, just update it
1913 1913
   if ( defined $mymeta ) {
1914 1914
     my $prereqs = $self->_normalize_prereqs;
1915  
-    # XXX refactor this mapping somewhere
1916  
-    $mymeta->{prereqs}{runtime}{requires} = $prereqs->{requires};
1917  
-    $mymeta->{prereqs}{build}{requires} = $prereqs->{build_requires};
1918  
-    $mymeta->{prereqs}{test}{requires} = $prereqs->{test_requires};
1919  
-    $mymeta->{prereqs}{runtime}{recommends} = $prereqs->{recommends};
1920  
-    $mymeta->{prereqs}{runtime}{conflicts} = $prereqs->{conflicts};
1921  
-    # delete empty entries
1922  
-    for my $phase ( keys %{$mymeta->{prereqs}} ) {
1923  
-      if ( ref $mymeta->{prereqs}{$phase} eq 'HASH' ) {
1924  
-        for my $type ( keys %{$mymeta->{prereqs}{$phase}} ) {
1925  
-          if ( ! defined $mymeta->{prereqs}{$phase}{$type}
1926  
-            || ! keys %{$mymeta->{prereqs}{$phase}{$type}}
1927  
-          ) {
1928  
-            delete $mymeta->{prereqs}{$phase}{$type};
1929  
-          }
1930  
-        }
1931  
-      }
1932  
-      if ( ! defined $mymeta->{prereqs}{$phase}
1933  
-        || ! keys %{$mymeta->{prereqs}{$phase}}
1934  
-      ) {
1935  
-        delete $mymeta->{prereqs}{$phase};
1936  
-      }
1937  
-    }
  1915
+    $self->_merge_meta_prereqs($mymeta, $prereqs);
1938 1916
     $mymeta->{dynamic_config} = 0;
1939 1917
     $mymeta->{generated_by} = "Module::Build version $Module::Build::VERSION";
1940 1918
     eval { $meta_obj = CPAN::Meta->new( $mymeta, { lazy_validation => 1 } ) }
@@ -1954,6 +1932,35 @@ sub create_mymeta {
1954 1932
   return 1;
1955 1933
 }
1956 1934
 
  1935
+sub _merge_meta_prereqs {
  1936
+    my ($self, $meta, $prereqs) = @_;
  1937
+
  1938
+    $meta->{prereqs}{runtime}{requires} = $prereqs->{requires};
  1939
+    $meta->{prereqs}{build}{requires} = $prereqs->{build_requires};
  1940
+    $meta->{prereqs}{test}{requires} = $prereqs->{test_requires};
  1941
+    $meta->{prereqs}{runtime}{recommends} = $prereqs->{recommends};
  1942
+    $meta->{prereqs}{runtime}{conflicts} = $prereqs->{conflicts};
  1943
+
  1944
+    # delete empty entries
  1945
+    for my $phase ( keys %{$meta->{prereqs}} ) {
  1946
+      if ( ref $meta->{prereqs}{$phase} eq 'HASH' ) {
  1947
+        for my $type ( keys %{$meta->{prereqs}{$phase}} ) {
  1948
+          if ( ! defined $meta->{prereqs}{$phase}{$type}
  1949
+            || ! keys %{$meta->{prereqs}{$phase}{$type}}
  1950
+          ) {
  1951
+            delete $meta->{prereqs}{$phase}{$type};
  1952
+          }
  1953
+        }
  1954
+      }
  1955
+      if ( ! defined $meta->{prereqs}{$phase}
  1956
+        || ! keys %{$meta->{prereqs}{$phase}}
  1957
+      ) {
  1958
+        delete $meta->{prereqs}{$phase};
  1959
+      }
  1960
+    }
  1961
+    $meta;
  1962
+}
  1963
+
1957 1964
 sub create_build_script {
1958 1965
   my ($self) = @_;
1959 1966
 
@@ -4571,6 +4578,12 @@ sub _get_meta_object {
4571 4578
     );
4572 4579
     $data->{dynamic_config} = $args{dynamic} if defined $args{dynamic};
4573 4580
     $meta = CPAN::Meta->create( $data );
  4581
+    # XXX get_metadata create spec 1.4 struct. needs to version up
  4582
+    my $meta2 = $meta->as_struct({version => "2"}); 
  4583
+    delete $meta2->{'x_'.$_} for @{$self->prereq_action_types}; 
  4584
+    my $prereqs = $self->_normalize_prereqs;
  4585
+    $self->_merge_meta_prereqs($meta2, $prereqs);
  4586
+    $meta = CPAN::Meta->create( $meta2 );
4574 4587
   };
4575 4588
   if ($@ && ! $args{quiet}) {
4576 4589
     $self->log_warn(
53  t/test_reqs.t
... ...
@@ -0,0 +1,53 @@
  1
+#!/usr/bin/perl -w
  2
+
  3
+use strict;
  4
+use lib 't/lib';
  5
+use MBTest;
  6
+use CPAN::Meta 2.110420;
  7
+use CPAN::Meta::YAML;
  8
+use Parse::CPAN::Meta 1.4401;
  9
+plan tests => 4;
  10
+
  11
+blib_load('Module::Build');
  12
+
  13
+my $tmp = MBTest->tmpdir;
  14
+
  15
+use DistGen;
  16
+my $dist = DistGen->new( dir => $tmp );
  17
+$dist->change_file('Build.PL', <<"---");
  18
+use strict;
  19
+use Module::Build;
  20
+
  21
+my \$builder = Module::Build->new(
  22
+  module_name         => '$dist->{name}',
  23
+  license             => 'perl',
  24
+  requires            => {
  25
+    'File::Spec' => 0,
  26
+  },
  27
+  test_requires       => {
  28
+    'Test::More' => 0,
  29
+  }
  30
+);
  31
+
  32
+\$builder->create_build_script();
  33
+---
  34
+$dist->regen;
  35
+$dist->chdir_in;
  36
+$dist->run_build_pl;
  37
+my $output = stdout_stderr_of sub { $dist->run_build('distmeta') };
  38
+
  39
+for my $file ( qw/MYMETA META/ ) {
  40
+    my $meta = Parse::CPAN::Meta->load_file($file.".json");
  41
+    is_deeply($meta->{prereqs}->{runtime},{
  42
+        requires => {
  43
+            'File::Spec' => '0',
  44
+        }
  45
+    }, "runtime prereqs in $file");
  46
+    is_deeply($meta->{prereqs}->{test},{
  47
+        requires => {
  48
+            'Test::More' => '0',
  49
+        }
  50
+    }, "test prereqs in $file");
  51
+}
  52
+
  53
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.