Skip to content

Commit 0847d46

Browse files
authored
Merge pull request ActiveState#3646 from ActiveState/mitchell/dx-3225
Added "--portable" flag to `state checkout` for copying runtime files instead of linking them.
2 parents ff76ae5 + 6f65ee3 commit 0847d46

File tree

11 files changed

+31
-10
lines changed

11 files changed

+31
-10
lines changed

cmd/state/internal/cmdtree/checkout.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func newCheckoutCommand(prime *primer.Values) *captain.Command {
2626
Description: locale.Tl("flag_state_checkout_runtime-path_description", "Path to store the runtime files"),
2727
Value: &params.RuntimePath,
2828
},
29+
{
30+
Name: "portable",
31+
Description: locale.Tl("flag_state_checkout_portable_description", "Copy files to their runtime path instead of linking to them"),
32+
Value: &params.Portable,
33+
},
2934
{
3035
Name: "no-clone",
3136
Description: locale.Tl("flag_state_checkout_no_clone_description", "Do not clone the github repository associated with this project (if any)"),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# It is recommended that you do not commit this file as it contains configuration that is specific to your machine
22
cache: {{ .Cache }}
3+
portable: {{ .Portable }}

internal/runbits/checkout/checkout.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func New(repo git.Repository, prime primeable) *Checkout {
5252
return &Checkout{repo, prime}
5353
}
5454

55-
func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath string, noClone, bareCheckout bool) (_ string, rerr error) {
55+
func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath string, noClone, bareCheckout, portable bool) (_ string, rerr error) {
5656
defer r.rationalizeError(&rerr)
5757

5858
path, err := r.pathToUse(ns, targetPath)
@@ -94,7 +94,7 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath
9494
return "", errNoCommitID
9595
}
9696

