| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package isolate | 5 package isolate |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "errors" | 10 "errors" |
| 11 "io/ioutil" | 11 "io/ioutil" |
| 12 "log" | 12 "log" |
| 13 "os" | 13 "os" |
| 14 "path/filepath" | 14 "path/filepath" |
| 15 "regexp" | 15 "regexp" |
| 16 "sort" | 16 "sort" |
| 17 "strings" | 17 "strings" |
| 18 | 18 |
| 19 "github.com/luci/luci-go/client/archiver" | 19 "github.com/luci/luci-go/client/archiver" |
| 20 » "github.com/luci/luci-go/client/internal/common" | 20 » "github.com/luci/luci-go/common/flag/stringlistflag" |
| 21 "github.com/luci/luci-go/common/flag/stringmapflag" | 21 "github.com/luci/luci-go/common/flag/stringmapflag" |
| 22 "github.com/luci/luci-go/common/isolated" | 22 "github.com/luci/luci-go/common/isolated" |
| 23 "github.com/luci/luci-go/common/isolatedclient" | 23 "github.com/luci/luci-go/common/isolatedclient" |
| 24 "github.com/luci/luci-go/common/runtime/tracer" | 24 "github.com/luci/luci-go/common/runtime/tracer" |
| 25 ) | 25 ) |
| 26 | 26 |
| 27 // IsolatedGenJSONVersion is used in the batcharchive json format. | 27 // IsolatedGenJSONVersion is used in the batcharchive json format. |
| 28 // | 28 // |
| 29 // TODO(tandrii): Migrate to batch_archive.go. | 29 // TODO(tandrii): Migrate to batch_archive.go. |
| 30 const IsolatedGenJSONVersion = 1 | 30 const IsolatedGenJSONVersion = 1 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 43 // Tree to be isolated. | 43 // Tree to be isolated. |
| 44 type Tree struct { | 44 type Tree struct { |
| 45 Cwd string | 45 Cwd string |
| 46 Opts ArchiveOptions | 46 Opts ArchiveOptions |
| 47 } | 47 } |
| 48 | 48 |
| 49 // ArchiveOptions for achiving trees. | 49 // ArchiveOptions for achiving trees. |
| 50 type ArchiveOptions struct { | 50 type ArchiveOptions struct { |
| 51 Isolate string `json:"isolate"` | 51 Isolate string `json:"isolate"` |
| 52 Isolated string `json:"isolated"` | 52 Isolated string `json:"isolated"` |
| 53 » Blacklist common.Strings `json:"blacklist"` | 53 » Blacklist stringlistflag.Flag `json:"blacklist"` |
| 54 PathVariables stringmapflag.Value `json:"path_variables"` | 54 PathVariables stringmapflag.Value `json:"path_variables"` |
| 55 ExtraVariables stringmapflag.Value `json:"extra_variables"` | 55 ExtraVariables stringmapflag.Value `json:"extra_variables"` |
| 56 ConfigVariables stringmapflag.Value `json:"config_variables"` | 56 ConfigVariables stringmapflag.Value `json:"config_variables"` |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Init initializes with non-nil values. | 59 // Init initializes with non-nil values. |
| 60 func (a *ArchiveOptions) Init() { | 60 func (a *ArchiveOptions) Init() { |
| 61 » a.Blacklist = common.Strings{} | 61 » a.Blacklist = stringlistflag.Flag{} |
| 62 a.PathVariables = map[string]string{} | 62 a.PathVariables = map[string]string{} |
| 63 » if common.IsWindows() { | 63 » if IsWindows() { |
| 64 a.PathVariables["EXECUTABLE_SUFFIX"] = ".exe" | 64 a.PathVariables["EXECUTABLE_SUFFIX"] = ".exe" |
| 65 } else { | 65 } else { |
| 66 a.PathVariables["EXECUTABLE_SUFFIX"] = "" | 66 a.PathVariables["EXECUTABLE_SUFFIX"] = "" |
| 67 } | 67 } |
| 68 a.ExtraVariables = map[string]string{} | 68 a.ExtraVariables = map[string]string{} |
| 69 a.ConfigVariables = map[string]string{} | 69 a.ConfigVariables = map[string]string{} |
| 70 } | 70 } |
| 71 | 71 |
| 72 // PostProcess post-processes the flags to fix any compatibility issue. | 72 // PostProcess post-processes the flags to fix any compatibility issue. |
| 73 func (a *ArchiveOptions) PostProcess(cwd string) { | 73 func (a *ArchiveOptions) PostProcess(cwd string) { |
| 74 // Set default blacklist only if none is set. | 74 // Set default blacklist only if none is set. |
| 75 if len(a.Blacklist) == 0 { | 75 if len(a.Blacklist) == 0 { |
| 76 // This cannot be generalized as ".*" as there is known use that
require | 76 // This cannot be generalized as ".*" as there is known use that
require |
| 77 // a ".pki" directory to be mapped. | 77 // a ".pki" directory to be mapped. |
| 78 » » a.Blacklist = common.Strings{ | 78 » » a.Blacklist = stringlistflag.Flag{ |
| 79 // Temporary python files. | 79 // Temporary python files. |
| 80 "*.pyc", | 80 "*.pyc", |
| 81 // Temporary vim files. | 81 // Temporary vim files. |
| 82 "*.swp", | 82 "*.swp", |
| 83 ".git", | 83 ".git", |
| 84 ".hg", | 84 ".hg", |
| 85 ".svn", | 85 ".svn", |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 if !filepath.IsAbs(a.Isolate) { | 88 if !filepath.IsAbs(a.Isolate) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 raw := &bytes.Buffer{} | 319 raw := &bytes.Buffer{} |
| 320 if err = json.NewEncoder(raw).Encode(i); err != nil { | 320 if err = json.NewEncoder(raw).Encode(i); err != nil { |
| 321 return nil, err | 321 return nil, err |
| 322 } | 322 } |
| 323 | 323 |
| 324 if err := ioutil.WriteFile(opts.Isolated, raw.Bytes(), 0644); err != nil
{ | 324 if err := ioutil.WriteFile(opts.Isolated, raw.Bytes(), 0644); err != nil
{ |
| 325 return nil, err | 325 return nil, err |
| 326 } | 326 } |
| 327 return arch.Push(displayName, isolatedclient.NewBytesSource(raw.Bytes())
, 0), nil | 327 return arch.Push(displayName, isolatedclient.NewBytesSource(raw.Bytes())
, 0), nil |
| 328 } | 328 } |
| OLD | NEW |