rpm  5.4.15
spec-rb.c
Go to the documentation of this file.
1 
9 #include "system.h"
10 
11 #include "rpm-rb.h"
12 #include "spec-rb.h"
13 #include "rpmmc-rb.h"
14 #include "package-rb.h"
15 
16 #ifndef _GNU_SOURCE
17 #define _GNU_SOURCE
18 #endif
19 #include <stdio.h>
20 
21 #define _RPMTS_INTERNAL
22 #define _RPMFI_INTERNAL
23 #include <rpmtag.h>
24 #include <rpmtypes.h>
25 #include <rpmio.h>
26 #include <rpmbuild.h>
27 #include <rpmspec.h>
28 #include <rpmmacro.h>
29 
30 
31 VALUE specClass;
32 
33 
37 static void
39 {
40  freeSpec(spec);
41 }
42 
43 
47 static Spec
48 _spec_get_spec(VALUE self)
49 {
50  Spec spec;
51  Data_Get_Struct(self, struct Spec_s, spec);
52  return spec;
53 }
54 
55 
59 static rpmts
60 _spec_get_ts(VALUE self)
61 {
62  rpmts ts;
63  Data_Get_Struct(rb_iv_get(self, "ts"), struct rpmts_s, ts);
64  return ts;
65 }
66 
67 
72 static VALUE
73 _spec_get_sources(VALUE self, int flags)
74 {
75  Spec spec = _spec_get_spec(self);
76 
77  VALUE ary = rb_ary_new();
78 
79  SpecSource src;
80  for(src = spec->sources; src != NULL; src = src->next)
81  if(src->flags & flags)
82  rb_ary_push(ary, rb_str_new2(src->fullSource));
83 
84  return ary;
85 }
86 
87 
96 static
97 VALUE spec_get_sources(VALUE self)
98 {
99  return _spec_get_sources(self, RPMFILE_SOURCE);
100 }
101 
102 
111 static VALUE
112 spec_get_patches(VALUE self)
113 {
114  return _spec_get_sources(self, RPMFILE_PATCH);
115 }
116 
117 
130 static VALUE
131 spec_get_packages(VALUE self)
132 {
133  VALUE pkg_ary = rb_ary_new();
134  Spec spec = _spec_get_spec(self);
135 
136  Package pkg;
137  for(pkg = spec->packages; pkg != NULL; pkg = pkg->next)
138  rb_ary_push(pkg_ary, Data_Wrap_Struct(packageClass, 0, -1, pkg));
139 
140  return pkg_ary;
141 }
142 
143 
152 static VALUE
153 spec_get_macros(VALUE self)
154 {
155  Spec spec = _spec_get_spec(self);
156  return rpmmc_wrap(spec->macros);
157 }
158 
159 
175 static VALUE
176 spec_build(VALUE argc, VALUE *argv, VALUE self)
177 {
178  VALUE test_v = T_FALSE, flags_v;
179  rb_scan_args(argc, argv, "11", &flags_v, &test_v);
180 
181  int test = 0;
182  switch(TYPE(test_v)) {
183  case T_TRUE:
184  test = 1;
185  break;
186  case T_NIL:
187  case T_FALSE:
188  test = 0;
189  break;
190  default:
191  rb_raise(rb_eTypeError,
192  "Value for test must be either true or false");
193  break;
194  }
195 
196  Check_Type(flags_v, T_FIXNUM);
197  int flags = FIX2INT(flags_v);
198 
199  rpmts ts = _spec_get_ts(self);
200  Spec spec = _spec_get_spec(self);
201 
202  rpmRC error = buildSpec(ts, spec, flags, test);
203  if(error) rpm_rb_raise(error, "Building spec file failed");
204 
205  return self;
206 }
207 
208 
209 VALUE
211 {
212  return Data_Wrap_Struct(specClass, 0, &_spec_free, spec);
213 }
214 
215 
216 void
218 {
219  specClass = rb_define_class_under(rpmModule, "Spec", rb_cObject);
220 
221  rb_define_method(specClass, "sources", &spec_get_sources, 0);
222  rb_define_method(specClass, "patches", &spec_get_patches, 0);
223  rb_define_method(specClass, "packages", &spec_get_packages, 0);
224  rb_define_method(specClass, "macros", &spec_get_macros, 0);
225  rb_define_method(specClass, "build", &spec_build, -1);
226 }
static void _spec_free(Spec spec)
C destructor for the Spec class.
Definition: spec-rb.c:38
const char bson_timestamp_t * ts
Definition: bson.h:1004
Package next
Definition: rpmspec.h:255
static VALUE spec_get_sources(VALUE self)
Returns an array of all sources defined in the spec file.
Definition: spec-rb.c:97
struct Source * sources
Definition: rpmspec.h:162
VALUE rpmmc_wrap(rpmmc mc)
Wraps an already existing MacroContext struct in a Ruby class.
Definition: rpmmc-rb.c:325
struct Source * next
Definition: rpmspec.h:52
const char * fullSource
Definition: rpmspec.h:46
Definition: rpmspec.h:44
VALUE spec_wrap(Spec spec)
Wraps an already existing Spec_s structure in a Ruby class.
Definition: spec-rb.c:210
static VALUE spec_build(VALUE argc, VALUE *argv, VALUE self)
Builds a part of the spec file.
Definition: spec-rb.c:176
MacroContext macros
Definition: rpmspec.h:177
static rpmts _spec_get_ts(VALUE self)
Returns the hiddenly associated transaction set.
Definition: spec-rb.c:60
The structure used to store values parsed from a spec file.
Definition: rpmspec.h:113
void rpm_rb_raise(rpmRC error, char *message)
Raises a Ruby exception (RPM::Error).
Definition: rpm-rb.c:53
Spec freeSpec(Spec spec)
Destroy a spec file control structure.
static Spec _spec_get_spec(VALUE self)
Returns the wrapped Spec structure.
Definition: spec-rb.c:48
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
static VALUE spec_get_macros(VALUE self)
Returns the macro context of the spec file.
Definition: spec-rb.c:153
RPM Ruby bindings "RPM" module.
enum rpmRC_e rpmRC
RPM return codes.
Package packages
Definition: rpmspec.h:204
This is the only module users of librpmbuild should need to include.
Ruby access to RPM's Package struct.
VALUE specClass
The Ruby class representation of the Spec_s structure and methods.
Definition: spec-rb.c:31
struct rpmts_s * rpmts
The RPM Transaction Set.
Definition: rpmtypes.h:14
void Init_spec(void)
Initializes the Ruby class.
Definition: spec-rb.c:217
VALUE rpmModule
The "RPM" Ruby module.
Definition: rpm-rb.c:35
Ruby bindings for spec file access.
static VALUE spec_get_patches(VALUE self)
Returns an array of all patches defined in the spec file.
Definition: spec-rb.c:112
static VALUE spec_get_packages(VALUE self)
Returns all packages associated with the spec file.
Definition: spec-rb.c:131
VALUE packageClass
RPM::Package class that represents a package during build.
Definition: package-rb.c:22
The structure used to store values for a package.
Definition: rpmspec.h:214
The Spec and Package data structures used during build.
Ruby bindings to RPM's macro context facility.
rpmRC buildSpec(rpmts ts, Spec spec, int what, int test)
Build stages state machine driver.
Definition: build.c:338
int flags
Definition: rpmspec.h:49
static VALUE _spec_get_sources(VALUE self, int flags)
A helper routine that returns a Ruby array containing all sources that match a specific set of OR'ed ...
Definition: spec-rb.c:73