/fw/package/check-for-pkgconfig-packages

http://github.com/cliffmoon/effigy · Perl · 165 lines · 100 code · 43 blank · 22 comment · 3 complexity · 2417f7ea5ca78ed79d94abd9a394cb5c MD5 · raw file

  1. #! /usr/bin/perl
  2. use strict;
  3. use IO::Pipe;
  4. use POSIX ":sys_wait_h";
  5. #---------------------------------------------------------------------
  6. # proctalk
  7. #
  8. # Fork a process and talk to it over a pipe pair.
  9. #---------------------------------------------------------------------
  10. sub proctalk ($$)
  11. {
  12. my ($parent_code, $child_code) = @_;
  13. my $par_to_child = new IO::Pipe;
  14. my $child_to_par = new IO::Pipe;
  15. my $pid;
  16. if ($pid = fork ())
  17. {
  18. # parent
  19. $par_to_child->writer ();
  20. $child_to_par->reader ();
  21. $parent_code-> ($child_to_par, $par_to_child);
  22. undef $par_to_child;
  23. undef $child_to_par;
  24. waitpid ($pid, 0);
  25. die "$0: fatal: subprocess failed" if $?;
  26. }
  27. else
  28. {
  29. # child
  30. $par_to_child->reader ();
  31. $child_to_par->writer ();
  32. $child_code-> ($par_to_child, $child_to_par);
  33. die "$0: fatal: child_code failed to exit";
  34. }
  35. }
  36. #---------------------------------------------------------------------
  37. # check_for_packages
  38. #
  39. # Check for the (installed) packages which correspond to the
  40. # build dependencies.
  41. #---------------------------------------------------------------------
  42. sub check_for_packages ($$$)
  43. {
  44. my ($arch, $depends, $package_type) = @_;
  45. my @packages;
  46. proctalk (
  47. sub
  48. {
  49. my ($readfh, $writefh) = @_;
  50. @packages = map { chomp; $_ } <$readfh>;
  51. },
  52. sub
  53. {
  54. my ($readfh, $writefh) = @_;
  55. close STDIN;
  56. open STDIN, "<&", $readfh or die "$0: fatal: can't dup STDIN: $!";
  57. close STDOUT;
  58. open STDOUT, ">&", $writefh or die "$0: fatal: can't dup STDOUT: $!";
  59. close STDERR unless $ENV{"FW_TRACE"};
  60. exec ("fw-exec",
  61. "package/$package_type/check-for-packages",
  62. "--arch",
  63. "$arch",
  64. "--depends",
  65. "$depends",
  66. "--release",
  67. "yes")
  68. or die "$0: fatal: exec failed: $!";
  69. }
  70. );
  71. return \@packages;
  72. }
  73. #---------------------------------------------------------------------
  74. # find_pc_files
  75. #
  76. # Find all the .pc files in a given set of (installed) packages.
  77. #---------------------------------------------------------------------
  78. sub find_pc_files ($$)
  79. {
  80. my ($package_type, $packages) = @_;
  81. my %pc_filez;
  82. proctalk (
  83. sub
  84. {
  85. my ($readfh, $writefh) = @_;
  86. foreach my $p (@$packages)
  87. {
  88. print $writefh "$p\n";
  89. }
  90. $writefh->close ();
  91. while (defined ($_ = <$readfh>))
  92. {
  93. chomp;
  94. next unless m%/([^/]+)\.pc$%;
  95. $pc_filez{$1} = 1;
  96. }
  97. },
  98. sub
  99. {
  100. my ($readfh, $writefh) = @_;
  101. close STDIN;
  102. open STDIN, "<&", $readfh or die "$0: fatal: can't dup STDIN: $!";
  103. close STDOUT;
  104. open STDOUT, ">&", $writefh or die "$0: fatal: can't dup STDOUT: $!";
  105. close STDERR unless $ENV{"FW_TRACE"};
  106. exec "xargs",
  107. "fw-exec",
  108. "package/$package_type/list-files"
  109. or die "$0: fatal: exec failed: $!";
  110. }
  111. );
  112. return keys %pc_filez;
  113. }
  114. #---------------------------------------------------------------------
  115. # main
  116. #---------------------------------------------------------------------
  117. my $usage = "package/check-for-pkgconfig-packages: fatal: usage: $0 arch depends package_type\n";
  118. my $arch = $ARGV[0] or die $usage;
  119. my $depends = $ARGV[1] or die $usage;
  120. my $package_type = $ARGV[2] or die $usage;
  121. my $packages = check_for_packages ($arch, $depends, $package_type);
  122. print join " ", find_pc_files ($package_type, $packages);