-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBuild.wls
137 lines (110 loc) · 3.61 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
#!/usr/bin/env wolframscript
(* ::Package:: *)
(* ::Text:: *)
(*This script builds the ImportMesh-X.Y.Z.paclet. The creation is two step process. First the source code and other files need to be copied alongside the documentation and then the paclet file is created. Previously documentation should be generated separately with Workbench as outlined in the README.md file.*)
(* ::Subsubsection:: *)
(*Git functions*)
getGitRevision[dir_]:=Module[{description},
SetDirectory[dir];
(* For meaning of this see: https://git-scm.com/docs/git-describe *)
description=First[
ReadList["!git describe --long --tags --dirty --always",String],
Return[$Failed]
];
ResetDirectory[];
description
];
getGitCommitCount[dir_]:=Module[{value},
SetDirectory[dir];
(* For meaning of this see: https://git-scm.com/docs/git-describe *)
value=First[
ReadList["!git rev-list --count HEAD",Number],
Return[$Failed]
];
ResetDirectory[];
value
];
(* ::Subsubsection:: *)
(*Build procedure*)
$name="ImportMesh";
(* Get the distribution directory by using this notebook\[CloseCurlyQuote]s directory. *)
$rootDir=If[$Notebooks,NotebookDirectory[],Directory[]];
$source=FileNameJoin[{$rootDir,$name}];
(* Construct the target directory from this notebooks base directory. *)
$target=FileNameJoin[{$rootDir,"build",$name}];
$helpMessage=(" Script to build the paclet and install it.
Usage: Build.wls [options]
Options:
-h, --help Output usage information
-r, --release Build public release");
Module[
{directories},
If[
MemberQ[Rest@$ScriptCommandLine,"/?"|"-h"|"--help"],
Print[$helpMessage];Quit[1]
];
If[
Not@DirectoryQ[$target],
CreateDirectory[$target,CreateIntermediateDirectories->True]
];
(* Copy neccesseary files from the source to the target directory. *)
Map[
CopyFile[
FileNameJoin[{$source,#}],
FileNameJoin[{$target,#}],
OverwriteTarget->True
]&,
{"ImportMesh.wl","PacletInfo.m"}
];
(* Delete old and copy the new source directories.
"Documentation" directory is already created by documentation build procedure. *)
directories={"Kernel"};
Map[
If[
FileExistsQ[FileNameJoin[{$target,#}]],
DeleteDirectory[FileNameJoin[{$target,#}],DeleteContents->True]
]&,
directories
];
Map[
CopyDirectory[FileNameJoin[{$source,#}],FileNameJoin[{$target,#}]]&,
directories
];
];
Module[
{original, modified,noCommits,revision,internalQ},
original=Import[FileNameJoin[{$source,"PacletInfo.m"}]];
noCommits=getGitCommitCount[$rootDir];
revision=getGitRevision[$rootDir];
internalQ=Not@MemberQ[Rest@$ScriptCommandLine,"-r"|"--release"];
(* Description of git repository (git describe ...) returns a string that cannot
be used as BuildNumber because only integers are accepted.
Otherwise PackPaclet returns $Failed and procedure fails. Instead now commit count is used. *)
modified=Fold[
Insert[#1,#2,4]&,
original,
{Internal->internalQ,BuildNumber->noCommits,"Hash"->revision}
];
Export[
FileNameJoin[{$target,"PacletInfo.m"}],
modified,
"Comments"->{"Paclet Info File","Created on "<>DateString[]}
];
];
Module[
{pacletPath,newPaclet},
Needs["PacletManager`"];
(* Change into the build directory and create the paclet. *)
SetDirectory[FileNameJoin[{$rootDir,"build"}]];
pacletPath=PackPaclet[$name];
ResetDirectory[];
(*Uninstall a possibly old version. *)
If[PacletFind[$name]=!={},PacletUninstall[$name]];
newPaclet=PacletInstall[pacletPath];
RebuildPacletData[];
If[
Length@PacletFind["HeatTrans"]===1,
Print[" ",FileNameTake[pacletPath]," built and installed succesfully."];Quit[0],
Print["Paclet build failed."];Quit[1]
]
];