Skip to content

Commit 0ea77fa

Browse files
authored
RSDK-7848 remove side-by-side meta.json support (#5008)
1 parent 7e10f2c commit 0ea77fa

File tree

2 files changed

+27
-74
lines changed

2 files changed

+27
-74
lines changed

config/module.go

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const (
2727
defaultFirstRunTimeout = 1 * time.Hour
2828
)
2929

30+
var errLocalTarballEntrypoint = errors.New("local tarballs must contain a meta.json with the 'entrypoint' field")
31+
3032
// Module represents an external resource module, with a path to the binary module file.
3133
type Module struct {
3234
// Name is an arbitrary name used to identify the module, and is used to name it's socket as well.
@@ -197,8 +199,7 @@ func parseJSONFile[T any](path string) (*T, error) {
197199

198200
// EvaluateExePath returns absolute ExePath from one of three sources (in order of precedence):
199201
// 1. if there is a meta.json in the exe dir, use that, except in local non-tarball case.
200-
// 2. if this is a local tarball and there's a meta.json next to the tarball, use that.
201-
// 3. otherwise use the exe path from config, or fail if this is a local tarball.
202+
// 2. otherwise use the exe path from config, or fail if this is a local tarball.
202203
// Note: the working directory must be the unpacked tarball directory or local exec directory.
203204
func (m Module) EvaluateExePath(packagesDir string) (string, error) {
204205
path, err := utils.ExpandHomeDir(m.ExePath)
@@ -233,24 +234,10 @@ func (m Module) EvaluateExePath(packagesDir string) (string, error) {
233234
}
234235
return filepath.Abs(entrypoint)
235236
}
236-
}
237-
if m.NeedsSyntheticPackage() {
238-
// this is case 2, side-by-side
239-
// TODO(RSDK-7848): remove this case once java sdk supports internal meta.json.
240-
metaPath, err := utils.SafeJoinDir(filepath.Dir(path), "meta.json")
241-
if err != nil {
242-
return "", err
237+
if m.NeedsSyntheticPackage() {
238+
// registry modules can use configured ExePath, but for local tarballs it is wrong, throw an error.
239+
return "", errLocalTarballEntrypoint
243240
}
244-
meta, err := parseJSONFile[JSONManifest](metaPath)
245-
if err != nil {
246-
// note: this error deprecates the side-by-side case because the side-by-side case is deprecated.
247-
return "", fmt.Errorf("couldn't find meta.json inside tarball %s (or next to it): %w", path, err)
248-
}
249-
entrypoint, err := utils.SafeJoinDir(exeDir, meta.Entrypoint)
250-
if err != nil {
251-
return "", err
252-
}
253-
return filepath.Abs(entrypoint)
254241
}
255242
return path, nil
256243
}
@@ -464,27 +451,6 @@ func (m Module) getJSONManifest(unpackedModDir string, env map[string]string) (*
464451
}
465452
}
466453

467-
var exeDir string
468-
var localTarballErr error
469-
470-
// TODO(RSDK-7848): remove this case once java sdk supports internal meta.json.
471-
// case 3: local AND tarball
472-
if m.NeedsSyntheticPackage() {
473-
exeDir = filepath.Dir(m.ExePath)
474-
475-
var meta *JSONManifest
476-
meta, localTarballErr = findMetaJSONFile(exeDir)
477-
if localTarballErr != nil {
478-
if !os.IsNotExist(localTarballErr) {
479-
return nil, "", fmt.Errorf("local tarball: %w", localTarballErr)
480-
}
481-
}
482-
483-
if meta != nil {
484-
return meta, exeDir, nil
485-
}
486-
}
487-
488454
if online {
489455
if !ok {
490456
return nil, "", fmt.Errorf("registry module: failed to find meta.json. VIAM_MODULE_ROOT not set: %w", registryTarballErr)
@@ -494,7 +460,7 @@ func (m Module) getJSONManifest(unpackedModDir string, env map[string]string) (*
494460
}
495461

496462
if !localNonTarball {
497-
return nil, "", fmt.Errorf("local tarball: failed to find meta.json: %w", errors.Join(registryTarballErr, localTarballErr))
463+
return nil, "", fmt.Errorf("local tarball: failed to find meta.json: %w", registryTarballErr)
498464
}
499465

500466
return nil, "", errors.New("local non-tarball: did not search for meta.json")

config/module_test.go

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,31 @@ func testChdir(t *testing.T, dir string) {
2727
func TestInternalMeta(t *testing.T) {
2828
tmp := t.TempDir()
2929
testChdir(t, tmp)
30-
testWriteJSON(t, "meta.json", JSONManifest{Entrypoint: "entry"})
3130
packagesDir := filepath.Join(tmp, "packages")
31+
3232
t.Run("local-tarball", func(t *testing.T) {
3333
mod := Module{
3434
Type: ModuleTypeLocal,
3535
ExePath: filepath.Join(tmp, "whatever.tar.gz"),
3636
}
37-
exePath, err := mod.EvaluateExePath(packagesDir)
38-
test.That(t, err, test.ShouldBeNil)
39-
exeDir, err := mod.exeDir(packagesDir)
40-
test.That(t, err, test.ShouldBeNil)
41-
// "entry" is from meta.json.
42-
test.That(t, exePath, test.ShouldEqual, filepath.Join(exeDir, "entry"))
37+
t.Run("meta.json missing", func(t *testing.T) {
38+
_, err := mod.EvaluateExePath(packagesDir)
39+
test.That(t, err, test.ShouldEqual, errLocalTarballEntrypoint)
40+
})
41+
42+
t.Run("meta.json present", func(t *testing.T) {
43+
exeDir, err := mod.exeDir(packagesDir)
44+
test.That(t, err, test.ShouldBeNil)
45+
manifest := JSONManifest{Entrypoint: "entry"}
46+
testWriteJSON(t, filepath.Join(exeDir, "meta.json"), manifest)
47+
exePath, err := mod.EvaluateExePath(packagesDir)
48+
test.That(t, err, test.ShouldBeNil)
49+
test.That(t, exePath, test.ShouldResemble, filepath.Join(exeDir, manifest.Entrypoint))
50+
})
4351
})
4452

4553
t.Run("non-tarball", func(t *testing.T) {
54+
testWriteJSON(t, "meta.json", JSONManifest{Entrypoint: "entry"})
4655
mod := Module{
4756
Type: ModuleTypeLocal,
4857
ExePath: filepath.Join(tmp, "whatever"),
@@ -94,11 +103,8 @@ func TestSyntheticModule(t *testing.T) {
94103
testWriteJSON(t, filepath.Join(tmp, "meta.json"), &meta)
95104

96105
// local tarball case
97-
syntheticPath, err := modNeedsSynthetic.EvaluateExePath(tmp)
98-
test.That(t, err, test.ShouldBeNil)
99-
exeDir, err := modNeedsSynthetic.exeDir(tmp)
100-
test.That(t, err, test.ShouldBeNil)
101-
test.That(t, syntheticPath, test.ShouldEqual, filepath.Join(exeDir, meta.Entrypoint))
106+
_, err := modNeedsSynthetic.EvaluateExePath(tmp)
107+
test.That(t, err, test.ShouldEqual, errLocalTarballEntrypoint)
102108

103109
// vanilla case
104110
notTarPath, err := modNotTar.EvaluateExePath(tmp)
@@ -289,7 +295,6 @@ func TestGetJSONManifest(t *testing.T) {
289295

290296
exePath := filepath.Join(tmp, "module.tgz")
291297
exeDir := filepath.Dir(exePath)
292-
exeMetaJSONFilepath := filepath.Join(exeDir, "meta.json")
293298
unpackedModDir := filepath.Join(tmp, "unpacked-mod-dir")
294299
unpackedModMetaJSONFilepath := filepath.Join(unpackedModDir, "meta.json")
295300
env := map[string]string{}
@@ -308,26 +313,6 @@ func TestGetJSONManifest(t *testing.T) {
308313
test.That(t, err.Error(), test.ShouldContainSubstring, unpackedModDir)
309314
test.That(t, err.Error(), test.ShouldContainSubstring, exeDir)
310315

311-
// meta.json found in executable directory; parsing fails
312-
exeMetaJSONFile, err := os.Create(exeMetaJSONFilepath)
313-
test.That(t, err, test.ShouldBeNil)
314-
defer exeMetaJSONFile.Close()
315-
316-
meta, moduleWorkingDirectory, err = modLocalTar.getJSONManifest(unpackedModDir, env)
317-
test.That(t, meta, test.ShouldBeNil)
318-
test.That(t, moduleWorkingDirectory, test.ShouldBeEmpty)
319-
test.That(t, err, test.ShouldNotBeNil)
320-
test.That(t, err.Error(), test.ShouldContainSubstring, "local tarball")
321-
test.That(t, errors.Is(err, os.ErrNotExist), test.ShouldBeFalse)
322-
323-
// meta.json found in executable directory; parsing succeeds
324-
testWriteJSON(t, exeMetaJSONFilepath, validJSONManifest)
325-
326-
meta, moduleWorkingDirectory, err = modLocalTar.getJSONManifest(unpackedModDir, env)
327-
test.That(t, *meta, test.ShouldResemble, validJSONManifest)
328-
test.That(t, moduleWorkingDirectory, test.ShouldEqual, exeDir)
329-
test.That(t, err, test.ShouldBeNil)
330-
331316
// meta.json found in unpacked modular directory; parsing fails
332317
unpackedModMetaJSONFile, err := os.Create(unpackedModMetaJSONFilepath)
333318
test.That(t, err, test.ShouldBeNil)
@@ -425,6 +410,8 @@ func TestMergeEnvVars(t *testing.T) {
425410
// testWriteJSON is a t.Helper that serializes `value` to `path` as json.
426411
func testWriteJSON(t *testing.T, path string, value any) {
427412
t.Helper()
413+
err := os.MkdirAll(filepath.Dir(path), 0o700)
414+
test.That(t, err, test.ShouldBeNil)
428415
file, err := os.Create(path)
429416
test.That(t, err, test.ShouldBeNil)
430417
defer file.Close()

0 commit comments

Comments
 (0)