forked from sifive/wake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.wake
158 lines (143 loc) · 6.02 KB
/
build.wake
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
# Copyright 2019 SiFive, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You should have received a copy of LICENSE.Apache2 along with
# this software. If not, you may obtain a copy at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
package build_wake
from wake import _
# Useful build variants (arguments to all)
def toVariant = match _
"default" = Pass (Pair "native-cpp11-release" "native-c11-release")
"static" = Pass (Pair "native-cpp11-static" "native-c11-static")
"debug" = Pass (Pair "native-cpp11-debug" "native-c11-debug")
"wasm" = Pass (Pair "wasm-cpp11-release" "wasm-c11-release")
s = Fail "Unknown build target ({s})".makeError
export def build: List String => Result String Error = match _
"tarball", Nil = tarball Unit | rmap (\_ "TARBALL")
kind, Nil =
require Pass variant = toVariant kind
all variant | rmap (\_ "BUILD")
_ = Fail "no target specified (try: build default/debug/tarball)".makeError
export def install: List String => Result String Error = match _
dest, kind, Nil = doInstall (in cwd dest) kind | rmap (\_ "INSTALL")
dest, Nil = doInstall (in cwd dest) "default" | rmap (\_ "INSTALL")
_ = Fail "no directory specified (try: install /opt/local)".makeError
# Build all wake targets
def targets =
def allPlatforms = buildWake, buildFuse, buildFuseDaemon, buildShim, buildPreload, buildPrelib, buildBSP, buildLSP, Nil
def linuxOnly = buildWakeBox, Nil
match sysname
"Linux" = allPlatforms ++ linuxOnly
_ = allPlatforms
def all variant =
require Pass x =
map (_ variant) targets
| findFail
Pass (flatten x)
# Install wake into a target location
def doInstall dest kind =
require Pass variant = toVariant kind
def datfiles = sources "{here}/share" `.*`
def binfilesResult = all variant
def releaseBin exe = installAs "{dest}/{replace `\.[^.]*$` '' exe.getPathName}" exe
def datinstall = map (installIn dest ".") datfiles
def readme = installIn "{dest}/share/doc/wake" "." (source "README.md")
require Pass binfiles = binfilesResult
def bininstall = map releaseBin binfiles
def outputs = readme, bininstall ++ datinstall
findFailFn getPathResult outputs
# Replace @VERSION@ with 'release'
def setVersion release file =
def in = source "{file}.in"
def script = "%
set -e
sed "s/@VERSION@/%{release}/g" "%{in.getPathName}" > "%{file}.tmp"
mv "%{file}.tmp" "%{file}"
%"
shellJob script (in, Nil) | getJobOutput
# Create a release tarball
def tarball Unit =
def releaseResult = buildAs Unit
def timeResult = buildOn Unit
require Pass release = releaseResult
require Pass time = timeResult
# Create debian + RedHat package files
def changelog = setVersion release "debian/changelog"
def spec = setVersion release "wake.spec"
# Identify those sources files to include in the tarball
def srcs =
sources "." `.*`
| filter (! matches `(debian/|wake.spec).*` _.getPathName) # omit packaging files
| filter (! matches `(\.circleci/|\.github/).*|\.dockerignore` _.getPathName) # omit CI files
| filter (! matches `(.*/)*\.gitignore` _.getPathName) # omit git files
def Pair testPaths wakePaths = splitBy (matches `tests/.*` _.getPathName) srcs
def wakeSourcesString =
wakePaths
| map (_.getPathName.format)
| foldr (_, ",\n ", _) Nil
| cat
def testSourcesString =
testPaths
| map (getPathName _ | format | replace `^"tests/` '"{here}/')
| foldr (_, ",\n ", _) Nil
| cat
def manifestStr = "%
# Generated by 'wake tarball Unit':
package build_wake
from wake import source , Nil
publish releaseAs = '%{release}', Nil
publish releaseOn = '%{time}', Nil
publish source =
%{wakeSourcesString}Nil
%"
def testsManifestStr = "%
# Generated by 'wake tarball Unit':
package test_wake
from wake import source , Nil
publish source =
%{testSourcesString}Nil
%"
# Create a manifest which describes the release and source files
def manifest = write "manifest.wake" manifestStr
def testManifest = write "tests/manifest.wake" testsManifestStr
# Execute tar to create a tarball of manifest + sources
def tarball =
def cmd =
def gnutar = which "gnutar"
def tar = if gnutar ==* "gnutar" then which "tar" else gnutar
def files = map getPathName (manifest, testManifest, spec, srcs) | sortBy (_<*_)
tar, "--mtime={time}", "--transform=s@^@wake-{release}/@",
"--owner=0", "--group=0", "--numeric-owner", "-cJf",
"wake_{release}.tar.xz", files
job cmd (manifest, testManifest, spec, srcs)
| getJobOutput
findFailFn getPathResult (tarball, changelog, Nil)
export def static _: Result Path Error =
def filesResult = doInstall "tmp" "static"
def releaseResult = buildAs Unit
def timeResult = buildOn Unit
require Pass release = releaseResult
require Pass time = timeResult
require Pass files = filesResult
def cmd =
which "tar", "--mtime={time}", "--transform=s@^tmp/@wake-{release}/@",
"--owner=0", "--group=0", "--numeric-owner", "-cJf",
"wake-static_{release}.tar.xz", map getPathName files | sortBy (_<*_)
job cmd files
| getJobOutput
| getPathResult
from test_wake import topic wakeTestBinary
publish wakeTestBinary = defaultWake, Nil
def defaultWake Unit =
require Pass wakeVisible =
doInstall "tmp" "default"
Pass (Pair "tmp/bin/wake" wakeVisible)