Patchwork [RFC,v2,07/17] qapi: qmp-gen.py, use basename of path for guard/core prefix

login
register
mail settings
Submitter Michael Roth
Date April 18, 2011, 3:02 p.m.
Message ID <1303138953-1334-8-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/91772/
State New
Headers show

Comments

Michael Roth - April 18, 2011, 3:02 p.m.
To avoid errors when generating output to a seperate subdirectory, use
only the filename, minus any leading directories, when passing it into
functions to be used as a prefix for header guards, includes, etc.

Also, trim file extensions based on "." seperator instead of assuming a
single-char extension and trimming the last 2 chars

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qmp-gen.py |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Patch

diff --git a/qmp-gen.py b/qmp-gen.py
index 3667ec5..eeef58c 100644
--- a/qmp-gen.py
+++ b/qmp-gen.py
@@ -2047,10 +2047,11 @@  def generate(kind, output):
     enum_types = []
     event_types = {}
     indent_level = 0
+    prefix = output.split("/")[-1].split(".")[0]
 
-    guard = '%s_H' % c_var(output[:-2]).upper()
-    core = '%s-core.h' % output[:-2]
-    header = '%s.h' % output[:-2]
+    guard = '%s_H' % c_var(prefix).upper()
+    core = '%s-core.h' % prefix
+    header = '%s.h' % prefix
 
     if kind.endswith('body') or kind.endswith('header'):
         ret = mcgen('''
@@ -2387,7 +2388,7 @@  void qcfg_options_init(void)
     return ret
 
 def main(args):
-    if len(args) != 2:
+    if len(args) < 2:
         return 1
     if not args[0].startswith('--'):
         return 1