Skip to content

Commit a53ea81

Browse files
committed
Update build_plugins.fsx
1 parent 4bff84d commit a53ea81

1 file changed

Lines changed: 83 additions & 49 deletions

File tree

build_plugins.fsx

Lines changed: 83 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,133 @@
22
open System.IO
33
let isWindows = System.OperatingSystem.IsWindows()
44
let isDebugBuild = isWindows
5+
56
let run cmd args =
67
printfn "Exec %s %A" cmd args
78
let psi = cmd |> System.Diagnostics.ProcessStartInfo
9+
810
for arg in args do
911
psi.ArgumentList.Add arg
10-
psi.UseShellExecute <- false//isWindows
12+
13+
psi.UseShellExecute <- false //isWindows
1114
psi.CreateNoWindow <- false
1215
let p = System.Diagnostics.Process.Start psi
1316
p.WaitForExit()
1417
p.ExitCode
18+
1519
let cd = __SOURCE_DIRECTORY__
1620
let src = Path.Combine(cd, "src")
1721
let output = Path.Combine(cd, "bin")
18-
let dotnetBuild src output =
19-
let extraArgs = if isDebugBuild then ["-c"; "Debug"] else []
20-
let exitCode = run "dotnet" (["build"; src; "-o"; output]@extraArgs)
22+
23+
let dotnetBuild src output =
24+
let extraArgs = if isDebugBuild then [ "-c"; "Debug" ] else []
25+
let exitCode = run "dotnet" ([ "build"; src; "-o"; output ] @ extraArgs)
26+
2127
if exitCode <> 0 then
2228
printfn "Command: dotnet build %s -o %s %s" src output (System.String.Join(" ", extraArgs))
2329
failwithf "Build failed for %s" src
2430
//delete output folder
25-
if output|>Directory.Exists then
26-
Directory.Delete(output,true)
27-
let projs = Directory.GetFiles(src, "*.csproj", SearchOption.AllDirectories)
28-
|> Array.map (fun p -> Path.GetRelativePath(cd,p))
29-
let coreFileNameList=
31+
if output |> Directory.Exists then
32+
Directory.Delete(output, true)
33+
34+
let projs =
35+
Directory.GetFiles(src, "*.csproj", SearchOption.AllDirectories)
36+
|> Array.map (fun p -> Path.GetRelativePath(cd, p))
37+
38+
let coreFileNameList =
3039
let projName = "HuaJiBot.NET"
3140
let outputDir = Path.Combine(output, projName)
3241
//run "dotnet" ["build"; Path.Combine("src",projName,"HuaJiBot.NET.csproj"); "-o"; outputDir]
33-
dotnetBuild (Path.Combine("src",projName,"HuaJiBot.NET.csproj")) outputDir
34-
let fileNameList=
35-
outputDir
36-
|> Directory.GetFiles
37-
|> Array.map (fun p -> Path.GetFileName p)
38-
Directory.Delete(outputDir,true)
42+
dotnetBuild (Path.Combine("src", projName, "HuaJiBot.NET.csproj")) outputDir
43+
44+
let fileNameList =
45+
outputDir |> Directory.GetFiles |> Array.map (fun p -> Path.GetFileName p)
46+
47+
Directory.Delete(outputDir, true)
3948
fileNameList
4049

