Skip to content

Commit 4881e6c

Browse files
authored
Updates build process to unify with dump and fdw anywhere. Closes #9
1 parent 6e04713 commit 4881e6c

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
build:
2-
go run generate/generator.go templates . $(plugin_alias) $(plugin_github_url)
1+
# Check if the 'plugin' variable is set
2+
validate_plugin:
3+
ifndef plugin
4+
$(error "The 'plugin' variable is missing. Usage: make build plugin=<plugin_name>")
5+
endif
6+
7+
build: validate_plugin
8+
go run generate/generator.go templates . $(plugin) $(plugin_github_url)
39
go mod tidy
410
make -f out/Makefile build

generate/generator.go

+23-11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import (
1313

1414
const templateExt = ".tmpl"
1515

16+
type RenderData struct {
17+
Plugin string
18+
PluginGithubUrl string
19+
}
20+
1621
func RenderDir(templatePath, root, pluginAlias, pluginGithubUrl string) {
1722
var targetFilePath string
1823
err := filepath.Walk(templatePath, func(filePath string, info os.FileInfo, err error) error {
@@ -59,12 +64,9 @@ func RenderDir(templatePath, root, pluginAlias, pluginGithubUrl string) {
5964
var renderedContent strings.Builder
6065

6166
// define the data to be used in the template
62-
data := struct {
63-
PluginAlias string
64-
PluginGithubUrl string
65-
}{
66-
pluginAlias,
67-
pluginGithubUrl,
67+
data := RenderData{
68+
Plugin: pluginAlias,
69+
PluginGithubUrl: pluginGithubUrl,
6870
}
6971

7072
// execute the template with the data
@@ -95,15 +97,25 @@ func RenderDir(templatePath, root, pluginAlias, pluginGithubUrl string) {
9597

9698
func main() {
9799
// Check if the correct number of command-line arguments are provided
98-
if len(os.Args) != 5 {
99-
fmt.Println("Usage: go run generator.go <templatePath> <root> <pluginAlias> <pluginGithubUrl>")
100+
if len(os.Args) < 4 {
101+
fmt.Println("Usage: go run generator.go <templatePath> <root> <plugin> [pluginGithubUrl]")
100102
return
101103
}
102104

103105
templatePath := os.Args[1]
104106
root := os.Args[2]
105-
pluginAlias := os.Args[3]
106-
pluginGithubUrl := os.Args[4]
107+
plugin := os.Args[3]
108+
var pluginGithubUrl string
109+
110+
fmt.Println(len(os.Args))
111+
112+
// Check if PluginGithubUrl is provided as a command-line argument
113+
if len(os.Args) == 5 {
114+
pluginGithubUrl = os.Args[4]
115+
} else {
116+
// If PluginGithubUrl is not provided, generate it based on PluginAlias
117+
pluginGithubUrl = "github.com/turbot/steampipe-plugin-" + plugin
118+
}
107119

108120
// Convert relative paths to absolute paths
109121
absTemplatePath, err := filepath.Abs(templatePath)
@@ -118,5 +130,5 @@ func main() {
118130
return
119131
}
120132

121-
RenderDir(absTemplatePath, absRoot, pluginAlias, pluginGithubUrl)
133+
RenderDir(absTemplatePath, absRoot, plugin, pluginGithubUrl)
122134
}

templates/main.go.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ package main
55
import (
66
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
77

8-
"{{.PluginGithubUrl}}/{{.PluginAlias}}"
8+
"{{.PluginGithubUrl}}/{{.Plugin}}"
99
)
1010

11-
var pluginServer = plugin.Server(&plugin.ServeOpts{PluginFunc: {{.PluginAlias}}.Plugin})
12-
var pluginAlias = "{{.PluginAlias}}"
11+
var pluginServer = plugin.Server(&plugin.ServeOpts{PluginFunc: {{.Plugin}}.Plugin})
12+
var pluginAlias = "{{.Plugin}}"
1313

1414
func init() {
1515
setupLogger(pluginAlias)

templates/out/Makefile.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ ifeq ($(shell uname -s),Darwin)
44
endif
55

66
build:
7-
go build -v -x -buildmode=c-shared -o steampipe_sqlite_extension_{{.PluginAlias}}.so
7+
go build -buildmode=c-shared -o steampipe_sqlite_extension_{{.Plugin}}.so

templates/out/README.md.tmpl

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# Steampipe SQLite Extension {{.PluginAlias}}
1+
# Steampipe SQLite Extension {{.Plugin}}
22

3-
This SQLite extensions allows you to query {{.PluginAlias}} using the [Steampipe Plugin](https://{{.PluginGithubUrl}})
3+
This SQLite extensions allows you to query {{.Plugin}} using the [Steampipe Plugin](https://{{.PluginGithubUrl}})
44

55
## Prerequisites
66
- A build of SQLite that supports extensions, you can verify this by opening SQLite and ensuring `.help` displays a `.load command`.
77
- If required you can [download](https://www.sqlite.org/download.html) a pre-compiled binary or compile from [source](https://github.com/sqlite/sqlite#compiling-for-unix-like-systems)
88

99
## Configuration
10-
If you require [configuration](https://hub.steampipe.io/plugins/turbot/{{.PluginAlias}}#configuration) for the extension, you need to set this prior to loading the extension.
10+
If you require [configuration](https://hub.steampipe.io/plugins/turbot/{{.Plugin}}#configuration) for the extension, you need to set this prior to loading the extension.
1111

1212
- Create the configuration table if it doesn't exist:
13-
- `CREATE TABLE IF NOT EXISTS {{.PluginAlias}}_config(config TEXT);`
13+
- `CREATE TABLE IF NOT EXISTS {{.Plugin}}_config(config TEXT);`
1414
- Insert your configuration into the config table:
15-
- `INSERT INTO {{.PluginAlias}}_config(config) VALUES('your_config="GoesHere"')`
15+
- `INSERT INTO {{.Plugin}}_config(config) VALUES('your_config="GoesHere"')`
1616

1717
## Installation
18-
- Copy the binary `steampipe-sqlite-extension-{{.PluginAlias}}.so` to a directory of choice.
18+
- Copy the binary `steampipe-sqlite-extension-{{.Plugin}}.so` to a directory of choice.
1919
- Start your `sqlite` instance.
2020
- `sqlite3` or `sqlite3 myDB.file`
2121
- Load the extension into `sqlite`.
22-
- `.load /path/to/steampipe-sqlite-extension-{{.PluginAlias}}.so`
22+
- `.load /path/to/steampipe-sqlite-extension-{{.Plugin}}.so`
2323

2424
## Usage
25-
Please refer to the [Table Documentation](https://hub.steampipe.io/plugins/turbot/{{.PluginAlias}}/tables).
25+
Please refer to the [Table Documentation](https://hub.steampipe.io/plugins/turbot/{{.Plugin}}/tables).

0 commit comments

Comments
 (0)