97-
if err := CreateProjectFiles(path, cachePath, owner, proj, branchName, commitID.String(), language); err != nil {
97+
if err := CreateProjectFiles(path, cachePath, owner, proj, branchName, commitID.String(), language, portable); err != nil {
9898
return "", errs.Wrap(err, "Could not create project files")
9999
}
100100

@@ -182,7 +182,7 @@ func (r *Checkout) fetchProject(
182182
return owner, proj, commitID, branchName, language, pj.RepoURL, nil
183183
}
184184

185-
func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID, language string) error {
185+
func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID, language string, portable bool) error {
186186
configFile := filepath.Join(checkoutPath, constants.ConfigFileName)
187187
if !fileutils.FileExists(configFile) {
188188
_, err := projectfile.Create(&projectfile.CreateParams{
@@ -192,6 +192,7 @@ func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID,
192192
Directory: checkoutPath,
193193
Language: language,
194194
Cache: cachePath,
195+
Portable: portable,
195196
})
196197
if err != nil {
197198
if osutils.IsAccessDeniedError(err) {

internal/runbits/runtime/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ func Update(
252252
if opts.Archive != nil {
253253
rtOpts = append(rtOpts, runtime.WithArchive(opts.Archive.Dir, opts.Archive.PlatformID, checkout.ArtifactExt))
254254
}
255+
if proj.IsPortable() {
256+
rtOpts = append(rtOpts, runtime.WithPortable())
257+
}
255258

256259
if err := rt.Update(buildPlan, rtHash, rtOpts...); err != nil {
257260
return nil, locale.WrapError(err, "err_packages_update_runtime_install")

internal/runners/activate/activate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) {
9595
}
9696

9797
// Perform fresh checkout
98-
pathToUse, err := r.activateCheckout.Run(params.Namespace, params.Branch, "", params.PreferredPath, false, false)
98+
pathToUse, err := r.activateCheckout.Run(params.Namespace, params.Branch, "", params.PreferredPath, false, false, false)
9999
if err != nil {
100100
return locale.WrapError(err, "err_activate_pathtouse", "Could not figure out what path to use.")
101101
}

internal/runners/checkout/checkout.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Params struct {
3838
RuntimePath string
3939
NoClone bool
4040
Force bool
41+
Portable bool
4142
}
4243

4344
type primeable interface {
@@ -121,7 +122,7 @@ func (u *Checkout) Run(params *Params) (rerr error) {
121122

122123
u.out.Notice(locale.Tr("checking_out", ns.String()))
123124

124-
projectDir, err := u.checkout.Run(ns, params.Branch, params.RuntimePath, params.PreferredPath, params.NoClone, archive != nil)
125+
projectDir, err := u.checkout.Run(ns, params.Branch, params.RuntimePath, params.PreferredPath, params.NoClone, archive != nil, params.Portable)
125126
if err != nil {
126127
return errs.Wrap(err, "Checkout failed")
127128
}

internal/runners/deploy/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (d *Deploy) install(params *Params, commitID strfmt.UUID) (rerr error) {
168168

169169
if err := checkout.CreateProjectFiles(
170170
params.Path, params.Path, params.Namespace.Owner, params.Namespace.Project,
171-
constants.DefaultBranchName, commitID.String(), "",
171+
constants.DefaultBranchName, commitID.String(), "", true,
172172
); err != nil {
173173
return errs.Wrap(err, "Could not create project files")
174174
}

pkg/project/project.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ func (p *Project) Lock() string { return p.projectfile.Lock }
255255
// Cache returns the cache information for this project
256256
func (p *Project) Cache() string { return p.projectfile.Cache }
257257

258+
func (p *Project) IsPortable() bool { return p.projectfile.Portable }
259+
258260
// Namespace returns project namespace
259261
func (p *Project) Namespace() *Namespaced {
260262
return &Namespaced{Owner: p.projectfile.Owner(), Project: p.projectfile.Name()}

pkg/projectfile/projectfile.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type Project struct {
108108
Jobs Jobs `yaml:"jobs,omitempty"`
109109
Private bool `yaml:"private,omitempty"`
110110
Cache string `yaml:"cache,omitempty"`
111+
Portable bool `yaml:"portable,omitempty"`
111112
path string // "private"
112113
parsedURL projectURL // parsed url data
113114
parsedChannel string
@@ -920,6 +921,7 @@ type CreateParams struct {
920921
path string
921922
ProjectURL string
922923
Cache string
924+
Portable bool
923925
}
924926

925927
// Create will create a new activestate.yaml with a projectURL for the given details
@@ -1019,7 +1021,7 @@ func createCustom(params *CreateParams, lang language.Language) (*Project, error
10191021
}
10201022

10211023
if params.Cache != "" {
1022-
createErr := createHostFile(params.Directory, params.Cache)
1024+
createErr := createHostFile(params.Directory, params.Cache, params.Portable)
10231025
if createErr != nil {
10241026
return nil, errs.Wrap(createErr, "Could not create cache file")
10251027
}
@@ -1028,14 +1030,15 @@ func createCustom(params *CreateParams, lang language.Language) (*Project, error
10281030
return Parse(params.path)
10291031
}
10301032

1031-
func createHostFile(filePath, cachePath string) error {
1033+
func createHostFile(filePath, cachePath string, portable bool) error {
10321034
user, err := user.Current()
10331035
if err != nil {
10341036
return errs.Wrap(err, "Could not get current user")
10351037
}
10361038

10371039
data := map[string]interface{}{
1038-
"Cache": cachePath,
1040+
"Cache": cachePath,
1041+
"Portable": portable,
10391042
}
10401043

10411044
tplName := "activestate.yaml.cache.tpl"

pkg/runtime/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ func WithPreferredLibcVersion(version string) SetOpt {
1717
return func(opts *Opts) { opts.PreferredLibcVersion = version }
1818
}
1919

20+
func WithPortable() SetOpt {
21+
return func(opts *Opts) { opts.Portable = true }
22+
}
23+
2024
func WithArchive(dir string, platformID strfmt.UUID, ext string) SetOpt {
2125
return func(opts *Opts) {
2226
opts.FromArchive = &fromArchive{dir, platformID, ext}

0 commit comments

Comments
 (0)