summaryrefslogtreecommitdiff
path: root/grc/core
diff options
context:
space:
mode:
authorJaredD <jareddpub@gmail.com>2021-09-27 09:04:13 -0600
committerGitHub <noreply@github.com>2021-09-27 11:04:13 -0400
commitaf3fbe432fe16efb05f26c24a0fa9724680dc8dd (patch)
tree4a6666b61cbdafc7596d0647d9992a153dd34353 /grc/core
parent91e9ddf8e1c37adff0c982c80bd1792df58cbe23 (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/core')
-rw-r--r--grc/core/generator/Generator.py6
-rw-r--r--grc/core/generator/cpp_top_block.py41
-rw-r--r--grc/core/generator/hier_block.py8
-rw-r--r--grc/core/generator/top_block.py2
-rw-r--r--grc/core/platform.py11
5 files changed, 43 insertions, 25 deletions
diff --git a/grc/core/generator/Generator.py b/grc/core/generator/Generator.py
index 204ee7e620..3f1831cc1b 100644
--- a/grc/core/generator/Generator.py
+++ b/grc/core/generator/Generator.py
@@ -15,14 +15,14 @@ from .cpp_hier_block import CppHierBlockGenerator
class Generator(object):
"""Adaptor for various generators (uses generate_options)"""
- def __init__(self, flow_graph, file_path):
+ def __init__(self, flow_graph, output_dir):
"""
Initialize the generator object.
Determine the file to generate.
Args:
flow_graph: the flow graph object
- file_path: the path to the grc file
+ output_dir: the output path for generated files
"""
self.generate_options = flow_graph.get_option('generate_options')
self.output_language = flow_graph.get_option('output_language')
@@ -45,7 +45,7 @@ class Generator(object):
else:
generator_cls = CppTopBlockGenerator
- self._generator = generator_cls(flow_graph, file_path)
+ self._generator = generator_cls(flow_graph, output_dir)
def __getattr__(self, item):
"""get all other attrib from actual generator object"""
diff --git a/grc/core/generator/cpp_top_block.py b/grc/core/generator/cpp_top_block.py
index f0da138bbe..ee9dc1a314 100644
--- a/grc/core/generator/cpp_top_block.py
+++ b/grc/core/generator/cpp_top_block.py
@@ -26,16 +26,15 @@ source_template = Template(filename=SOURCE_TEMPLATE)
cmake_template = Template(filename=CMAKE_TEMPLATE)
-class CppTopBlockGenerator(TopBlockGenerator):
+class CppTopBlockGenerator(object):
- def __init__(self, flow_graph, file_path):
+ def __init__(self, flow_graph, output_dir):
"""
- Initialize the C++ top block generator object.
+ Initialize the top block generator object.
Args:
flow_graph: the flow graph object
- file_path: the path where we want to create
- a new directory with C++ files
+ output_dir: the path for written files
"""
self._flow_graph = FlowGraphProxy(flow_graph)
@@ -44,14 +43,32 @@ class CppTopBlockGenerator(TopBlockGenerator):
self._mode = TOP_BLOCK_FILE_MODE
# Handle the case where the directory is read-only
# In this case, use the system's temp directory
- if not os.access(file_path, os.W_OK):
- file_path = tempfile.gettempdir()
-
- # When generating C++ code, we create a new directory
- # (file_path) and generate the files inside that directory
+ if not os.access(output_dir, os.W_OK):
+ output_dir = tempfile.gettempdir()
filename = self._flow_graph.get_option('id')
- self.file_path = os.path.join(file_path, filename)
- self._dirname = file_path
+ self.file_path = os.path.join(output_dir, filename)
+ self.output_dir = output_dir
+
+ def _warnings(self):
+ throttling_blocks = [b for b in self._flow_graph.get_enabled_blocks()
+ if b.flags.throttle]
+ if not throttling_blocks and not self._generate_options.startswith('hb'):
+ Messages.send_warning("This flow graph may not have flow control: "
+ "no audio or RF hardware blocks found. "
+ "Add a Misc->Throttle block to your flow "
+ "graph to avoid CPU congestion.")
+ if len(throttling_blocks) > 1:
+ keys = set([b.key for b in throttling_blocks])
+ if len(keys) > 1 and 'blocks_throttle' in keys:
+ Messages.send_warning("This flow graph contains a throttle "
+ "block and another rate limiting block, "
+ "e.g. a hardware source or sink. "
+ "This is usually undesired. Consider "
+ "removing the throttle block.")
+
+ deprecated_block_keys = {b.name for b in self._flow_graph.get_enabled_blocks() if b.flags.deprecated}
+ for key in deprecated_block_keys:
+ Messages.send_warning("The block {!r} is deprecated.".format(key))
def write(self):
"""create directory, generate output and write it to files"""
diff --git a/grc/core/generator/hier_block.py b/grc/core/generator/hier_block.py
index 9c80271235..d609a50ff9 100644
--- a/grc/core/generator/hier_block.py
+++ b/grc/core/generator/hier_block.py
@@ -12,15 +12,17 @@ from ..io import yaml
class HierBlockGenerator(TopBlockGenerator):
"""Extends the top block generator to also generate a block YML file"""
- def __init__(self, flow_graph, _):
+ def __init__(self, flow_graph, output_dir=None):
"""
Initialize the hier block generator object.
Args:
flow_graph: the flow graph object
+ output_dir: the path for written files
"""
- platform = flow_graph.parent
- output_dir = platform.config.hier_block_lib_dir
+ if output_dir is None:
+ platform = flow_graph.parent
+ output_dir = platform.config.hier_block_lib_dir
if not os.path.exists(output_dir):
os.mkdir(output_dir)
diff --git a/grc/core/generator/top_block.py b/grc/core/generator/top_block.py
index 6653bc7ae0..275921da51 100644
--- a/grc/core/generator/top_block.py
+++ b/grc/core/generator/top_block.py
@@ -26,7 +26,7 @@ class TopBlockGenerator(object):
Args:
flow_graph: the flow graph object
- output_dir: the path to write the file to
+ output_dir: the path for written files
"""
self._flow_graph = FlowGraphProxy(flow_graph)
diff --git a/grc/core/platform.py b/grc/core/platform.py
index 42d5b660c7..1064dc6ba2 100644
--- a/grc/core/platform.py
+++ b/grc/core/platform.py
@@ -73,7 +73,7 @@ class Platform(Element):
if os.path.exists(os.path.normpath(file_path)):
return file_path
- def load_and_generate_flow_graph(self, file_path, out_path=None, hier_only=False):
+ def load_and_generate_flow_graph(self, file_path, out_dir=None, hier_only=False):
"""Loads a flow graph from file and generates it"""
Messages.set_indent(len(self._auto_hier_block_generate_chain))
Messages.send('>>> Loading: {}\n'.format(file_path))
@@ -101,17 +101,16 @@ class Platform(Element):
Messages.set_indent(len(self._auto_hier_block_generate_chain))
try:
- generator = self.Generator(flow_graph, out_path or file_path)
+ if flow_graph.get_option('generate_options').startswith('hb'):
+ generator = self.Generator(flow_graph, out_dir)
+ else:
+ generator = self.Generator(flow_graph, out_dir or file_path)
Messages.send('>>> Generating: {}\n'.format(generator.file_path))
generator.write()
except Exception as e:
Messages.send('>>> Generate Error: {}: {}\n'.format(file_path, str(e)))
return None, None
- if flow_graph.get_option('generate_options').startswith('hb'):
- # self.load_block_xml(generator.file_path_xml)
- # TODO: implement yml output for hier blocks
- pass
return flow_graph, generator.file_path
def build_library(self, path=None):