41-
let buidActions = [
42-
for proj in projs do
43-
printfn "Processing %s" proj
44-
let filename = Path.GetFileName proj
45-
if filename.StartsWith "HuaJiBot.NET.Plugin" then
46-
async {
47-
let projName = Path.GetFileNameWithoutExtension proj
48-
let outputDir = Path.Combine(output, projName)
49-
if outputDir|>Directory.Exists|>not then outputDir|>Directory.CreateDirectory|>ignore
50-
printfn "Building %s" filename
51-
//let exitCode = run "dotnet" ["build"; proj; "-o"; outputDir]
52-
dotnetBuild proj outputDir
53-
//delete files which already included in executable and no need to copy as dependency
54-
for file in coreFileNameList do
55-
let coreFile = Path.Combine(outputDir, file)
56-
if coreFile|>File.Exists then
57-
File.Delete coreFile
58-
printfn "Delete %s" coreFile
59-
printfn "Build %s done" filename
60-
return outputDir
61-
}
62-
]
63-
let binDirs=
50+
let buidActions =
51+
[ for proj in projs do
52+
printfn "Processing %s" proj
53+
let filename = Path.GetFileName proj
54+
55+
if filename.StartsWith "HuaJiBot.NET.Plugin" then
56+
async {
57+
let projName = Path.GetFileNameWithoutExtension proj
58+
let outputDir = Path.Combine(output, projName)
59+
60+
if outputDir |> Directory.Exists |> not then
61+
outputDir |> Directory.CreateDirectory |> ignore
62+
63+
printfn "Building %s" filename
64+
//let exitCode = run "dotnet" ["build"; proj; "-o"; outputDir]
65+
dotnetBuild proj outputDir
66+
//delete files which already included in executable and no need to copy as dependency
67+
for file in coreFileNameList do
68+
let coreFile = Path.Combine(outputDir, file)
69+
70+
if coreFile |> File.Exists then
71+
File.Delete coreFile
72+
printfn "Delete %s" coreFile
73+
74+
printfn "Build %s done" filename
75+
return outputDir
76+
} ]
77+
78+
let binDirs =
6479
if isWindows then
65-
[for dir in buidActions|>Async.Parallel|>Async.RunSynchronously do dir]
66-
else
67-
[for action in buidActions do action|>Async.RunSynchronously]
80+
[ for dir in buidActions |> Async.Parallel |> Async.RunSynchronously do
81+
dir ]
82+
else
83+
[ for action in buidActions do
84+
action |> Async.RunSynchronously ]
6885
//resort files
6986
let pluginDir = Path.Combine(output, "plugins")
70-
if pluginDir|>Directory.Exists|>not then pluginDir|>Directory.CreateDirectory|>ignore
87+
88+
if pluginDir |> Directory.Exists |> not then
89+
pluginDir |> Directory.CreateDirectory |> ignore
90+
7191
let libsDir = Path.Combine(pluginDir, "libs")
72-
if libsDir|>Directory.Exists|>not then libsDir|>Directory.CreateDirectory|>ignore
92+
93+
if libsDir |> Directory.Exists |> not then
94+
libsDir |> Directory.CreateDirectory |> ignore
95+
7396
for dir in binDirs do
74-
let files = Array.concat [Directory.GetFiles(dir,"*.dll") ;Directory.GetFiles(dir,"*.pdb")]
97+
let files =
98+
Array.concat [ Directory.GetFiles(dir, "*.dll"); Directory.GetFiles(dir, "*.pdb") ]
99+
75100
for file in files do
76101
let fileName = Path.GetFileName file
102+
77103
if fileName.StartsWith "HuaJiBot.NET.Plugin" then
78104
let dest = Path.Combine(pluginDir, fileName)
79105
File.Copy(file, dest, true)
80106
printfn "Copy %s to %s" file dest
81-
else
107+
else if
108+
// skip *.Abstractions.dll
109+
fileName.EndsWith "Abstractions.dll" |> not
110+
then
82111
let dest = Path.Combine(libsDir, fileName)
83112
File.Copy(file, dest, true)
84113
printfn "Copy %s to %s" file dest
85114
//remove original output
86115
for dir in binDirs do
87-
Directory.Delete(dir,true)
116+
Directory.Delete(dir, true)
88117
printfn "Delete %s" dir
89118
//compress
90119
open SharpCompress.Archives
91120
open SharpCompress.Archives.Zip
92121
open SharpCompress.Common
93-
let compress()=
122+
123+
let compress () =
94124
let zipFile = Path.Combine(cd, "HuaJiBot.NET.Plugins.zip")
95-
if zipFile|>File.Exists then File.Delete zipFile
125+
126+
if zipFile |> File.Exists then
127+
File.Delete zipFile
128+
96129
use archive = ZipArchive.CreateArchive()
97130
archive.AddAllFromDirectory output
98131
archive.SaveTo(zipFile, CompressionType.Deflate) |> ignore
132+
99133
if isWindows then
100-
compress()
134+
compress ()

0 commit comments

Comments
 (0)