Types.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # Copyright © 2007 Frank Lichtenheld <djpig@debian.org>
  2. # Copyright © 2010, 2013-2016 Guillem Jover <guillem@debian.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package Dpkg::Build::Types;
  17. use strict;
  18. use warnings;
  19. our $VERSION = '0.01';
  20. our @EXPORT = qw(
  21. BUILD_DEFAULT
  22. BUILD_SOURCE
  23. BUILD_ARCH_DEP
  24. BUILD_ARCH_INDEP
  25. BUILD_BINARY
  26. BUILD_FULL
  27. build_has
  28. build_has_not
  29. build_is
  30. set_build_type
  31. );
  32. use Exporter qw(import);
  33. use Dpkg::Gettext;
  34. use Dpkg::ErrorHandling;
  35. =encoding utf8
  36. =head1 NAME
  37. Dpkg::Build::Types - track build types
  38. =head1 DESCRIPTION
  39. The Dpkg::Build::Types module is used by various tools to track and decide
  40. what artifacts need to be built.
  41. The build types are bit constants that are exported by default. Multiple
  42. types can be ORed.
  43. =head1 CONSTANTS
  44. =over 4
  45. =item BUILD_DEFAULT
  46. This build is the default.
  47. =item BUILD_SOURCE
  48. This build includes source artifacts.
  49. =item BUILD_ARCH_DEP
  50. This build includes architecture dependent binary artifacts.
  51. =item BUILD_ARCH_INDEP
  52. This build includes architecture independent binary artifacts.
  53. =item BUILD_BINARY
  54. This build includes binary artifacts.
  55. =item BUILD_FULL
  56. This build includes source and binary artifacts.
  57. =cut
  58. # Simple types.
  59. use constant {
  60. BUILD_DEFAULT => 1,
  61. BUILD_SOURCE => 2,
  62. BUILD_ARCH_DEP => 4,
  63. BUILD_ARCH_INDEP => 8,
  64. };
  65. # Composed types.
  66. use constant BUILD_BINARY => BUILD_ARCH_DEP | BUILD_ARCH_INDEP;
  67. use constant BUILD_FULL => BUILD_BINARY | BUILD_SOURCE;
  68. my $current_type = BUILD_FULL | BUILD_DEFAULT;
  69. my $current_option = undef;
  70. =back
  71. =head1 FUNCTIONS
  72. =over 4
  73. =item build_has($bits)
  74. Return a boolean indicating whether the current build type has the specified
  75. $bits.
  76. =cut
  77. sub build_has
  78. {
  79. my ($bits) = @_;
  80. return ($current_type & $bits) == $bits;
  81. }
  82. =item build_has_not($bits)
  83. Return a boolean indicating whether the current build type does not have the
  84. specified $bits.
  85. =cut
  86. sub build_has_not
  87. {
  88. my ($bits) = @_;
  89. return ($current_type & $bits) != $bits;
  90. }
  91. =item build_is($bits)
  92. Return a boolean indicating whether the current build type is the specified
  93. set of $bits.
  94. =cut
  95. sub build_is
  96. {
  97. my ($bits) = @_;
  98. return $current_type == $bits;
  99. }
  100. =item set_build_type($build_type, $build_option)
  101. Set the current build type to $build_type, which was specified via the
  102. $build_option command-line option.
  103. =cut
  104. sub set_build_type
  105. {
  106. my ($build_type, $build_option) = @_;
  107. usageerr(g_('cannot combine %s and %s'), $current_option, $build_option)
  108. if build_has_not(BUILD_DEFAULT) and $current_type != $build_type;
  109. $current_type = $build_type;
  110. $current_option = $build_option;
  111. }
  112. =back
  113. =head1 CHANGES
  114. =head2 Version 0.xx
  115. This is a private module.
  116. =cut
  117. 1;