Skip to content

Commit

Permalink
add some flags
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas committed Jan 21, 2024
1 parent d02bc8c commit 7d4ab95
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Espressif ESP32 Core Board V2"
title: "ESP32 Core Board V2"
weight: 3
---

Expand Down
14 changes: 13 additions & 1 deletion doc-gen/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
all:
go run . `tinygo targets`
go run . --machine --interfaces --pins --matrix `tinygo targets`

interfaces:
go run . --interfaces `tinygo targets`

pins:
go run . --pins `tinygo targets`

matrix:
go run . --matrix `tinygo targets`

help:
go run . --help
48 changes: 28 additions & 20 deletions doc-gen/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ var targetsKnownToSkip = map[string]struct{}{"atmega1284p": {}, "attiny1616": {}
var targetsKnownToSkipAndShouldBeDocumented = map[string]struct{}{"bluemicro840": {}, "esp32-c3-devkit-rust-1": {},
"feather-m0-express": {}}

// TODO: fix wrong matrix output
// TODO: revert unneeded adjustments in mcu pages (e.g. link text)
func Execute(targets []string) {
// TODO: support parameters: machine doc, pins table, interfaces table, hw matrix
func Execute(targets []string, createMachineDoc, updateBoardInterfaces, updateBoardPins, createHardwareMatrix bool) {
// collect
collector := collectFiles(targets)

Expand All @@ -62,21 +62,24 @@ func Execute(targets []string) {
if co.docStatus == canProcessed {
fmt.Println(" Generating documentation...")
machineDocPath := filepath.Join(controllerDocBaseDir, "machine", target+".md")
if err := updateMicrocontrollerDocumentation(target, machineDocPath, co.controllerDocPath); err != nil {
if err := updateMicrocontrollerDocumentation(target, machineDocPath, co.controllerDocPath,
createMachineDoc, updateBoardInterfaces, updateBoardPins); err != nil {
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
co.errors = append(co.errors, err)
}
}

fmt.Println(" Prepare hardware matrix...")
matrixRow, err := hardwarematrix.ParseFeatureMap(co.controllerDocPath)
if err != nil {
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
co.errors = append(co.errors, err)
continue
}
if createHardwareMatrix {
fmt.Println(" Prepare hardware matrix...")
matrixRow, err := hardwarematrix.ParseFeatureMap(co.controllerDocPath)
if err != nil {
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
co.errors = append(co.errors, err)
continue
}

co.matrixRow = matrixRow
co.matrixRow = matrixRow
}

if co.docStatus == documentFound {
co.docStatus = finishedWithoutTargetOk
Expand All @@ -85,10 +88,12 @@ func Execute(targets []string) {
co.docStatus = finishedOk
}

fmt.Println("\nUpdate hardware matrix...")
hwmatrixDocPath := filepath.Join("..", "content", "docs", "reference", "hardware-matrix.md")
if err := updateHardwareMatrix(hwmatrixDocPath, collector); err != nil {
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
if createHardwareMatrix {
fmt.Println("\nUpdate hardware matrix...")
hwmatrixDocPath := filepath.Join("..", "content", "docs", "reference", "hardware-matrix.md")
if err := updateHardwareMatrix(hwmatrixDocPath, collector); err != nil {
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
}
}

// summary
Expand Down Expand Up @@ -201,18 +206,21 @@ func collectFiles(targets []string) map[string]*collection {
return collector
}

func updateMicrocontrollerDocumentation(target, machineDocPath, controllerDocPath string) error {
func updateMicrocontrollerDocumentation(target, machineDocPath, controllerDocPath string,
createMachineDoc, updateBoardInterfaces, updateBoardPins bool) error {
ti, err := targetinfo.Create(target)
if err != nil {
return fmt.Errorf("target info can not be created: %v", err)
}

err = machinepackagedoc.CreateNew(machineDocPath, target, ti.Pkg)
if err != nil {
return fmt.Errorf("error on write machine package doc: %v", err)
if createMachineDoc {
err = machinepackagedoc.CreateNew(machineDocPath, target, ti.Pkg)
if err != nil {
return fmt.Errorf("error on write machine package doc: %v", err)
}
}

errors := boarddoc.Update(controllerDocPath, ti)
errors := boarddoc.Update(controllerDocPath, ti, updateBoardInterfaces, updateBoardPins)
if len(errors) > 0 {
return fmt.Errorf("error on update board documentation: %v", errors)
}
Expand Down
16 changes: 13 additions & 3 deletions doc-gen/doc-gen.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package main

import (
"os"
"flag"
"fmt"

"github.com/tinygo-org/tinygo-site/doc-gen/cmd"
)

// main just calls the Execute function
func main() {

createMachineDoc := flag.Bool("machine", false, "re-create machine package documentation for the given targets")
updateBoardInterfaces := flag.Bool("interfaces", false, "update the Interfaces table for the given targets")
updateBoardPins := flag.Bool("pins", false, "update the Pins table for the given targets")
createHardwareMatrix := flag.Bool("matrix", false, "re-create the hardware matrix document")
flag.Parse()

// get the targets from the list of command line options
targets := os.Args[1:]
cmd.Execute(targets)
targets := flag.Args()
fmt.Printf("Targets: %+q\n", targets)

cmd.Execute(targets, *createMachineDoc, *updateBoardInterfaces, *updateBoardPins, *createHardwareMatrix)
}
24 changes: 14 additions & 10 deletions doc-gen/internal/boarddoc/boarddoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/tinygo-org/tinygo-site/doc-gen/internal/targetinfo"
)

func Update(path string, ti *targetinfo.TargetInfo) []error {
func Update(path string, ti *targetinfo.TargetInfo, updateInterfaces, updatePins bool) []error {
// Read the entire Markdown file in memory.
docBuf, err := os.ReadFile(path)
if err != nil {
Expand All @@ -18,17 +18,21 @@ func Update(path string, ti *targetinfo.TargetInfo) []error {

var interfacesUpdated, pinsUpdated bool
var errors []error
features := ti.SupportedFeatures()
doc, interfacesUpdated, err = updateInterfacesSection(doc, features)
if err != nil {
fmt.Fprintln(os.Stderr, "interfaces section could not be updated", err)
errors = append(errors, err)
if updateInterfaces {
features := ti.SupportedFeatures()
doc, interfacesUpdated, err = updateInterfacesSection(doc, features)
if err != nil {
fmt.Fprintln(os.Stderr, "interfaces section could not be updated", err)
errors = append(errors, err)
}
}

doc, pinsUpdated, err = updatePinsSection(doc, ti)
if err != nil {
fmt.Fprintln(os.Stderr, "pins section could not be updated", err)
errors = append(errors, err)
if updatePins {
doc, pinsUpdated, err = updatePinsSection(doc, ti)
if err != nil {
fmt.Fprintln(os.Stderr, "pins section could not be updated", err)
errors = append(errors, err)
}
}

if !interfacesUpdated && !pinsUpdated {
Expand Down

0 comments on commit 7d4ab95

Please sign in to comment.