Merge lp:~riddlepl/granite/trunk into lp:~elementary-pantheon/granite/granite

Proposed by riddle
Status: Rejected
Rejected by: kay van der Zander
Proposed branch: lp:~riddlepl/granite/trunk
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 92 lines (+33/-15)
2 files modified
demo/main.vala (+1/-0)
lib/Application.vala (+32/-15)
To merge this branch: bzr merge lp:~riddlepl/granite/trunk
Reviewer Review Type Date Requested Status
Victor Martinez (community) Needs Fixing
Rico Tzschichholz Needs Fixing
Cody Garver Pending
Review via email: mp+123253@code.launchpad.net

Description of the change

Diff contains a fix for --version bug reported for all apps separately. Now cmdline arguments are handled in granite itself, no need to do it in particular app.
If you want --help to show name for file param like here "app_name [option] *OPTION_FILE*" please initialize cmd_parameter_name in app (see demo example).
If your app require its own cmdline options you can override add_custom_cmd_options_group method and put there context.add_main_entries (app_options, program_name);.
If your app require gst, use context.add_group(Gst.init_get_option_group()); inside add_custom_cmd_options_group and do not initialize gst additionaly with init_check and similiar.

If it's merged, I will clean up apps (some of them do things which won't be required anymore)

To post a comment you must log in.
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Introducing an ABI break of this kind is not welcome. You didnt even gave an explaination for your changes.

Adding new methods is fine while preserve the old ones to give reverse-depends the time to settle. You can use the "[Deprecated ...]" vala-annoation to propagate a change is needed in the future.

Revision history for this message
Rico Tzschichholz (ricotz) :
review: Needs Fixing
Revision history for this message
riddle (riddlepl) wrote :

Thank you for the comment. I will change implementation, and it won't break the interface of granite.

Revision history for this message
riddle (riddlepl) wrote :

Code is fixed. Description added!

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

This is far from keeping abi compatibility even the api still broken.

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

I agree that we'd prefer to avoid ABI breaks for not mission-critical improvements.

Rico, could you point to any reading on avoiding API/ABI breaks? Or maybe suggest a way to avoid one here?

Otherwise I'd postpone it till granite's almost inevitable ABI break that's needed for transitioning AppMenu to Glib.Menu structure. This item alone doesn't justify an ABI break either, but if several non-critical items pile up...

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

The problem is the ordering and inserting of new symbols between others which changes the layout of the object structure.
Breaking the ABI is fine if is it going together with a soname bump, but this was forgotten a long time ago since i doubt the current granite is compatible with the 0.1 release.

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

In that case, would you mind unleashing abicheck on granite-demo from 0.1 on a system with daily Granite installed?

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Current ubuntu version versus trunk:
http://people.ubuntu.com/~ricotz/elementary/granite_compat_report.html

(Sorry for hijacking this proposal)

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Thanks!

AFAIK time picker fixup requires an API/ABI break either way, so let's bump the soname along with merging of this branch.

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

So, should Krzysztof try to rework this in a way that doesn't break the ABI, or we don't care since it's broken anyway? Is preserving the old API possible, and does it make sense? Are there any other problems with the code?

Revision history for this message
Cody Garver (codygarver) wrote :

It is allowed to expand/change as long as deprecation warnings happen for old API and the old API still works.

Revision history for this message
Victor Martinez (victored) wrote :

This is one of those unnecessary ABI/API breaks IMHO. As I told darklin on IRC, making the default option context a protected read-only property is enough. For instance:

// Add the property
private OptionContext op_context;
protected OptionContext option_context {
   get {
       if (op_context == null)
          op_context = new OptionContext (exec_name ?? "");
       return op_context;
   }
}

After that, you would remove the code in Granite.Application.run() that creates a new context.

How is this supposed to be used? For example, in Noise:

// Noise.App constructor
public App () {
    option_context.add_main_entries (app_specific_entries);
    [...]
}

When Granite.Application.run() is called, all our options would be part of the default context and parsed accordingly. Our app's options would be later applied in activate().

The print-version option is a neat addition! Please use message() instead of stdout.print() and it will be perfect.

review: Needs Fixing

Unmerged revisions

371. By riddle

Merge from parent

370. By darklin <email address hidden>

Coding style

369. By darklin <email address hidden>

Cmdline Args handling does not break ABI any more. cmd_parameter_name represent string displayed as a optional filename within --help

368. By riddle

add_custom_cmd_options_group is protected now. Cmd args handling done explicitly by granite

367. By riddle

Generic cmd params handling

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'demo/main.vala'
2--- demo/main.vala 2012-08-16 00:38:28 +0000
3+++ demo/main.vala 2012-09-07 18:03:18 +0000
4@@ -34,6 +34,7 @@
5 main_url = "https://launchpad.net/granite";
6 bug_url = "https://bugs.launchpad.net/granite";
7 help_url = "https://answers.launchpad.net/granite";
8+ cmd_parameter_name = "Demo";
9 translate_url = "https://translations.launchpad.net/granite";
10 about_authors = {"Kekun",
11 null
12
13=== modified file 'lib/Application.vala'
14--- lib/Application.vala 2012-06-17 18:44:59 +0000
15+++ lib/Application.vala 2012-09-07 18:03:18 +0000
16@@ -39,6 +39,7 @@
17
18 public string program_name;
19 public string exec_name;
20+ public string cmd_parameter_name;
21
22 public string app_copyright;
23 public string app_years;
24@@ -77,37 +78,53 @@
25
26 // Deprecated
27 Granite.app = this;
28-
29 }
30
31 [CCode (cheader_filename = "sys/prctl.h", cname = "prctl")]
32 protected extern static int prctl (int option, string arg2, ulong arg3, ulong arg4, ulong arg5);
33-
34- public new int run (string[] args) {
35-
36- // parse commandline options
37- var context = new OptionContext ("");
38-
39- context.add_main_entries (options, null);
40- context.add_group (Gtk.get_option_group (false));
41-
42+
43+ protected virtual void add_custom_cmd_options_group(ref OptionContext context) {
44+ }
45+
46+ protected bool handle_common_cmd_options (ref OptionContext context, string[] args) {
47+
48+ add_custom_cmd_options_group (ref context);
49+ context.add_main_entries (options, program_name);
50+ context.add_group (Gtk.get_option_group (true));
51+
52+
53 try {
54 context.parse (ref args);
55- } catch { }
56-
57- set_options ();
58-
59+ } catch (Error e) {
60+ warning (e.message);
61+ }
62+ if (PRINT_VERSION) {
63+ stdout.printf("%s %s\n", program_name, build_version);
64+ stdout.printf("Copyright %s %s Developers.\n", app_years, program_name);
65+ return false;
66+ }
67+ set_log_options ();
68+ return true;
69+ }
70+
71+ public new int run (string[] args) {
72+ OptionContext context = new OptionContext(cmd_parameter_name);
73+
74+ if(!handle_common_cmd_options (ref context, args))
75+ return 0;
76 return base.run (args);
77 }
78
79 protected static bool DEBUG = false;
80+ protected static bool PRINT_VERSION = false;
81
82 protected const OptionEntry[] options = {
83 { "debug", 'd', 0, OptionArg.NONE, out DEBUG, "Enable debug logging", null },
84+ { "version", 'v', 0, OptionArg.NONE, out PRINT_VERSION, "Print version info and exit", null },
85 { null }
86 };
87
88- protected virtual void set_options () {
89+ protected virtual void set_log_options () {
90
91 if (DEBUG)
92 Logger.DisplayLevel = LogLevel.DEBUG;

Subscribers

People subscribed via source and target branches