Mac OS X に HTML::Tidy がインストールできるといいな

パッチをあてて HTML::Tidy のインストールを試してみる

まずは HTML::Tidy のソースをダウンロードする。

% mkdir ~/src
% cd src
% wget http://search.cpan.org/CPAN/authors/id/P/PE/PETDANCE/HTML-Tidy-1.08.tar.gz
--2010-03-09 23:46:54--  http://search.cpan.org/CPAN/authors/id/P/PE/PETDANCE/HTML-Tidy-1.08.tar.gz
2010-03-09 23:46:55 (384 KB/s) - `HTML-Tidy-1.08.tar.gz' へ保存完了 [26399/26399]

ソースを展開する

% tar zxvf HTML-Tidy-1.08.tar.gz
% cd HTML-Tidy-1.08/
% ls -l
total 120
-rw-r--r--   1 littlebuddha  staff   2418 11 11  2006 Changes
-rw-r--r--   1 littlebuddha  staff    544  4 14  2007 MANIFEST
-rw-r--r--   1 littlebuddha  staff    524  4 14  2007 META.yml
-rw-r--r--   1 littlebuddha  staff   2011 11 11  2006 Makefile.PL
-rw-r--r--   1 littlebuddha  staff   2105  9 25  2006 README
-rw-r--r--   1 littlebuddha  staff   6566 11 11  2006 Tidy.xs
drwxr-xr-x   3 littlebuddha  staff    102  4 14  2007 bin
drwxr-xr-x   3 littlebuddha  staff    102  4 14  2007 lib
-rw-r--r--   1 littlebuddha  staff    516  9 25  2006 perlcriticrc
-rw-r--r--   1 littlebuddha  staff  26438  9 25  2006 ppport.h
drwxr-xr-x  27 littlebuddha  staff    918  4 14  2007 t

パッチをダウンロードする

Bug #29593 for HTML-Tidy: PATCH fixing coredumps in 1.08 からダウンロードしたパッチ tidy.patch を HTML::Tidy のソースを展開したディレクトリに移動する。
ホームディレクトリに tidy.patch を保存したと仮定する。

% cp ~/tidy.pathc ~/src/HTML-Tidy-1.08/tidy.patch

% less tidy.patch
--- Tidy.xs.orig        2007-09-24 11:36:19.000000000 +0200
+++ Tidy.xs     2007-09-24 11:37:42.000000000 +0200
@@ -55,6 +55,7 @@ _tidy_messages(input, configfile, tidy_o
         const char* newline;
         int rc = 0;
     PPCODE:
+        tidyBufInit(&errbuf);
         rc = ( tidyOptSetValue( tdoc, TidyCharEncoding, "utf8" ) ? rc : -1 );
 
         if ( (rc >= 0 ) && configfile && *configfile ) {
@@ -117,6 +118,8 @@ _tidy_clean(input, configfile, tidy_opti
         const char* newline;
         int rc = 0;
     PPCODE:
+        tidyBufInit(&output);
+        tidyBufInit(&errbuf);
         /* Set our default first. */
         /* Don't word-wrap */
         rc = ( tidyOptSetInt( tdoc, TidyWrapLen, 0 ) ? rc : -1 );
tidy.patch (END)

パッチをあてる

% patch -b < tidy.patch
% ls -l
-rw-r--r--   1 littlebuddha  staff   6656  3  9 23:58 Tidy.xs
-rw-r--r--   1 littlebuddha  staff   6566  3  9 23:49 Tidy.xs.orig

Tidy.xs.orig がオリジナルのファイルで、Tidy.xs はパッチが適用されたファイルとなる。

makefile を生成する

% sudo ranlib /opt/local/lib/libtidy.a
Password:
% perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for HTML::Tidy
% make 
cp lib/HTML/Tidy/Message.pm blib/lib/HTML/Tidy/Message.pm
cp lib/HTML/Tidy.pm blib/lib/HTML/Tidy.pm
/opt/local/bin/perl /opt/local/lib/perl5/vendor_perl/5.8.9/ExtUtils/xsubpp  -typemap /opt/local/lib/perl5/5.8.9/ExtUtils/typemap  Tidy.xs > Tidy.xsc && mv Tidy.xsc Tidy.c
/usr/bin/gcc-4.2 -c  -I. -I/usr/include/tidy -I/usr/local/include/tidy -I/sw/include/tidy -fno-common -DPERL_DARWIN -I/opt/local/include -no-cpp-precomp -fno-strict-aliasing -pipe -I/opt/local/include -O3   -DVERSION=\"1.08\" -DXS_VERSION=\"1.08\"  "-I/opt/local/lib/perl5/5.8.9/darwin-2level/CORE"   Tidy.c
In file included from /usr/include/tidy/tidy.h:70,
                 from Tidy.xs:5:
/usr/include/tidy/platform.h:107:1: warning: "HAS_VSNPRINTF" redefined
In file included from /opt/local/lib/perl5/5.8.9/darwin-2level/CORE/perl.h:38,
                 from Tidy.xs:2:
/opt/local/lib/perl5/5.8.9/darwin-2level/CORE/config.h:3783:1: warning: this is the location of the previous definition
Running Mkbootstrap for HTML::Tidy ()
chmod 644 Tidy.bs
rm -f blib/arch/auto/HTML/Tidy/Tidy.bundle
LD_RUN_PATH="/opt/local/lib" env MACOSX_DEPLOYMENT_TARGET=10.3 /usr/bin/gcc-4.2  -L/opt/local/lib -bundle -undefined dynamic_lookup Tidy.o  -o blib/arch/auto/HTML/Tidy/Tidy.bundle 	\
	   -ltidy  	\
	  
chmod 755 blib/arch/auto/HTML/Tidy/Tidy.bundle
cp Tidy.bs blib/arch/auto/HTML/Tidy/Tidy.bs
chmod 644 blib/arch/auto/HTML/Tidy/Tidy.bs
cp bin/webtidy blib/script/webtidy
/opt/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/webtidy
Manifying blib/man3/HTML::Tidy::Message.3pm
Manifying blib/man3/HTML::Tidy.3pm

テストをしてみる

% make test
PERL_DL_NONLAZY=1 /opt/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-load............ok                                                      
t/cfg-for-parse......dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 3
	Failed 1/3 tests, 66.67% okay
t/clean-crash........dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 3
	Failed 1/3 tests, 66.67% okay
t/extra-quote........dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED tests 3-4
	Failed 2/4 tests, 50.00% okay
t/ignore-text........dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 3
	Failed 1/3 tests, 66.67% okay
t/ignore.............dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED tests 3-7
	Failed 5/7 tests, 28.57% okay
t/levels.............dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 3
	Failed 1/3 tests, 66.67% okay
t/message............ok                                                      
t/opt-00.............dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 2
	Failed 1/2 tests, 50.00% okay
t/perfect............dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 3
	Failed 1/3 tests, 66.67% okay
t/pod-coverage.......skipped
        all skipped: Test::Pod::Coverage 1.04 required for testing POD coverage
t/pod................skipped
        all skipped: Test::Pod 1.14 required for testing POD
t/roundtrip..........dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED tests 3-4
	Failed 2/4 tests, 50.00% okay
t/segfault-form......dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED tests 2-3
	Failed 2/3 tests, 33.33% okay
t/simple.............dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED tests 3-4
	Failed 2/4 tests, 50.00% okay
t/too-many-titles....dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 3
	Failed 1/3 tests, 66.67% okay
t/unicode............dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED tests 4-7
	Failed 4/7 tests, 42.86% okay
t/venus..............dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 3
	Failed 1/3 tests, 66.67% okay
t/version............ok                                                      
t/wordwrap...........dubious                                                 
	Test returned status 0 (wstat 11, 0xb)
DIED. FAILED test 2
	Failed 1/2 tests, 50.00% okay
Failed Test         Stat Wstat Total Fail  List of Failed
-------------------------------------------------------------------------------
t/cfg-for-parse.t      0    11     3    2  3
t/clean-crash.t        0    11     3    2  3
t/extra-quote.t        0    11     4    4  3-4
t/ignore-text.t        0    11     3    2  3
t/ignore.t             0    11     7   10  3-7
t/levels.t             0    11     3    2  3
t/opt-00.t             0    11     2    2  2
t/perfect.t            0    11     3    2  3
t/roundtrip.t          0    11     4    4  3-4
t/segfault-form.t      0    11     3    4  2-3
t/simple.t             0    11     4    4  3-4
t/too-many-titles.t    0    11     3    2  3
t/unicode.t            0    11     7    8  4-7
t/venus.t              0    11     3    2  3
t/wordwrap.t           0    11     2    2  2
2 tests skipped.
Failed 15/20 test scripts. 26/75 subtests failed.
Files=20, Tests=75,  2 wallclock secs ( 0.59 cusr +  0.18 csys =  0.77 CPU)
Failed 15/20 test programs. 26/75 subtests failed.
make: *** [test_dynamic] Error 255

見事にテストがこける…。

でも、インストールはできてしまう

すんなりとファイルが配置される。

% make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/auto/HTML/Tidy/Tidy.bs
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/auto/HTML/Tidy/Tidy.bundle
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/HTML/Tidy.pm
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/HTML/Tidy/Message.pm
Installing /Users/littlebuddha/local/man/man3/HTML::Tidy.3pm
Installing /Users/littlebuddha/local/man/man3/HTML::Tidy::Message.3pm
Installing /Users/littlebuddha/local/bin/webtidy
Writing /Users/littlebuddha/local/lib/perl5/darwin-2level/auto/HTML/Tidy/.packlist
Appending installation info to /Users/littlebuddha/local/lib/perl5/darwin-2level/perllocal.pod

正常に動かない場合は、インストールされた上記のファイルを手動で消すしかないか…。
注: CPAN モジュールの local::lib を利用しているため、インストールされるディレクトリは通常と異なる。