From 5f8399ff65650ec8fb9a01718380149016e72acb Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 24 Mar 2015 11:05:47 +0100 Subject: [PATCH 01/13] add ui initialization if none is started for testing purpose --- src/binary/Yast.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/binary/Yast.cc b/src/binary/Yast.cc index 426378d7..1dfe24da 100644 --- a/src/binary/Yast.cc +++ b/src/binary/Yast.cc @@ -384,6 +384,30 @@ static VALUE code_call( int argc, VALUE *argv, VALUE self ) rb_raise(rb_eRuntimeError, "YCode is empty"); } +static void init_ui() +{ + const char *ui_name = "UI"; + + Y2Component *c = YUIComponent::uiComponent(); + if (c == 0) + { + y2debug ("UI component not created yet, creating %s", ui_name); + + c = Y2ComponentBroker::createServer(ui_name); // just dummy ui if none is defined + if (c == 0) + { + y2error("can't create UI component"); + return; + } + + c->setServerOptions(0, NULL); + } + else + { + y2debug("UI component already present: %s", c->name ().c_str ()); + } +} + } //extern C extern "C" @@ -398,6 +422,7 @@ extern "C" Init_yastx() { YCPPathSearch::initialize(); + init_ui(); /* * module YCP From 62fbe2de41950f3db27f9636d23389c5e3b4eb17 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 24 Mar 2015 11:25:24 +0100 Subject: [PATCH 02/13] link also ui plugin --- src/binary/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/binary/CMakeLists.txt b/src/binary/CMakeLists.txt index 5b2c3ae6..02d18f23 100644 --- a/src/binary/CMakeLists.txt +++ b/src/binary/CMakeLists.txt @@ -78,6 +78,7 @@ SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'${YAST target_link_libraries( yastx ${YAST_LIBRARY} ) target_link_libraries( yastx ${YAST_YCP_LIBRARY} ) +target_link_libraries( yastx ${YAST_PLUGIN_UI_LIBRARY} ) # # The WFM and SCR component can only be initialized statically # (e.g. through Y2CCWFM), thus we must link against the plugin libs From fce61ea15eea1782f6193735989ba50a243511f6 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 24 Mar 2015 11:36:25 +0100 Subject: [PATCH 03/13] fix scr initialization --- src/CMakeLists.txt | 15 --------------- src/binary/CMakeLists.txt | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd005b5a..4a753f5c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,17 +1,2 @@ add_subdirectory(ruby) add_subdirectory(binary) - -# rdoc -set(rdoc_dir "${CMAKE_CURRENT_BINARY_DIR}/html") -ADD_CUSTOM_COMMAND ( - OUTPUT ${rdoc_dir} - COMMAND ${CMAKE_COMMAND} -E echo_append "Creating rdoc documentation ..." - COMMAND rm -rf ${rdoc_dir} - COMMAND rdoc -o ${rdoc_dir} ruby binary/Yast.cc - COMMAND ${CMAKE_COMMAND} -E echo "Done." - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/ - DEPENDS ${CMAKE_SOURCE_DIR}/src/binary/Yast.cc ${CMAKE_SOURCE_DIR}/src/ruby/*.rb -) -add_custom_target(rdoc ALL DEPENDS "${rdoc_dir}") -add_dependencies(rdoc yastx) -add_dependencies(rdoc scrx) diff --git a/src/binary/CMakeLists.txt b/src/binary/CMakeLists.txt index 02d18f23..8b0c4b04 100644 --- a/src/binary/CMakeLists.txt +++ b/src/binary/CMakeLists.txt @@ -90,6 +90,7 @@ target_link_libraries( builtinx ${YAST_LIBRARY} ) target_link_libraries( builtinx ${YAST_YCP_LIBRARY} ) target_link_libraries( builtinx ${YAST_PLUGIN_SCR_LIBRARY} ) target_link_libraries( builtinx ${YAST_PLUGIN_WFM_LIBRARY} ) +target_link_libraries( builtinx ${YAST_PLUGIN_UI_LIBRARY} ) target_link_libraries( builtinx crypt ) find_library( OWCRYPT_LIBRARY owcrypt ) if ( OWCRYPT_LIBRARY ) From 11eeffb00acbe0214a1c61c2633e62288d1c4913 Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Fri, 10 Apr 2015 14:16:48 +0200 Subject: [PATCH 04/13] link yastx with more libraries especially py2scr which contains the component creator for SCR --- src/binary/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/binary/CMakeLists.txt b/src/binary/CMakeLists.txt index 8b0c4b04..445ddec4 100644 --- a/src/binary/CMakeLists.txt +++ b/src/binary/CMakeLists.txt @@ -78,6 +78,8 @@ SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'${YAST target_link_libraries( yastx ${YAST_LIBRARY} ) target_link_libraries( yastx ${YAST_YCP_LIBRARY} ) +target_link_libraries( yastx ${YAST_PLUGIN_SCR_LIBRARY} ) +target_link_libraries( yastx ${YAST_PLUGIN_WFM_LIBRARY} ) target_link_libraries( yastx ${YAST_PLUGIN_UI_LIBRARY} ) # # The WFM and SCR component can only be initialized statically From 347506fa098e9f847d95cf28754c2ff5dff62751 Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Fri, 10 Apr 2015 15:26:27 +0200 Subject: [PATCH 05/13] linker: disable --as-needed Otherwise yastx.so is missing libraries like libpy2scr. This is the same workaround as in yast2-core.rpm. We should really merge the libraries that are mutually dependent. --- package/yast2-ruby-bindings.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package/yast2-ruby-bindings.spec b/package/yast2-ruby-bindings.spec index 2ad9393f..eaa13dfc 100644 --- a/package/yast2-ruby-bindings.spec +++ b/package/yast2-ruby-bindings.spec @@ -54,6 +54,8 @@ and also Ruby scripts can use YaST agents, APIs and modules. %prep %setup -n yast2-ruby-bindings-%{version} %build +export SUSE_ASNEEDED=0 # disable --as-needed until this package is fixed + mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=%{prefix} \ From 04b23218131051023ac68edf2d45cee3213af4bb Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Fri, 24 Apr 2015 17:04:37 +0200 Subject: [PATCH 06/13] always use the ncurses ui FIXME, add an API for specifying the frontend --- src/binary/Yast.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/binary/Yast.cc b/src/binary/Yast.cc index 1dfe24da..fcfb41fa 100644 --- a/src/binary/Yast.cc +++ b/src/binary/Yast.cc @@ -386,7 +386,7 @@ static VALUE code_call( int argc, VALUE *argv, VALUE self ) static void init_ui() { - const char *ui_name = "UI"; + const char *ui_name = "ncurses"; Y2Component *c = YUIComponent::uiComponent(); if (c == 0) From 5b5ca4897613193bc7219baaa6c1c97ba0ef2dbe Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Fri, 15 May 2015 14:03:41 +0200 Subject: [PATCH 07/13] API for choosing the UI frontend --- src/binary/Yast.cc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/binary/Yast.cc b/src/binary/Yast.cc index fcfb41fa..8807a406 100644 --- a/src/binary/Yast.cc +++ b/src/binary/Yast.cc @@ -384,9 +384,34 @@ static VALUE code_call( int argc, VALUE *argv, VALUE self ) rb_raise(rb_eRuntimeError, "YCode is empty"); } +static VALUE ui_get_component() +{ + string s; + YUIComponent *c = YUIComponent::uiComponent(); + if (c) + { + s = c->requestedUIName(); + } + return yrb_utf8_str_new(s); +} + +static VALUE ui_set_component(VALUE self, VALUE name) +{ + YUIComponent *c = YUIComponent::uiComponent(); + if (c) + { + YUIComponent::setUseDummyUI(false); + + string s = StringValuePtr(name); + c->setRequestedUIName(s); + } + + return Qnil; +} + static void init_ui() { - const char *ui_name = "ncurses"; + const char *ui_name = "UI"; Y2Component *c = YUIComponent::uiComponent(); if (c == 0) @@ -441,6 +466,10 @@ extern "C" rb_define_method( rb_mYast, "y2_logger", RUBY_METHOD_FUNC(yast_y2_logger), -1); rb_define_singleton_method( rb_mYast, "y2_logger", RUBY_METHOD_FUNC(yast_y2_logger), -1); + // UI initialization + rb_define_singleton_method( rb_mYast, "ui_get_component", RUBY_METHOD_FUNC(ui_get_component), 0); + rb_define_singleton_method( rb_mYast, "ui_set_component", RUBY_METHOD_FUNC(ui_set_component), 1); + // Y2 references rb_cYReference = rb_define_class_under(rb_mYast, "YReference", rb_cObject); rb_define_method(rb_cYReference, "call", RUBY_METHOD_FUNC(ref_call), -1); From 744f9cd39332eb43bb604a9a4b4edd5f323de4cf Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Fri, 15 May 2015 17:58:50 +0200 Subject: [PATCH 08/13] ui_finalizer to call shutdownThreads on the derived object --- src/binary/Yast.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/binary/Yast.cc b/src/binary/Yast.cc index 8807a406..af742c0a 100644 --- a/src/binary/Yast.cc +++ b/src/binary/Yast.cc @@ -32,6 +32,7 @@ as published by the Free Software Foundation; either version #include #include #include +#include #include #include #include @@ -433,6 +434,17 @@ static void init_ui() } } +static VALUE ui_finalizer() +{ + YUIComponent *c = YUIComponent::uiComponent(); + if (c) + { + // Shut down the component. + c->result(YCPVoid()); + } + return Qnil; +} + } //extern C extern "C" @@ -469,6 +481,7 @@ extern "C" // UI initialization rb_define_singleton_method( rb_mYast, "ui_get_component", RUBY_METHOD_FUNC(ui_get_component), 0); rb_define_singleton_method( rb_mYast, "ui_set_component", RUBY_METHOD_FUNC(ui_set_component), 1); + rb_define_singleton_method( rb_mYast, "ui_finalizer", RUBY_METHOD_FUNC(ui_finalizer), 0); // Y2 references rb_cYReference = rb_define_class_under(rb_mYast, "YReference", rb_cObject); From e7ed9ff3260dad369793e805a90313b779e0b1bf Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 18 May 2015 09:56:51 +0200 Subject: [PATCH 09/13] Define a finalizer for ui. --- src/ruby/yast.rb | 1 + src/ruby/yast/ui.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 src/ruby/yast/ui.rb diff --git a/src/ruby/yast.rb b/src/ruby/yast.rb index 46597831..09844f1c 100644 --- a/src/ruby/yast.rb +++ b/src/ruby/yast.rb @@ -41,6 +41,7 @@ require "yast/path" require "yast/scr" require "yast/term" +require "yast/ui" require "yast/ui_shortcuts" require "yast/wfm" diff --git a/src/ruby/yast/ui.rb b/src/ruby/yast/ui.rb new file mode 100644 index 00000000..8bd44b3b --- /dev/null +++ b/src/ruby/yast/ui.rb @@ -0,0 +1,5 @@ +module Yast + # This is a counterpart to init_ui in the C code. + # It really belongs near it but I don't know how to code a proc in C. + ObjectSpace.define_finalizer(Yast, proc { Yast.ui_finalizer } ) +end From 3b9e250c95d1d8cee06e35735e64470f2c0b4a4d Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 18 May 2015 10:03:25 +0200 Subject: [PATCH 10/13] Disable as-needed portably so that Travis/Ubuntu works too. --- package/yast2-ruby-bindings.spec | 2 -- src/binary/CMakeLists.txt | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package/yast2-ruby-bindings.spec b/package/yast2-ruby-bindings.spec index 68cfac40..b10d408f 100644 --- a/package/yast2-ruby-bindings.spec +++ b/package/yast2-ruby-bindings.spec @@ -54,8 +54,6 @@ and also Ruby scripts can use YaST agents, APIs and modules. %prep %setup -n yast2-ruby-bindings-%{version} %build -export SUSE_ASNEEDED=0 # disable --as-needed until this package is fixed - mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=%{prefix} \ diff --git a/src/binary/CMakeLists.txt b/src/binary/CMakeLists.txt index 445ddec4..d9b2efee 100644 --- a/src/binary/CMakeLists.txt +++ b/src/binary/CMakeLists.txt @@ -76,6 +76,12 @@ set_target_properties( builtinx PROPERTIES INSTALL_RPATH "${YAST_PLUGIN_DIR}") # SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'${YAST_PLUGIN_DIR}'" ) +# Correct initialization depends on libraries being linked and providing +# global variables with certain names. (Y2PluginComponent: "g_y2cc*") +# Tell the linker not to optimize them away. +set_target_properties( yastx PROPERTIES LINK_FLAGS "-Wl,--no-as-needed") +set_target_properties( builtinx PROPERTIES LINK_FLAGS "-Wl,--no-as-needed") + target_link_libraries( yastx ${YAST_LIBRARY} ) target_link_libraries( yastx ${YAST_YCP_LIBRARY} ) target_link_libraries( yastx ${YAST_PLUGIN_SCR_LIBRARY} ) From 505cca07ea1133c8d027362888f30125d9932a91 Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 18 May 2015 13:48:58 +0200 Subject: [PATCH 11/13] Better names and documentation for Yast.ui_component --- src/binary/Yast.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/binary/Yast.cc b/src/binary/Yast.cc index af742c0a..221d4322 100644 --- a/src/binary/Yast.cc +++ b/src/binary/Yast.cc @@ -100,7 +100,7 @@ import_namespace( const char *name) * Tries to import a YCP namespace * * call-seq: - * YCP::import("name") + * Yast.import("name") * */ @@ -385,6 +385,12 @@ static VALUE code_call( int argc, VALUE *argv, VALUE self ) rb_raise(rb_eRuntimeError, "YCode is empty"); } +/* + * Document-method: ui_component + * + * YaST component serving the UI: "gtk", "ncurses", "qt", + * or the dummy one "UI" + */ static VALUE ui_get_component() { string s; @@ -396,6 +402,15 @@ static VALUE ui_get_component() return yrb_utf8_str_new(s); } +/* + * Document-method: ui_component= + * + * When Ruby is embedded in YaST (y2base is the main program), the UI + * is determined by the time Ruby code gets run. If ruby is the main program, + * we need to load the UI frontend if we need one. + * + * Assign "ncurses" or "qt" before UI calls. + */ static VALUE ui_set_component(VALUE self, VALUE name) { YUIComponent *c = YUIComponent::uiComponent(); @@ -479,8 +494,8 @@ extern "C" rb_define_singleton_method( rb_mYast, "y2_logger", RUBY_METHOD_FUNC(yast_y2_logger), -1); // UI initialization - rb_define_singleton_method( rb_mYast, "ui_get_component", RUBY_METHOD_FUNC(ui_get_component), 0); - rb_define_singleton_method( rb_mYast, "ui_set_component", RUBY_METHOD_FUNC(ui_set_component), 1); + rb_define_singleton_method( rb_mYast, "ui_component", RUBY_METHOD_FUNC(ui_get_component), 0); + rb_define_singleton_method( rb_mYast, "ui_component=", RUBY_METHOD_FUNC(ui_set_component), 1); rb_define_singleton_method( rb_mYast, "ui_finalizer", RUBY_METHOD_FUNC(ui_finalizer), 0); // Y2 references From 16601f75e9bee26b2ffee16c47b366a15833c0a3 Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 18 May 2015 15:12:17 +0200 Subject: [PATCH 12/13] Example for Yast.ui_component --- src/binary/Yast.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/binary/Yast.cc b/src/binary/Yast.cc index 221d4322..851b37ad 100644 --- a/src/binary/Yast.cc +++ b/src/binary/Yast.cc @@ -410,6 +410,22 @@ static VALUE ui_get_component() * we need to load the UI frontend if we need one. * * Assign "ncurses" or "qt" before UI calls. + * + * #! /usr/bin/env ruby + * require "yast" + * include Yast + * include Yast::UIShortcuts + * + * if Yast.ui_component == "" + * Yast.ui_component = ARGV[0] || "ncurses" + * end + * + * Builtins.y2milestone("UI component: %1", Yast.ui_component) + * Yast.import "UI" + * + * UI.OpenDialog(PushButton("This is a button")) + * UI.UserInput + * UI.CloseDialog */ static VALUE ui_set_component(VALUE self, VALUE name) { From a99ffa96f9ee31bf51bcda9cbedb4a8d066daa6c Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 18 May 2015 10:35:08 +0200 Subject: [PATCH 13/13] version + changelog --- package/yast2-ruby-bindings.changes | 7 +++++++ package/yast2-ruby-bindings.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/yast2-ruby-bindings.changes b/package/yast2-ruby-bindings.changes index 3c675d26..d8f80814 100644 --- a/package/yast2-ruby-bindings.changes +++ b/package/yast2-ruby-bindings.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Mon May 18 08:34:37 UTC 2015 - mvidner@suse.com + +- Initialize the YaST UI so that it can be called + when the main program is not y2base (bsc#922023). +- 3.1.32 + ------------------------------------------------------------------- Wed Apr 1 15:38:04 UTC 2015 - ancor@suse.com diff --git a/package/yast2-ruby-bindings.spec b/package/yast2-ruby-bindings.spec index b10d408f..f36273c9 100644 --- a/package/yast2-ruby-bindings.spec +++ b/package/yast2-ruby-bindings.spec @@ -17,7 +17,7 @@ Name: yast2-ruby-bindings -Version: 3.1.31 +Version: 3.1.32 Url: https://github.com/yast/yast-ruby-bindings Release: 0 BuildRoot: %{_tmppath}/%{name}-%{version}-build