@@ -31,6 +31,7 @@ import (
31
31
type Solidity struct {
32
32
Path , Version , FullVersion string
33
33
Major , Minor , Patch int
34
+ ExtraAllowedPath []string
34
35
}
35
36
36
37
// --combined-output format
@@ -58,11 +59,19 @@ type solcOutputV8 struct {
58
59
Version string
59
60
}
60
61
62
+ func (s * Solidity ) allowedPaths () string {
63
+ paths := []string {"." , "./" , "../" } // default to support relative paths
64
+ if len (s .ExtraAllowedPath ) > 0 {
65
+ paths = append (paths , s .ExtraAllowedPath ... )
66
+ }
67
+ return strings .Join (paths , ", " )
68
+ }
69
+
61
70
func (s * Solidity ) makeArgs () []string {
62
71
p := []string {
63
72
"--combined-json" , "bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc" ,
64
- "--optimize" , // code optimizer switched on
65
- "--allow-paths" , "., ./, ../" , // default to support relative paths
73
+ "--optimize" , // code optimizer switched on
74
+ "--allow-paths" , s . allowedPaths (),
66
75
}
67
76
if s .Major > 0 || s .Minor > 4 || s .Patch > 6 {
68
77
p [1 ] += ",metadata,hashes"
@@ -108,22 +117,33 @@ func CompileSolidityString(solc, source string) (map[string]*Contract, error) {
108
117
if err != nil {
109
118
return nil , err
110
119
}
111
- args := append (s .makeArgs (), "--" )
112
- cmd := exec .Command (s .Path , append (args , "-" )... )
113
- cmd .Stdin = strings .NewReader (source )
114
- return s .run (cmd , source )
120
+ return s .CompileSource (source )
115
121
}
116
122
117
123
// CompileSolidity compiles all given Solidity source files.
118
124
func CompileSolidity (solc string , sourcefiles ... string ) (map [string ]* Contract , error ) {
119
125
if len (sourcefiles ) == 0 {
120
126
return nil , errors .New ("solc: no source files" )
121
127
}
122
- source , err := slurpFiles ( sourcefiles )
128
+ s , err := SolidityVersion ( solc )
123
129
if err != nil {
124
130
return nil , err
125
131
}
126
- s , err := SolidityVersion (solc )
132
+
133
+ return s .CompileFiles (sourcefiles ... )
134
+ }
135
+
136
+ // CompileSource builds and returns all the contracts contained within a source string.
137
+ func (s * Solidity ) CompileSource (source string ) (map [string ]* Contract , error ) {
138
+ args := append (s .makeArgs (), "--" )
139
+ cmd := exec .Command (s .Path , append (args , "-" )... )
140
+ cmd .Stdin = strings .NewReader (source )
141
+ return s .run (cmd , source )
142
+ }
143
+
144
+ // CompileFiles compiles all given Solidity source files.
145
+ func (s * Solidity ) CompileFiles (sourcefiles ... string ) (map [string ]* Contract , error ) {
146
+ source , err := slurpFiles (sourcefiles )
127
147
if err != nil {
128
148
return nil , err
129
149
}
0 commit comments