@@ -5,14 +5,19 @@ import (
55 "fmt"
66 "io"
77 "os"
8+ "path"
89 "path/filepath"
10+ "runtime"
11+ "strings"
912)
1013
1114// DepConfig defines the source and destination directories for a dependency
1215type DepConfig struct {
1316 Name string // Name of the dependency (for logging)
1417 SrcDir string // Source directory (relative to project root)
1518 DstDir string // Destination directory (relative to output base directory)
19+ // Blacklist is an optional per-dependency map of OS -> filename patterns to skip.
20+ Blacklist map [string ][]string
1621}
1722
1823// Dependencies to copy. Add new entries here to copy additional dependencies.
@@ -22,6 +27,23 @@ var deps = []DepConfig{
2227 Name : "MaaFramework" ,
2328 SrcDir : "deps/MaaFramework/bin" ,
2429 DstDir : "lib" ,
30+ Blacklist : map [string ][]string {
31+ "windows" : {
32+ "MaaNode.node" ,
33+ "MaaNodeServer.node" ,
34+ "MaaPiCli.exe" ,
35+ },
36+ "linux" : {
37+ "MaaNode.node" ,
38+ "MaaNodeServer.node" ,
39+ "MaaPiCli" ,
40+ },
41+ "darwin" : {
42+ "MaaNode.node" ,
43+ "MaaNodeServer.node" ,
44+ "MaaPiCli" ,
45+ },
46+ },
2547 },
2648 {
2749 Name : "MaaAgentBinary" ,
4062 forceFlag = flag .Bool ("f" , false , "Force copy all files even if they exist" )
4163 dirFlag = flag .String ("C" , "" , "Change to directory before running (project root)" )
4264 outputFlag = flag .String ("o" , "build/bin" , "Output base directory for dependencies" )
65+ // Target OS for blacklist matching. Defaults to current GOOS, can be overridden.
66+ targetOSFlag = flag .String ("os" , runtime .GOOS , "Target OS for blacklist (defaults to current GOOS)" )
4367)
4468
69+ // isBlacklisted checks whether the given relative path matches any pattern for the
70+ // selected target OS.
71+ //
72+ // Matching rules:
73+ // All patterns are matched against the relative path from the dependency source directory.
74+ // This is similar to .gitignore behavior with a leading slash (anchored to root).
75+ //
76+ // Examples:
77+ // - "foo.dll": Matches "foo.dll" in the root, but NOT "bin/foo.dll"
78+ // - "bin/foo.dll": Matches "bin/foo.dll"
79+ // - "*.pdb": Matches any .pdb file in the root directory only
80+ func isBlacklisted (relPath , targetOS string , depBlacklist map [string ][]string ) bool {
81+ if depBlacklist == nil {
82+ return false
83+ }
84+ patterns := depBlacklist [targetOS ]
85+ if len (patterns ) == 0 {
86+ return false
87+ }
88+
89+ // Normalize to forward slashes for consistent matching
90+ relPath = filepath .ToSlash (relPath )
91+
92+ for _ , p := range patterns {
93+ // Allow patterns starting with / to anchor to root explicitly
94+ // (though all patterns are implicitly anchored to root in this simplified version)
95+ pattern := strings .TrimPrefix (p , "/" )
96+
97+ if matched , _ := path .Match (pattern , relPath ); matched {
98+ return true
99+ }
100+ }
101+ return false
102+ }
103+
45104func main () {
46105 flag .Parse ()
47106
@@ -85,8 +144,8 @@ func main() {
85144 continue
86145 }
87146
88- // Copy directory contents
89- copyDir (srcDir , dstDir , totalStats )
147+ // Copy directory contents (pass DepConfig so we can use per-dep blacklist)
148+ copyDir (srcDir , dstDir , "." , dep , totalStats )
90149 }
91150
92151 fmt .Printf ("Done: %d copied, %d skipped (exists), %d errors\n " , totalStats .copied , totalStats .skipped , len (totalStats .errors ))
@@ -106,8 +165,9 @@ type copyStats struct {
106165 errors []string
107166}
108167
109- // copyDir recursively copies directory contents
110- func copyDir (src , dst string , stats * copyStats ) {
168+ // copyDir recursively copies directory contents. Accepts DepConfig so per-dep
169+ // blacklist rules can be applied.
170+ func copyDir (src , dst , relBase string , dep DepConfig , stats * copyStats ) {
111171 entries , err := os .ReadDir (src )
112172 if err != nil {
113173 errMsg := fmt .Sprintf ("failed to read directory %s: %v" , src , err )
@@ -117,6 +177,16 @@ func copyDir(src, dst string, stats *copyStats) {
117177 }
118178
119179 for _ , entry := range entries {
180+ relPath := filepath .Join (relBase , entry .Name ())
181+
182+ // Check blacklist for target OS
183+ targetOS := * targetOSFlag
184+ if isBlacklisted (relPath , targetOS , dep .Blacklist ) {
185+ fmt .Printf ("Blacklisted: %s (skipped for %s)\n " , relPath , targetOS )
186+ stats .skipped ++
187+ continue
188+ }
189+
120190 srcPath := filepath .Join (src , entry .Name ())
121191 dstPath := filepath .Join (dst , entry .Name ())
122192
@@ -129,7 +199,7 @@ func copyDir(src, dst string, stats *copyStats) {
129199 continue
130200 }
131201 // Recursively copy subdirectory
132- copyDir (srcPath , dstPath , stats )
202+ copyDir (srcPath , dstPath , relPath , dep , stats )
133203 } else {
134204 // Skip if file exists and not force mode
135205 if ! * forceFlag {
0 commit comments