source: trunk/debathena/third/schroot/bin/csbuild/csbuild-options.cc @ 24167

Revision 24167, 6.8 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
1/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
2 *
3 * schroot is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * schroot is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 *********************************************************************/
18
19#include <config.h>
20
21#include <sbuild/sbuild-i18n.h>
22
23#include "csbuild-options.h"
24
25#include <cstdlib>
26#include <iostream>
27
28#include <boost/format.hpp>
29#include <boost/program_options.hpp>
30
31using std::endl;
32using boost::format;
33using sbuild::string_list;
34using sbuild::_;
35namespace opt = boost::program_options;
36using namespace csbuild;
37
38const options::action_type options::ACTION_BUILD ("build");
39
40options::options ():
41  schroot_base::options(),
42  packages(),
43  nolog(false),
44  batch_mode(false),
45  deb_build_options(),
46  deb_build_options_string(),
47  distribution(),
48  archive(),
49  build_arch(),
50  build_arch_all(false),
51  build_source(false),
52  force_orig_source(false),
53  bin_nmu(false),
54  bin_nmu_changelog(),
55  bin_nmu_version(0),
56  append_version(),
57  apt_update(false),
58  chroot(),
59  purge_string(),
60  purge(PURGE_ALWAYS),
61  purge_deps_string(),
62  purge_deps(PURGE_ALWAYS),
63  setup_hook_script(),
64  keyid(),
65  maintainer(),
66  uploader(),
67  build_depends(),
68  build_conflicts(),
69  build_depends_indep(),
70  build_conflicts_indep(),
71  depends_algorithm(),
72  gcc_snapshot(false),
73  build(_("Build options")),
74  version(_("Package version options")),
75  chrootopt(_("Build environment options")),
76  user(_("User options")),
77  depends(_("Build dependency override options")),
78  special(_("Special options"))
79{
80}
81
82options::~options ()
83{
84}
85
86void
87options::add_options ()
88{
89  // Chain up to add basic options.
90  schroot_base::options::add_options();
91
92  action.add(ACTION_BUILD);
93  action.set_default(ACTION_BUILD);
94
95  actions.add_options()
96    ("build",
97     _("Build source packages (default)"));
98
99  general.add_options()
100    ("nolog,n", _("Don't log program output"))
101    ("batch,b", _("Run in batch mode"));
102
103  build.add_options()
104    ("debbuildopt", opt::value<sbuild::string_list>(&this->deb_build_options),
105     _("dpkg-buildpackage option"))
106    ("debbuildopts", opt::value<std::string>(&this->deb_build_options_string),
107     _("dpkg-buildpackage options (space-separated)"))
108    ("dist,d", opt::value<std::string>(&this->distribution),
109     _("Distribution to build for"))
110    ("archive", opt::value<std::string>(&this->archive),
111     _("Archive to build for"))
112    ("arch", opt::value<std::string>(&this->build_arch),
113     _("Build architecture"))
114    ("arch-all,A",
115     _("Build architecture \"all\" packages"))
116    ("source,s",
117     _("Build a source package"))
118    ("force-orig-source",
119     _("Force building of a source package, irrespective of Debian version"));
120
121  version.add_options()
122    ("make-binNMU", opt::value<std::string>(&this->bin_nmu_changelog),
123     _("Make a binary non-maintainer upload (changelog entry)"))
124    ("binNMU", opt::value<unsigned int>(&this->bin_nmu_version),
125     _("Make a binary non-maintainer upload (binNMU number)"))
126    ("append-to-version", opt::value<std::string>(&this->append_version),
127     _("Append version suffix"));
128
129  chrootopt.add_options()
130    ("apt-update", _("Update chroot environment"))
131    ("chroot,c", opt::value<std::string>(&this->chroot),
132     _("Chroot environment to build in"))
133    ("purge,p", opt::value<std::string>(&this->purge_string),
134     _("Purge build mode"))
135    ("purge-deps", opt::value<std::string>(&this->purge_deps_string),
136     _("Purge dependencies mode"))
137    ("setup-hook", opt::value<std::string>(&this->setup_hook_script),
138     _("Run setup hook script in chroot prior to building"));
139
140  user.add_options()
141    ("keyid,k", opt::value<std::string>(&this->keyid),
142     _("GPG key identifier"))
143    ("maintainer,m", opt::value<std::string>(&this->maintainer),
144     _("Package maintainer"))
145    ("uploader,u", opt::value<std::string>(&this->uploader),
146     _("Package uploader"));
147
148  depends.add_options()
149    ("add-depends", opt::value<string_list>(&this->build_depends),
150     _("Add a build dependency"))
151    ("add-conflicts", opt::value<string_list>(&this->build_conflicts),
152     _("Add a build conflict"))
153    ("add-depends-indep", opt::value<string_list>(&this->build_depends_indep),
154     _("Add an architecture-independent build dependency"))
155    ("add-conflicts-indep", opt::value<string_list>(&this->build_conflicts_indep),
156     _("Add an architecture-independent build conflict"));
157
158  special.add_options()
159    ("check-depends-algorithm,C", opt::value<std::string>(&this->depends_algorithm),
160     _("Specify algorithm for dependency checking"))
161    ("gcc-snapshot,G",
162     _("Build using the current GCC development snapshot"));
163
164  hidden.add_options()
165    ("package", opt::value<sbuild::string_list>(&this->packages),
166     _("Package to build"));
167
168  positional.add("package", -1);
169}
170
171void
172options::add_option_groups ()
173{
174  // Chain up to add basic option groups.
175  schroot_base::options::add_option_groups();
176
177  visible.add(build);
178  global.add(build);
179
180  visible.add(version);
181  global.add(version);
182
183  visible.add(chrootopt);
184  global.add(chrootopt);
185
186  visible.add(user);
187  global.add(user);
188
189  visible.add(depends);
190  global.add(depends);
191
192  visible.add(special);
193  global.add(special);
194}
195
196void
197options::check_options ()
198{
199  // Chain up to check basic options.
200  schroot_base::options::check_options();
201
202  if (vm.count("build"))
203    this->action = ACTION_BUILD;
204
205  if (vm.count("nolog"))
206    this->nolog = true;
207
208  if (vm.count("batch"))
209    this->batch_mode = true;
210
211  if (vm.count("arch-all"))
212    this->build_arch_all = true;
213
214  if (vm.count("source"))
215    this->build_source = true;
216
217  if (vm.count("force-orig-source"))
218    this->force_orig_source = true;
219
220  if (vm.count("binNMU") && vm.count("make-binNMU"))
221    this->bin_nmu = true;
222  else if (vm.count("binNMU"))
223    throw opt::validation_error(_("--makebinNMU missing"));
224  else if (vm.count("make-binNMU"))
225    throw opt::validation_error(_("--binNMU missing"));
226
227  if (!deb_build_options_string.empty())
228    {
229      string_list bopts = sbuild::split_string(deb_build_options_string,
230                                               std::string(1, ' '));
231
232      for (string_list::const_iterator pos = bopts.begin();
233           pos != bopts.end();
234           ++pos)
235        {
236          if (!pos->empty())
237            deb_build_options.push_back(*pos);
238        }
239    }
240
241  if (vm.count("apt-update"))
242    this->apt_update = true;
243
244  if (vm.count("use-snapshot"))
245    this->gcc_snapshot = true;
246}
Note: See TracBrowser for help on using the repository browser.