From 2fe65a059fc48e4a4f3c6fa4fddb2035b3648fb1 Mon Sep 17 00:00:00 2001 From: Nellie McKesson Date: Tue, 7 Mar 2023 11:14:40 -0800 Subject: [PATCH] adding a new data file for things like pico sdk version --- Makefile | 4 +-- build.ninja | 3 +++ scripts/create_auto_ninjabuild.py | 21 ++++++++++++--- scripts/create_output_supplemental_data.py | 30 ++++++++++++++++++++++ scripts/transform_doxygen_html.py | 26 +++---------------- 5 files changed, 56 insertions(+), 28 deletions(-) create mode 100755 scripts/create_output_supplemental_data.py diff --git a/Makefile b/Makefile index a4c49ca481..2341a582c9 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ clean_doxygen_html: # Also need to move index.adoc to a different name, because it conflicts with the autogenerated index.adoc $(ASCIIDOC_DOXYGEN_DIR)/picosdk_index.json $(ASCIIDOC_DOXYGEN_DIR)/index_doxygen.adoc: $(SCRIPTS_DIR)/transform_doxygen_html.py $(PICO_SDK_DIR)/docs/index.h $(DOXYGEN_PICO_SDK_BUILD_DIR)/docs/Doxyfile | $(DOXYGEN_HTML_DIR) $(ASCIIDOC_DOXYGEN_DIR) $(MAKE) clean_ninja - $< $(DOXYGEN_HTML_DIR) $(ASCIIDOC_DOXYGEN_DIR) $(PICO_SDK_DIR)/docs/index.h $(DOXYGEN_PICO_SDK_BUILD_DIR)/docs/Doxyfile $(SITE_CONFIG) $(ASCIIDOC_DOXYGEN_DIR)/picosdk_index.json + $< $(DOXYGEN_HTML_DIR) $(ASCIIDOC_DOXYGEN_DIR) $(PICO_SDK_DIR)/docs/index.h $(ASCIIDOC_DOXYGEN_DIR)/picosdk_index.json cp $(DOXYGEN_HTML_DIR)/*.png $(ASCIIDOC_DOXYGEN_DIR) mv $(ASCIIDOC_DOXYGEN_DIR)/index.adoc $(ASCIIDOC_DOXYGEN_DIR)/index_doxygen.adoc @@ -89,7 +89,7 @@ clean_everything: clean_submodules clean_doxygen_html clean # AUTO_NINJABUILD contains all the parts of the ninjabuild where the rules themselves depend on other files $(AUTO_NINJABUILD): $(SCRIPTS_DIR)/create_auto_ninjabuild.py $(DOCUMENTATION_INDEX) $(SITE_CONFIG) | $(BUILD_DIR) - $< $(DOCUMENTATION_INDEX) $(SITE_CONFIG) $(ASCIIDOC_DIR) $(SCRIPTS_DIR) $(ASCIIDOC_BUILD_DIR) $(ASCIIDOC_INCLUDES_DIR) $(JEKYLL_ASSETS_DIR) $(DOCUMENTATION_REDIRECTS_DIR) $(IMAGES_DIR) $@ + $< $(DOCUMENTATION_INDEX) $(SITE_CONFIG) $(ASCIIDOC_DIR) $(SCRIPTS_DIR) $(ASCIIDOC_BUILD_DIR) $(ASCIIDOC_INCLUDES_DIR) $(JEKYLL_ASSETS_DIR) $(DOXYGEN_PICO_SDK_BUILD_DIR) $(DOCUMENTATION_REDIRECTS_DIR) $(IMAGES_DIR) $@ # This runs ninjabuild to build everything in the ASCIIDOC_BUILD_DIR (and ASCIIDOC_INCLUDES_DIR) run_ninja: $(AUTO_NINJABUILD) diff --git a/build.ninja b/build.ninja index 61b5f2e55c..56acd19aef 100644 --- a/build.ninja +++ b/build.ninja @@ -18,6 +18,9 @@ rule create_categories_page rule create_toc command = $scripts_dir/create_nav.py $in $src_dir $out +rule create_output_supplemental_data + command = $scripts_dir/create_output_supplemental_data.py $in $out + rule create_build_adoc command = $scripts_dir/create_build_adoc.py $documentation_index $site_config $GITHUB_EDIT_TEMPLATE $in $inc_dir $out diff --git a/scripts/create_auto_ninjabuild.py b/scripts/create_auto_ninjabuild.py index e775b0a54e..0a4122725d 100755 --- a/scripts/create_auto_ninjabuild.py +++ b/scripts/create_auto_ninjabuild.py @@ -60,9 +60,12 @@ def add_entire_directory(tab_dir, dir_path, pages_set, src_images, dest_images): output_dir = sys.argv[5] adoc_includes_dir = sys.argv[6] assets_dir = sys.argv[7] - redirects_dir = sys.argv[8] - images_dir = sys.argv[9] - output_ninjabuild = sys.argv[10] + doxygen_pico_sdk_build_dir = sys.argv[8] + if not os.path.exists(doxygen_pico_sdk_build_dir): + raise Exception("{} doesn't exist".format(doxygen_pico_sdk_build_dir)) + redirects_dir = sys.argv[9] + images_dir = sys.argv[10] + output_ninjabuild = sys.argv[11] global_images = ['full-sized/Datasheets.png', 'full-sized/PIP.png', 'full-sized/Tutorials.png', 'full-sized/Forums.png'] @@ -134,6 +137,7 @@ def add_entire_directory(tab_dir, dir_path, pages_set, src_images, dest_images): ninja.variable('documentation_index', index_json) ninja.variable('output_index', os.path.join(output_dir, "_data", "index.json")) ninja.variable('site_config', config_yaml) + ninja.variable('doxyfile', os.path.join(doxygen_pico_sdk_build_dir, "docs", "Doxyfile")) ninja.newline() targets = [] @@ -247,6 +251,17 @@ def add_entire_directory(tab_dir, dir_path, pages_set, src_images, dest_images): targets = [] ninja.newline() + # supplemental data + dest = os.path.join('$out_dir', '_data', 'supplemental.json') + source = '$doxyfile' + extra_sources = ['$scripts_dir/create_output_supplemental_data.py'] + ninja.build(dest, 'create_output_supplemental_data', source, extra_sources) + targets.append(dest) + if targets: + ninja.default(targets) + targets = [] + ninja.newline() + # Redirects & htaccess dest = os.path.join('$out_dir', '.htaccess') source = '$HTACCESS_EXTRA' diff --git a/scripts/create_output_supplemental_data.py b/scripts/create_output_supplemental_data.py new file mode 100755 index 0000000000..b1651bb07a --- /dev/null +++ b/scripts/create_output_supplemental_data.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import os +import sys +import json +import re + +def add_release_version(doxyfile_path, data_obj): + with open(doxyfile_path) as f: + doxy_content = f.read() + version_search = re.search("(\nPROJECT_NUMBER\s*=\s*)([\d.]+)", doxy_content) + if version_search is not None: + version = version_search.group(2) + data_obj["pico_sdk_release"] = version + return data_obj + +def write_new_data_file(output_dir, data_obj): + f = open(output_dir, 'w') + f.write(json.dumps(data_obj)) + f.close() + return + +if __name__ == "__main__": + # read the doxygen config file + input_file = sys.argv[1] + # output the new data file + output_dir = sys.argv[2] + data_obj = {} + data_obj = add_release_version(input_file, data_obj) + write_new_data_file(output_dir, data_obj) \ No newline at end of file diff --git a/scripts/transform_doxygen_html.py b/scripts/transform_doxygen_html.py index aba62e59a0..c402543dc8 100755 --- a/scripts/transform_doxygen_html.py +++ b/scripts/transform_doxygen_html.py @@ -578,22 +578,6 @@ def parse_header(header_path): print("ERROR: ", e, exc_tb.tb_lineno) return h_json -def update_release_version(doxyfile_path, site_config_path): - try: - with open(doxyfile_path) as f: - doxy_content = f.read() - version_search = re.search("(\nPROJECT_NUMBER\s*=\s*)([\d.]+)", doxy_content) - if version_search is not None: - version = version_search.group(2) - with open(site_config_path) as c: - config_content = c.read() - new_config = re.sub("doxygen_release: \S+", "doxygen_release: "+version, config_content) - write_output(site_config_path, new_config) - except Exception as e: - exc_type, exc_obj, exc_tb = sys.exc_info() - print("ERROR: ", e, exc_tb.tb_lineno) - return - def compile_json_mappings(json_dir, json_files): try: compiled = [] @@ -646,7 +630,7 @@ def walk_nested_adoc(k, v, output_path, level): print("ERROR: ", e, exc_tb.tb_lineno) return level -def handler(html_path, output_path, header_path, doxyfile_path, site_config_path, output_json): +def handler(html_path, output_path, header_path, output_json): try: dir_path = os.path.dirname(os.path.realpath(__file__)) json_dir = os.path.join(dir_path, "doxygen_json_mappings") @@ -754,8 +738,6 @@ def handler(html_path, output_path, header_path, doxyfile_path, site_config_path write_output(group_output_path, group_adoc) # write the json structure file as well write_output(output_json, json.dumps(h_json, indent="\t")) - # set the doxygen release version - update_release_version(doxyfile_path, site_config_path) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() print("ERROR: ", e, exc_tb.tb_lineno) @@ -765,7 +747,5 @@ def handler(html_path, output_path, header_path, doxyfile_path, site_config_path html_path = sys.argv[1] output_path = sys.argv[2] header_path = sys.argv[3] - doxyfile_path = sys.argv[4] - site_config_path = sys.argv[5] - output_json = sys.argv[6] - handler(html_path, output_path, header_path, doxyfile_path, site_config_path, output_json) + output_json = sys.argv[4] + handler(html_path, output_path, header_path, output_json)