Creats temporary source file from COMMON_HEADERS
and src. Yields the created source string and uses the returned string as the source code, if the block is given.
Returns a string represents the type of type, or member of type if member is not nil
.
Generates a header file consisting of the various macro definitions generated by other methods such as have_func
and have_header. These are then wrapped in a custom #ifndef
based on the header
file name, which defaults to “extconf.h”.
For example:
# extconf.rb require 'mkmf' have_func('realpath') have_header('sys/utime.h') create_header create_makefile('foo')
The above script would generate the following extconf.h file:
#ifndef EXTCONF_H #define EXTCONF_H #define HAVE_REALPATH 1 #define HAVE_SYS_UTIME_H 1 #endif
Given that the create_header
method generates a file based on definitions set earlier in your extconf.rb file, you will probably want to make this one of the last methods you call in your script.
Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.
The target
name should correspond the name of the global function name defined within your C extension, minus the Init_
. For example, if your C extension is defined as Init_foo
, then your target would simply be “foo”.
If any “/” characters are present in the target name, only the last name is interpreted as the target name, and the rest are considered toplevel directory names, and the generated Makefile will be altered accordingly to follow that directory structure.
For example, if you pass “test/foo” as a target name, your extension will be installed under the “test” directory. This means that in order to load the file within a Ruby program later, that directory structure will have to be followed, e.g. require 'test/foo'
.
The srcprefix
should be used when your source files are not in the same directory as your build script. This will not only eliminate the need for you to manually copy the source files into the same directory as your build script, but it also sets the proper target_prefix
in the generated Makefile.
Setting the target_prefix
will, in turn, install the generated binary in a directory under your RbConfig::CONFIG['sitearchdir']
that mimics your local filesystem when you run make install
.
For example, given the following file tree:
ext/ extconf.rb test/ foo.c
And given the following code:
create_makefile('test/foo', 'test')
That will set the target_prefix
in the generated Makefile to “test”. That, in turn, will create the following file tree when installed via the make install
command:
/path/to/ruby/sitearchdir/test/foo.so
It is recommended that you use this approach to generate your makefiles, instead of copying files around manually, because some third party libraries may depend on the target_prefix
being set properly.
The srcprefix
argument can be used to override the default source directory, i.e. the current directory. It is included as part of the VPATH
and added to the list of INCFLAGS
.
Basically a wrapper for Process.spawn
that:
Creates a child process for each of the given cmds
by calling Process.spawn
.
Does not wait for child processes to exit.
With no block given, returns an array of the wait threads for all of the child processes.
Example:
wait_threads = Open3.pipeline_start('ls', 'grep R') # => [#<Process::Waiter:0x000055e8de9d2bb0 run>, #<Process::Waiter:0x000055e8de9d2890 run>] wait_threads.each do |wait_thread| wait_thread.join end
Output:
Rakefile README.md
With a block given, calls the block with an array of the wait processes:
Open3.pipeline_start('ls', 'grep R') do |wait_threads| wait_threads.each do |wait_thread| wait_thread.join end end
Output:
Rakefile README.md
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
If the first argument is a hash, it becomes leading argument env
in each call to Process.spawn
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in each call to Process.spawn
; see Execution Options.
Each remaining argument in cmds
is one of:
A command_line
: a string that begins with a shell reserved word or special built-in, or contains one or more metacharacters.
An exe_path
: the string path to an executable to be called.
An array containing a command_line
or an exe_path
, along with zero or more string arguments for the command.
Basically a wrapper for Process.spawn
that:
Creates a child process for each of the given cmds
by calling Process.spawn
.
Does not wait for child processes to exit.
With no block given, returns an array of the wait threads for all of the child processes.
Example:
wait_threads = Open3.pipeline_start('ls', 'grep R') # => [#<Process::Waiter:0x000055e8de9d2bb0 run>, #<Process::Waiter:0x000055e8de9d2890 run>] wait_threads.each do |wait_thread| wait_thread.join end
Output:
Rakefile README.md
With a block given, calls the block with an array of the wait processes:
Open3.pipeline_start('ls', 'grep R') do |wait_threads| wait_threads.each do |wait_thread| wait_thread.join end end
Output:
Rakefile README.md
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
If the first argument is a hash, it becomes leading argument env
in each call to Process.spawn
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in each call to Process.spawn
; see Execution Options.
Each remaining argument in cmds
is one of:
A command_line
: a string that begins with a shell reserved word or special built-in, or contains one or more metacharacters.
An exe_path
: the string path to an executable to be called.
An array containing a command_line
or an exe_path
, along with zero or more string arguments for the command.
Returns a parse result whose value is an array of tokens that closely resembles the return value of Ripper::lex
. The main difference is that the ‘:on_sp` token is not emitted.
For supported options, see Prism::parse
.
Foo, = bar ^^^
Foo::Bar ^^^^^^^^
foo in bar ^^^^^^^^^^
Visit the list of statements of a statements node. We support nil statements in the list. This would normally not be allowed by the structure of the prism parse tree, but we manually add them here so that we can mirror Ripper’s void stmt.
A list of statements.
A list of statements.
Pattern
constants get wrapped in another layer of :const.
Foo::Bar += baz ^^^^^^^^^^^^^^^
Foo::Bar += baz ^^^^^^^^^^^^^^^
@foo += bar
becomes
@foo = @foo + bar