diff options
author | guybe7 <guy.benoish@redislabs.com> | 2021-12-16 11:54:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 12:54:40 +0200 |
commit | ffbe36fc3ee824407b3818c0a6f861176ce56482 (patch) | |
tree | 3bd995b4a40c92c193e6dd39046c1d5017f9aff4 /utils | |
parent | 70ff26b454357c4fdf77ff2cec31380ad3a32f40 (diff) | |
download | redis-ffbe36fc3ee824407b3818c0a6f861176ce56482.tar.gz |
Command table: Sorted subcommands (#9951)
Sort the sub-commands so that every time we execute the script it generates the exact same results.
This will case less merge conflicts if two PRs edit different json files.
also:
* make the script agnostic to where it is executed (more flexible).
* add documentation about commands.c and the json files in the readme.
Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/generate-command-code.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/utils/generate-command-code.py b/utils/generate-command-code.py index e23bc0bfa..513dbc0f1 100755 --- a/utils/generate-command-code.py +++ b/utils/generate-command-code.py @@ -4,8 +4,6 @@ import os import glob import json -# Note: This script should be run from the src/ dir: ../utils/generate-command-code.py - ARG_TYPES = { "string": "ARG_TYPE_STRING", "integer": "ARG_TYPE_INTEGER", @@ -305,12 +303,13 @@ class Command(object): def write_internal_structs(self, f): if self.subcommands: - for subcommand in sorted(self.subcommands, key=lambda cmd: cmd.name): + subcommand_list = sorted(self.subcommands, key=lambda cmd: cmd.name) + for subcommand in subcommand_list: subcommand.write_internal_structs(f) f.write("/* %s command table */\n" % self.fullname()) f.write("struct redisCommand %s[] = {\n" % self.subcommand_table_name()) - for subcommand in self.subcommands: + for subcommand in subcommand_list: f.write("{%s},\n" % subcommand.struct_code()) f.write("{0}\n") f.write("};\n\n") @@ -367,9 +366,12 @@ def create_command(name, desc): # MAIN +# Figure out where the sources are +srcdir = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../src") + # Create all command objects print("Processing json files...") -for filename in glob.glob('commands/*.json'): +for filename in glob.glob('%s/commands/*.json' % srcdir): with open(filename,"r") as f: d = json.load(f) for name, desc in d.items(): @@ -387,7 +389,7 @@ for command in commands.values(): command.subcommands.append(subcommand) print("Generating commands.c...") -with open("commands.c","w") as f: +with open("%s/commands.c" % srcdir,"w") as f: f.write("/* Automatically generated by %s, do not edit. */\n\n" % os.path.basename(__file__)) f.write("#include \"server.h\"\n") f.write( |