Re: Install custom files

Simon Ruderich <[email protected]> Mon, 4 Apr 2011 15:55:24 +0200
Newsgroups gmane.comp.lang.perl.modules.module-build
Message-ID <[email protected]>
--=_zucker.schokokeks.org-29450-1301925325-0001-2
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Apr 01, 2011 at 09:15:53PM +0200, Leon Timmermans wrote:
> On Fri, Apr 1, 2011 at 7:15 PM, Simon Ruderich wrote:
>> I'm trying to install custom files to a specific location which
>> should be relative to the given prefix/install_base/.. In this
>> case into share/locale. So e.g. if --prefix=3D/usr/local then it
>> should install into /usr/local/share/locale/.
>
> How do you call your Build/Build.PL exactly? Do you call your example
> with --install_base?

Hi Leon,

Thanks for your quick response.

Yes, I tried --install_base and --prefix, both have the same
problem. It looks like --destdir also doesn't work with ./Build,
just with perl Build.PL. I'm not sure if this is expected or a
bug.

>> I'm using Module::Build 0.340201 on Debian Squeeze.

> You might want to upgrade to a more recent version of Module::Build.
> =C2=ABapt-get install libmodule-build-perl=C2=BB should upgrade it to 0.3=
607.
> CPAN will upgrade it to 0.38. It might solve your problems.

Retried with 0.38, same problem.

>>    $build->add_build_element('locale');
>>    $build->install_base_relpaths(locale =3D> 'locale');
>
> The general solution looks something like this:
>
>   use File::Spec 'catdir';
>   =E2=80=A6
>   $build->add_build_element('locale');
>   $build->install_base_relpaths(locale =3D> catdir('share', 'locale'));
>   $build->prefix_relpaths($_, locale =3D> catdir('share', 'locale')) for
> qw/core vendor site/;
>   $build->install_sets($_, 'locale',
> catdir($build->original_prefix($_)), 'share', 'locale')) for qw/core
> vendor site/;

Hm, looks really complicated for such a simple task :-/

But it works fine, thanks for your help.

> Yeah, you need all of that for all options to work as you expect them
> to. Also, you then have to figure out a way for your program to know
> where to find the files, but that's a different discussion.

Yeah, at the moment I rewrite the files to point to the right
place. My current solution feels really like a hack:

    # Fix some paths so custom installation paths work.
    sub ACTION_build {
        my $self =3D shift;

        $self->SUPER::ACTION_build;

        $self->sed('blib/script/pabook',
                   'LIBDIR', $self->install_destination('lib'));
        $self->sed('blib/lib/Pabook/Util.pm',
                   'LOCALEDIR', $self->install_destination('locale'));
    }
    sub sed {
        my $self =3D shift;
        my ($file, $search, $replacement) =3D @_;

        $replacement =3D~ s/\//\\\//g;
        $self->do_system('perl', '-pi', '-e',
                         "s/$search/$replacement/g", $file);
    }

Is there a simple way for text replacements like this in
Module::Build (or maybe a better way to do it)? One known problem
with my solution is that a --prefix/--install_base change doesn't
case an update to the file, so it points to the wrong path.

> A much simpler solution in your case would be to use the sharedir
> functionality of Module::Build (available since 0.36). It doesn't
> sound like you need something sharedir can't provide.

I had a look at it, but I want a path like /usr/share/locale, and
it gives me something like /usr/share/perl/5.10.1/auto/<package-name>.

But the solution you gave me above works fine.

>> It seems to work, but doesn't look like a good solution. Is there
>> a variable which returns the absolute installation prefix? I
>> couldn't find any in the documentation.
>
> No, that's not how it works on the inside: an absolute installation
> prefix is only well-defined in a limited set of circumstances (when
> using --prefix and --install_base).

I see the problem now - I'm only used to --prefix so I didn't
think of that.

> Leon

Regards,
Simon
--=20
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

--=_zucker.schokokeks.org-29450-1301925325-0001-2
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAEBCAAGBQJNmc3MAAoJEJL+/bfkTDL5EisQAKy/cdNbB3AxuGl4YPJk9bPk
0bTG2jBUNEir9bCnPKBkvae8KftZfBl8Db0KMhkV8pKTeqqCUJeCdNaJe05ipg6d
ltyx0KEck4utzZqbVZW4E0LpNWkYEzopAv0kSl/240KNRHNUAZfQFhJbPFh/CLXs
Ih0ulGNcPUx0KoAE5Wdn4FdspeipSbzdEJh0OXke91rAmFeIS386o6m1SYn860IJ
TCEUluqir0VwXWwrE/ro+VNYStGqZLZhb+A+owSmrghp7j3AZHnkezMJ/fuWLQGO
TqUX/lmEGBsf3UCbpRTdC7xCbGXA6HfwL59MryVrjGF1rVWtKMLtFg9ocKQpgSat
bCe+kHal3HPqoxlv0Tnpy8W6FoEOyeTWZf/JCuQuw7WJoyMOl8JZG8cyP10keC7o
qqG+vACq5DYDE/OmIOZTdFWvpqlVFSRAAozFKyYjJQ3n/boEqwc5K6StdOrJ2nYZ
/GTuhX5qj2WMtcoc0oy7/TxX4xVi1hVcXPIfspsC+OM//Bmk+S9qns15ehQFNCXR
le8J7S59lrNVDrDpXrh7XUWbTup71OJMKBQhR25XClEWh9LqyP2XssRL+u0/ivlN
ve6vur+IHK0ioSKqQ0Pd9MSJDLMOcPxy4d4TfoxDAK83dTC/onPTdU6TW0NaTbsj
egi5BQ1unPSRNq8lBpKt
=FEsG
-----END PGP SIGNATURE-----

--=_zucker.schokokeks.org-29450-1301925325-0001-2--