Types.pm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_SOURCE_DEP
  27. BUILD_SOURCE_INDEP
  28. BUILD_FULL
  29. build_has
  30. build_has_not
  31. build_is
  32. set_build_type
  33. );
  34. use Exporter qw(import);
  35. use Dpkg::Gettext;
  36. use Dpkg::ErrorHandling;
  37. =encoding utf8
  38. =head1 NAME
  39. Dpkg::Build::Types - track build types
  40. =head1 DESCRIPTION
  41. The Dpkg::Build::Types module is used by various tools to track and decide
  42. what artifacts need to be built.
  43. The build types are bit constants that are exported by default. Multiple
  44. types can be ORed.
  45. =head1 CONSTANTS
  46. =over 4
  47. =item BUILD_DEFAULT
  48. This build is the default.
  49. =item BUILD_SOURCE
  50. This build includes source artifacts.
  51. =item BUILD_ARCH_DEP
  52. This build includes architecture dependent binary artifacts.
  53. =item BUILD_ARCH_INDEP
  54. This build includes architecture independent binary artifacts.
  55. =item BUILD_BINARY
  56. This build includes binary artifacts.
  57. =item BUILD_SOURCE_DEP
  58. This build includes source and architecture dependent binary artifacts.
  59. =item BUILD_SOURCE_INDEP
  60. This build includes source and architecture independent binary artifacts.
  61. =item BUILD_FULL
  62. This build includes source and binary artifacts.
  63. =cut
  64. # Simple types.
  65. use constant {
  66. BUILD_DEFAULT => 1,
  67. BUILD_SOURCE => 2,
  68. BUILD_ARCH_DEP => 4,
  69. BUILD_ARCH_INDEP => 8,
  70. };
  71. # Composed types.
  72. use constant {
  73. BUILD_BINARY => BUILD_ARCH_DEP | BUILD_ARCH_INDEP,
  74. BUILD_SOURCE_DEP => BUILD_SOURCE | BUILD_ARCH_DEP,
  75. BUILD_SOURCE_INDEP => BUILD_SOURCE | BUILD_ARCH_INDEP,
  76. };
  77. use constant {
  78. BUILD_FULL => BUILD_BINARY | BUILD_SOURCE,
  79. };
  80. my $current_type = BUILD_FULL | BUILD_DEFAULT;
  81. my $current_option = undef;
  82. =back
  83. =head1 FUNCTIONS
  84. =over 4
  85. =item build_has($bits)
  86. Return a boolean indicating whether the current build type has the specified
  87. $bits.
  88. =cut
  89. sub build_has
  90. {
  91. my ($bits) = @_;
  92. return ($current_type & $bits) == $bits;
  93. }
  94. =item build_has_not($bits)
  95. Return a boolean indicating whether the current build type does not have the
  96. specified $bits.
  97. =cut
  98. sub build_has_not
  99. {
  100. my ($bits) = @_;
  101. return ($current_type & $bits) != $bits;
  102. }
  103. =item build_is($bits)
  104. Return a boolean indicating whether the current build type is the specified
  105. set of $bits.
  106. =cut
  107. sub build_is
  108. {
  109. my ($bits) = @_;
  110. return $current_type == $bits;
  111. }
  112. =item set_build_type($build_type, $build_option)
  113. Set the current build type to $build_type, which was specified via the
  114. $build_option command-line option.
  115. =cut
  116. sub set_build_type
  117. {
  118. my ($build_type, $build_option) = @_;
  119. usageerr(g_('cannot combine %s and %s'), $current_option, $build_option)
  120. if build_has_not(BUILD_DEFAULT) and $current_type != $build_type;
  121. $current_type = $build_type;
  122. $current_option = $build_option;
  123. }
  124. =back
  125. =head1 CHANGES
  126. =head2 Version 0.xx
  127. This is a private module.
  128. =cut
  129. 1;