Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: load go extensions based on go app's manifest #343

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion core/src/ten_runtime/binding/go/tools/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,20 @@ func (ab *AppBuilder) autoDetectExtensions() error {
return nil
}

// Load the app's `manifest.json` to get the list of extension dependencies.
manifest, err := LoadManifest(ab.options.AppDir)
if err != nil {
return fmt.Errorf("Failed to load manifest.json: %v", err)
}

// Collect names of extensions from dependencies.
extensionNames := make(map[string]bool)
for _, dep := range manifest.Dependencies {
if dep.Type == "extension" {
extensionNames[dep.Name] = true
}
}

entries, err := os.ReadDir(extBaseDir)
if err != nil {
return err
Expand All @@ -1075,6 +1089,18 @@ func (ab *AppBuilder) autoDetectExtensions() error {
continue
}

// Check if the extension is in the list of extension dependencies.
extensionName := entry.Name()
if _, ok := extensionNames[extensionName]; !ok {
if ab.options.Verbose {
log.Printf(
"Skipping extension [%s], not in manifest dependencies.\n",
extensionName,
)
}
continue
}

extDir := path.Join(extBaseDir, entry.Name())
ext, err := LoadExtensionModule(extDir, ab.options.Verbose)
if err != nil {
Expand Down Expand Up @@ -1113,8 +1139,17 @@ func (ab *AppBuilder) autoDetectExtensions() error {

// -------------- manifest ---------------

type Dependency struct {
Type string `json:"type"`
Name string `json:"name"`
Version string `json:"version"`
}

type TenPackageManifest struct {
Type string `json:"type"`
Type string `json:"type"`
Name string `json:"name"`
Version string `json:"version"`
Dependencies []Dependency `json:"dependencies"`
}

func LoadManifest(pkgDir string) (*TenPackageManifest, error) {
Expand Down