-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBuild.wls
184 lines (140 loc) · 4.42 KB
/
Build.wls
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env wolframscript
(* ::Package:: *)
(* ::Section:: *)
(*Build script*)
(* ::Text:: *)
(*This script builds the (installation) paclet file from source code.*)
(* ::Subsection:: *)
(*Git functions*)
(* Get human readable description of current state of repository.
For more info see: https://git-scm.com/docs/git-describe *)
getGitRevision[dir_]:=Module[
{description},
SetDirectory[dir];
description=First[
ReadList["!git describe --long --tags --dirty --always",String],
Return[$Failed]
];
ResetDirectory[];
description
];
(* Get repository commit count. It is useful to mark "build number". *)
getGitCommitCount[dir_]:=Module[
{value},
SetDirectory[dir];
value=First[
ReadList["!git rev-list --count HEAD",Number],
Return[$Failed]
];
ResetDirectory[];
value
];
(* ::Subsection:: *)
(*Build procedure*)
(* ::Subsubsection:: *)
(*Initialization*)
$name="FindBounce";
(* Get the distribution directory by using this notebook directory. *)
$root=If[$Notebooks,NotebookDirectory[],Directory[]];
(* Directory of main source code. *)
$source=FileNameJoin[{$root,$name}];
(* Construct the target directory from this notebooks base directory. *)
$target=FileNameJoin[{$root,"build",$name}];
(* This should support text based interface with "wolframscript" mechanism and
"wolfram -script" mechanism. See tutorial/WolframLanguageScripts for more info. *)
$args=Join[$ScriptCommandLine,$CommandLine];
$helpMessage=("
This script converts package source code to installation .paclet file.
Script options:
--install Install just created paclet
");
(* Help message is printed every time. *)
Print[$helpMessage];
If[$VersionNumber<10.0, Print["Mathematica 10.0 or later required."];Quit[1]];
(* Verify that we have git *)
With[
{rg=RunProcess[{"git","--version"}]},
If[
rg===$Failed||rg["ExitCode"]!=0,
Print["git software is not available."];Quit[1]
]
];
If[
Not@DirectoryQ[$target],
CreateDirectory[$target,CreateIntermediateDirectories->True]
];
(* ::Subsubsection:: *)
(*Copy files*)
Module[
{docDir,docFiles,lastModTime},
(* Delete old and copy the new source directories. Documentation is build separately. *)
Map[
(If[
FileExistsQ[FileNameJoin[{$target,#}]],
DeleteDirectory[FileNameJoin[{$target,#}],DeleteContents->True]
];
CopyDirectory[
FileNameJoin[{$source,#}],
FileNameJoin[{$target,#}]
])&,
{"FrontEnd","Kernel"}
];
(* Documentation should be built with a separate procedure before. *)
docDir=FileNameJoin[{$target,"Documentation"}];
docFiles=FileNames["*.nb",docDir,Infinity];
If[
docFiles=!={},
lastModTime=Min[FileDate[#,"Modification"]&/@docFiles];
(* Check if all notebooks have been created at least one hour ago. *)
If[
(AbsoluteTime@Now-AbsoluteTime@lastModTime)/3600. > 1.,
Print[" Warning! Documentation notebooks may be outdated. Earliest change ",DateString@lastModTime]
],
Print[" Warning! Documentation directory is missing in build folder."]
];
];
Module[
{original,modified,noCommits,revision},
original=List@@Import[FileNameJoin[{$source,"PacletInfo.m"}]];
revision=getGitRevision[$root];
(* Number of commits cannot be appended to version number because otherwise loading
from development directory with PacletDirectoryAdd procedure is broken. *)
modified=Paclet@@Normal[
Merge[{Association@@original,<|"UUID"->revision|>},Last]
];
If[
StringContainsQ[revision,"dirty"],
Print[" Warning! Repository contains uncommited changes."]
];
(* Overwrite "PacletInfo.m" with updated contents. *)
Export[
FileNameJoin[{$target,"PacletInfo.m"}],
modified,
"Comments"->{"Paclet Info File","Created on "<>DateString[]}
];
];
(* ::Subsubsection:: *)
(*Create .paclet file*)
Module[
{path,buildNo,successQ},
buildNo=getGitCommitCount[$root];
Print[" Build number: ",buildNo];
(* Change into the build directory and create the paclet. *)
SetDirectory@FileNameJoin[{$root,"build"}];
path=Quiet[PackPaclet[$name],PackPaclet::expobs];
ResetDirectory[];
successQ=TrueQ[(AbsoluteTime@Now-AbsoluteTime@FileDate@path)<1.];
If[
successQ&&MemberQ[$args,"--install"],
(* Uninstall older versions first. *)
Quiet@PacletUninstall[$name];
(* Option ForceVersionInstall appears in 12.1 *)
PacletInstall[path,ForceVersionInstall->True];
Quiet[RebuildPacletData[], RebuildPacletData::expobs];
];
If[
successQ,
Print[" ",FileNameTake[path]," built succesfully."];Quit[0],
Print[" Paclet build failed!"];Quit[1]
]
]