-
Notifications
You must be signed in to change notification settings - Fork 546
/
install.go
106 lines (93 loc) · 2.58 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (c) 2021 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Package install implements the ``gop install'' command.
package install
import (
"fmt"
"log"
"os"
"reflect"
"syscall"
"github.com/goplus/gop"
"github.com/goplus/gop/cl"
"github.com/goplus/gop/cmd/internal/base"
"github.com/goplus/gop/x/gocmd"
"github.com/goplus/gop/x/gopenv"
"github.com/goplus/gop/x/gopprojs"
"github.com/goplus/gox"
)
// gop install
var Cmd = &base.Command{
UsageLine: "gop install [-v] [packages]",
Short: "Build Go+ files and install target to GOBIN",
}
var (
flag = &Cmd.Flag
flagVerbose = flag.Bool("v", false, "print verbose information")
)
func init() {
Cmd.Run = runCmd
}
func runCmd(_ *base.Command, args []string) {
err := flag.Parse(args)
if err != nil {
log.Fatalln("parse input arguments failed:", err)
}
pattern := flag.Args()
if len(pattern) == 0 {
pattern = []string{"."}
}
projs, err := gopprojs.ParseAll(pattern...)
if err != nil {
log.Panicln("gopprojs.ParseAll:", err)
}
if *flagVerbose {
gox.SetDebug(gox.DbgFlagAll &^ gox.DbgFlagComments)
cl.SetDebug(cl.DbgFlagAll)
cl.SetDisableRecover(true)
}
gopEnv := gopenv.Get()
conf := &gop.Config{Gop: gopEnv}
confCmd := &gocmd.Config{Gop: gopEnv}
for _, proj := range projs {
install(proj, conf, confCmd)
}
}
func install(proj gopprojs.Proj, conf *gop.Config, install *gocmd.InstallConfig) {
var obj string
var err error
switch v := proj.(type) {
case *gopprojs.DirProj:
obj = v.Dir
err = gop.InstallDir(obj, conf, install)
case *gopprojs.PkgPathProj:
obj = v.Path
err = gop.InstallPkgPath("", v.Path, conf, install)
case *gopprojs.FilesProj:
err = gop.InstallFiles(v.Files, conf, install)
default:
log.Panicln("`gop install` doesn't support", reflect.TypeOf(v))
}
if err == syscall.ENOENT {
fmt.Fprintf(os.Stderr, "gop install %v: not found\n", obj)
} else if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
return
}
os.Exit(1)
}
// -----------------------------------------------------------------------------