Skip to content

Commit

Permalink
adding a new data file for things like pico sdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
nelliemckesson committed Mar 7, 2023
1 parent b160048 commit 2fe65a0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 18 additions & 3 deletions scripts/create_auto_ninjabuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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'
Expand Down
30 changes: 30 additions & 0 deletions scripts/create_output_supplemental_data.py
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 3 additions & 23 deletions scripts/transform_doxygen_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit 2fe65a0

Please sign in to comment.