Skip to content

Commit e41fb7c

Browse files
authored
copy LICENSE file on bootstrap (#34)
1 parent 08e08a1 commit e41fb7c

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

cmd/dpm/cmd/repo_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"testing"
1414

15+
root "daml.com/x/assistant"
1516
"daml.com/x/assistant/pkg/assistantconfig"
1617
"daml.com/x/assistant/pkg/licenseutils"
1718
"daml.com/x/assistant/pkg/ocilister"
@@ -92,6 +93,12 @@ func (suite *RepoSuite) TestRepoCreateTarball() {
9293
require.NoError(t, err)
9394
verifyLnkAtPath(t, filepath.Join(dir, entries[0].Name()))
9495
})
96+
t.Run("verify LICENSE file", func(t *testing.T) {
97+
licenseFile := filepath.Join(tmpDamlHome, "cache", "components", "dpm", "4.5.6", "LICENSE")
98+
bytes, err := os.ReadFile(licenseFile)
99+
require.NoError(t, err)
100+
assert.Equal(t, bytes, root.License)
101+
})
95102
})
96103

97104
t.Run("test multi-platform sdk", func(t *testing.T) {

embed.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2017-2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package root
5+
6+
import _ "embed"
7+
8+
//go:embed LICENSE
9+
var License []byte

pkg/sdkbundle/sdkbundle.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"runtime"
1414
"strings"
1515

16+
root "daml.com/x/assistant"
1617
"daml.com/x/assistant/pkg/assembler"
1718
"daml.com/x/assistant/pkg/assistantconfig"
1819
"daml.com/x/assistant/pkg/assistantconfig/assistantremote"
@@ -62,7 +63,18 @@ func bootstrap(ctx context.Context, config *assistantconfig.Config, bundlePath s
6263
}
6364

6465
sdkVersion := manifest.Spec.Version.Value()
65-
if _, err := sdkinstall.LinkAssistantIfNewerSdk(config, *assemblyResult.AssistantAbsolutePath, &sdkVersion); err != nil {
66+
assistantBinPath := *assemblyResult.AssistantAbsolutePath
67+
if _, err := sdkinstall.LinkAssistantIfNewerSdk(config, assistantBinPath, &sdkVersion); err != nil {
68+
return err
69+
}
70+
71+
// Copy LICENSE file into $DPM_HOME/cache/components/dpm/<version>/
72+
// We'll assume the `dpm` binary running this bootstrap is of the same <version>
73+
74+
// Note that bootstrap only runs once, namely when installing a tarball, and doesn't run when dpm install <sdk version>
75+
// This means only the first dpm version under $DPM_HOME/cache/components/dpm/ will have the LICENSE file,
76+
// but later ones obtained via dpm install won't!
77+
if err := os.WriteFile(filepath.Join(filepath.Dir(assistantBinPath), "LICENSE"), root.License, 0666); err != nil {
6678
return err
6779
}
6880

0 commit comments

Comments
 (0)