Skip to content

Commit

Permalink
Merge pull request #291 from yast/backport_sp6
Browse files Browse the repository at this point in the history
Backport sp6
  • Loading branch information
jreidinger authored Sep 14, 2023
2 parents 35a3a2e + a69f53a commit 59de3b7
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 55 deletions.
16 changes: 14 additions & 2 deletions package/yast2-ruby-bindings.changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
-------------------------------------------------------------------
Fri Sep 01 19:57:03 UTC 2023 - Josef Reidinger <[email protected]>
Mon Apr 3 10:46:37 UTC 2023 - Josef Reidinger <[email protected]>

- Branch package for SP6 (bsc#1208913)
- Improve YaST memory consumption related to import+publish (bsc#1210051)
- 4.6.2

-------------------------------------------------------------------
Thu Mar 9 10:36:23 UTC 2023 - Martin Vidner <[email protected]>

- Use ruby-devel versioned to match the gems (bsc#1209098)
- 4.6.1

-------------------------------------------------------------------
Fri Mar 03 14:44:07 UTC 2023 - Ladislav Slezák <[email protected]>

- Bump version to 4.6.0 (bsc#1208913)

-------------------------------------------------------------------
Mon Oct 24 12:51:30 UTC 2022 - Ladislav Slezák <[email protected]>
Expand Down
5 changes: 3 additions & 2 deletions package/yast2-ruby-bindings.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-ruby-bindings
Version: 4.6.0
Version: 4.6.2
Release: 0
URL: https://github.com/yast/yast-ruby-bindings
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -31,7 +31,8 @@ BuildRequires: yast2-devtools >= 3.1.10
BuildRequires: rubygem(%{rb_default_ruby_abi}:fast_gettext) < 3.0
BuildRequires: rubygem(%{rb_default_ruby_abi}:rspec)
Requires: rubygem(%{rb_default_ruby_abi}:fast_gettext) < 3.0
BuildRequires: ruby-devel
# this is ruby-devel pinned to the default version, matching the gems
BuildRequires: %{rubydevel}
Requires: yast2-core >= 3.2.2
BuildRequires: yast2-core-devel >= 3.2.2
# MenuBar-shortcuts-test.rb
Expand Down
18 changes: 18 additions & 0 deletions profiling/yast_import.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "memory_profiler"

usage = <<CMD
cd build # cmake ..; make
# use the built version
ruby -r ../tests/test_helper.rb ../profiling/yast_import.rb # | head -n2
# use the system version
ruby ../profiling/yast_import.rb # | head -n2
CMD

MemoryProfiler.report {
require "yast"

Yast.import "Pkg"
Yast.import "Bootloader"
Yast.import "UI"
Yast.import "Lan"
}.pretty_print
32 changes: 17 additions & 15 deletions src/binary/YRubyNamespace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ as published by the Free Software Foundation; either version
#include "YRuby.h"
#include "Y2RubyUtils.h"


// HELPER method to inspect ruby values from C++. Useful for debugging
/*
// usage: log_inspect("surely not nil, foobar", foobar);
static void log_inspect(const char * message, VALUE v)
{
VALUE inspect = rb_funcall(v, rb_intern("inspect"), 0);
y2internal("%s: %s", message, StringValueCStr(inspect));
}
*/

/**
* Exception raised when type signature in ruby class is invalid
*/
Expand Down Expand Up @@ -274,15 +285,12 @@ VALUE YRubyNamespace::getRubyModule()
int YRubyNamespace::addMethods(VALUE module)
{
VALUE methods = rb_funcall(module, rb_intern("published_functions"),0);
methods = rb_funcall(methods,rb_intern("values"),0);
int j = 0;
for (int i = 0; i < RARRAY_LEN(methods); ++i)
{
VALUE method = rb_ary_entry(methods,i);
if (getenv("Y2ALLGLOBAL") == NULL && RTEST(rb_funcall(method, rb_intern("private?"), 0)))
continue;
VALUE method_name = rb_funcall(method, rb_intern("function"), 0);
VALUE type = rb_funcall(method,rb_intern("type"),0);
VALUE method = rb_ary_entry(methods, i);
VALUE method_name = rb_ary_entry(method, 0);
VALUE type = rb_ary_entry(method, 1);
string signature = StringValueCStr(type);

addMethod(rb_id2name(SYM2ID(method_name)), signature, j++);
Expand All @@ -293,18 +301,12 @@ int YRubyNamespace::addMethods(VALUE module)
int YRubyNamespace::addVariables(VALUE module, int offset)
{
VALUE variables = rb_funcall(module, rb_intern("published_variables"),0);
variables = rb_funcall(variables,rb_intern("values"),0);
int j=0;
for (int i = 0; i < RARRAY_LEN(variables); ++i)
{
VALUE variable = rb_ary_entry(variables,i);
VALUE variable_name = rb_funcall(variable, rb_intern("variable"), 0);
if (getenv("Y2ALLGLOBAL") == NULL && RTEST(rb_funcall(variable, rb_intern("private?"), 0)))
{
y2debug("variable: '%s' is private and not needed", rb_id2name(SYM2ID(variable_name)));
continue;
}
VALUE type = rb_funcall(variable,rb_intern("type"),0);
VALUE variable = rb_ary_entry(variables, i);
VALUE variable_name = rb_ary_entry(variable, 0);
VALUE type = rb_ary_entry(variable, 1);
string signature = StringValueCStr(type);
constTypePtr sym_tp = Type::fromSignature(signature);

Expand Down
43 changes: 21 additions & 22 deletions src/ruby/yast/exportable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@ module Yast
# Provides ability to export functions and variables to Yast component system.
# The most important method is {Yast::Exportable#publish}
module Exportable
# Holder for exported data
class ExportData < OpenStruct
# Is exported data only for private purpose.
# It is useful only to test private methods from old Yast testsuite.
def private?
table = marshal_dump
!!table[:private]
end
end

# list of published functions
# @api private
# @return [Array<Array(Symbol,String)>] list of published functions
# @example
# [
# [:doit, "void()"],
# [:is_odd, "boolean(integer)"]
# ]
def published_functions
@__published_functions ||= {}
@__published_functions ||= []
end

# list of published variables
# @api private
# @return [Array<Array(Symbol,String)>] list of published variables
# @example
# [
# [:answer, "integer"],
# [:having_fun, "boolean"]
# ]
def published_variables
@__published_variables ||= {}
@__published_variables ||= []
end

# Publishes function or variable to component system
Expand All @@ -37,16 +39,13 @@ def publish(options)
raise "Missing signature" unless options[:type]
# convert type to full specification
type = options[:type].delete " \t"
type = type.gsub(/map([^<]|$)/, 'map<any,any>\\1')
type = type.gsub(/list([^<]|$)/, 'list<any>\\1')
options[:type] = type
type.gsub!(/map([^<]|$)/, 'map<any,any>\\1')
type.gsub!(/list([^<]|$)/, 'list<any>\\1')
if options[:function]
published_functions[options[:function]] = ExportData.new options
published_functions.push([options[:function], type])
elsif options[:variable]
published_variables[options[:variable]] = ExportData.new options
if !options[:private] || ENV["Y2ALLGLOBAL"]
attr_accessor :"#{options[:variable]}"
end
published_variables.push([options[:variable], type])
attr_accessor options[:variable]
else
raise "Missing publish kind"
end
Expand Down
7 changes: 4 additions & 3 deletions src/ruby/yast/path.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Yast
# Represents paths like it is in ycp. It is path elements separated by dot.
# Elements can be simple or complex. Simple can contain only ascii characters [a-zA-Z0-9].
Expand Down Expand Up @@ -71,7 +72,7 @@ def <=>(other)
def load_components(value)
state = :initial
skip_next = false
buffer = ""
buffer = "".dup
value.each_char do |c|
case state
when :initial
Expand All @@ -91,7 +92,7 @@ def load_components(value)
raise "Invalid path '#{value}'" if invalid_buffer?(buffer)

@components << modify_buffer(buffer)
buffer = ""
buffer = "".dup
next
end
buffer << c
Expand All @@ -107,7 +108,7 @@ def load_components(value)
state = :initial
buffer << c
@components << buffer
buffer = ""
buffer = "".dup
next
when '\\'
skip_next = true
Expand Down
4 changes: 2 additions & 2 deletions src/ruby/yast/yast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ def self.import(mname)
# do not reimport if already imported and contain some methods
# ( in case namespace contain some methods )
if base.constants.include?(modules.last.to_sym) &&
!(base.const_get(modules.last).methods - Object.methods).empty?
!base.const_get(modules.last).public_methods(false).empty?
return
end

import_pure(mname)

# do not create wrapper if module is in ruby and define itself object
if base.constants.include?(modules.last.to_sym) &&
!(base.const_get(modules.last).methods - Object.methods).empty?
!base.const_get(modules.last).public_methods(false).empty?
return
end

Expand Down
16 changes: 7 additions & 9 deletions tests/exportable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,20 @@ def test(_a, _b)

describe "ExportableTest" do
it "tests publish methods" do
expect(MyTest.class.published_functions.keys).to eq([:test])
expect(MyTest.class.published_functions.values.first.function).to eq(:test)
expect(MyTest.class.published_functions[:test].type).to eq("string(integer,term)")
expect(MyTest.class.published_functions).to eq([
[:test, "string(integer,term)"]
])
end

it "tests publish variables" do
expect(MyTest.class.published_variables[:variable_a].type).to eq("map<any,any>")
expect(MyTest.class.published_variables).to eq([
[:complex, "map<string,map<list<any>,map<any,any>>>"],
[:variable_a, "map<any,any>"]
])
end

it "tests variable definition" do
MyTest.variable_a = ({ a: 15 })
expect(MyTest.variable_a).to eq(a: 15)
end

it "tests type full specification" do
expect(MyTest.class.published_variables[:complex].type)
.to eq("map<string,map<list<any>,map<any,any>>>")
end
end
2 changes: 2 additions & 0 deletions tests/test_module/modules/InvalidTypeModule.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Yast
class InvalidTypeModuleClass < Module
include Yast::Logger

def a
puts "Fail"
end
Expand Down

0 comments on commit 59de3b7

Please sign in to comment.