diff options
author | JaredD <jareddpub@gmail.com> | 2021-09-27 09:04:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 11:04:13 -0400 |
commit | af3fbe432fe16efb05f26c24a0fa9724680dc8dd (patch) | |
tree | 4a6666b61cbdafc7596d0647d9992a153dd34353 /grc/compiler.py | |
parent | 91e9ddf8e1c37adff0c982c80bd1792df58cbe23 (diff) |
grc: Implement grcc --output switch for hierarchical blocks
* grc: Implement --output functionality for grcc
Reference gnradio Issue #2799.
This commit adjusts some logic and code to enable the --output switch
for grcc.
Prior to this commit, grcc would only output to the GRC_HIER_PATH.
The commit adjusts the various Generators in grc/core/generator to
consistently use
output_dir for the output directory.
If it's None, then take from the platform.config.hier_block_lib_dir
attribute which can be set via the
GRC_HIER_PATH env var.
The cpp_top_block generator was also modified to remote its __init__ function
which appeared identical to its base TopBlockGenerator.
I did not test c++ GRC output.
* Make output directory if does not exist
* Duplicate TopBlockGenerator __init__ without .py extension; base class object
* Typo in os.makedirs kwarg
* Added _warnings method from TopBlockGenerator
Signed-off-by: Jared Dulmage <jared.dulmage@caliola.com>
Diffstat (limited to 'grc/compiler.py')
-rwxr-xr-x | grc/compiler.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/grc/compiler.py b/grc/compiler.py index 3f2bd98b07..2478055daf 100755 --- a/grc/compiler.py +++ b/grc/compiler.py @@ -42,13 +42,12 @@ def main(args=None): ) platform.build_library() - out_dir = args.output if not args.user_lib_dir else platform.config.hier_block_lib_dir - if os.path.exists(out_dir): - pass # all is well - elif args.save_to_lib: - os.mkdir(out_dir) # create missing hier_block lib directory - else: - exit('Error: Invalid output directory') + output_dir = args.output if not args.user_lib_dir else platform.config.hier_block_lib_dir + try: + # recursive mkdir: os.makedirs doesn't work with .. paths, resolve with realpath + os.makedirs(os.path.realpath(output_dir), exist_ok=True) + except Exception as e: + exit(str(e)) Messages.send_init(platform) flow_graph = file_path = None @@ -57,7 +56,7 @@ def main(args=None): Messages.send('\n') flow_graph, file_path = platform.load_and_generate_flow_graph( - os.path.abspath(grc_file), os.path.abspath(out_dir)) + os.path.abspath(grc_file), os.path.abspath(output_dir)) if not file_path: exit('Compilation error') if file_path and args.run: |