-
Notifications
You must be signed in to change notification settings - Fork 2
/
bootstrap-package.sh
executable file
·152 lines (137 loc) · 3.66 KB
/
bootstrap-package.sh
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
#! /bin/bash
# Taken from https://github.com/jordwalke/pesy/blob/c348c750f1b5a61527d78cfc150ef628c03d51b7/pesy-create.sh#L14
#usage: camelcasify "some_stringHere" -> "some-string-here"
#usage: camelcasify "domHTML" -> "dom-html"
#usage: camelcasify "domHtML" -> "dom-ht-ml"
#usage: camelcasify "dom-HTML" -> "dom-html"
function lowerHyphenate(){
OUTPUT=""
i=0
prevWasUpper="true" # Causes leading uppercase
while ([ $i -lt ${#1} ]) do
CUR=${1:$i:1}
case $uppers in
*$CUR*)
CUR=${uppers%$CUR*};
if [[ "${prevWasUpper}" == "false" ]]; then
OUTPUT="${OUTPUT}-${lowers:${#CUR}:1}"
else
# No hyphen
OUTPUT="${OUTPUT}${lowers:${#CUR}:1}"
fi
prevWasUpper="true" # Causes leading uppercase
;;
*)
OUTPUT="${OUTPUT}$CUR"
prevWasUpper="false" # Causes leading uppercase
;;
esac
i=$((i+1))
done
echo "${OUTPUT}"
}
function main {
PROJECT_ROOT=$1
COMMAND=$2
ESY_PKG=$2
CI_FOLDER="$PROJECT_ROOT/.ci"
mkdir -p $CI_FOLDER
cat >azure-pipelines.yml<<EOF
jobs:
- template: .ci/build.yaml
parameters:
host: macOS
pool:
vmImage: 'macOS-10.13'
- template: .ci/build.yaml
parameters:
host: Linux
pool:
vmImage: 'Ubuntu-16.04'
- template: .ci/build.yaml
parameters:
host: Windows
pool:
vmImage: 'vs2017-win2016'
EOF
# Installing pkg-config in esy's cygwin (for testing)
cat >$CI_FOLDER/pkg-config-cygwin.sh <<EOF
ROOT="\$(cygpath -m /)"
echo "cygwin root: \$ROOT"
LOCAL_PACKAGE_DIR="\$(cygpath -w /var/cache/setup)"
\$ROOT/setup-x86_64.exe --root \$ROOT -q --packages=pkg-config --local-package-dir \$LOCAL_PACKAGE_DIR --site=http://cygwin.mirror.constant.com/ --no-desktop --no-startmenu --no-shortcuts --verbose
EOF
sed -e "s;<COMMAND>;$COMMAND;g;" > $CI_FOLDER/build.yaml <<EOF
parameters:
host: ''
pool: ''
sign: false
jobs:
- job: \${{ parameters.host }}
pool: \${{ parameters.pool }}
steps:
- \${{ if eq(parameters.host, 'macOS') }}:
- script: brew install pkg-config
displayName: 'Install pkg-config (for testing)'
- \${{ if eq(parameters.host, 'Windows') }}:
- script: 'npm install -g esy@latest --unsafe-perm'
displayName: 'Install esy'
- \${{ if ne(parameters.host, 'Windows') }}:
- script: 'sudo npm install -g esy@latest --unsafe-perm'
displayName: 'Install esy'
- script: esy install
displayName: 'esy install'
- \${{ if eq(parameters.host, 'Windows') }}:
- script: esy b
displayName: 'esy build'
- \${{ if ne(parameters.host, 'Windows') }}:
- script: 'esy x pkg-config --libs <COMMAND>'
displayName: 'esy x pkg-config --libs <COMMAND>'
EOF
cat >.gitattributes<<EOF
* text eol=lf
EOF
cat >.gitignore<<EOF
node_modules
_esy
*~
EOF
cat >package.json<<EOF
{
"name": "esy-$(lowerHyphenate "${ESY_PKG}")",
"version": "0.0.000",
"description": "$ESY_PKG packaged for esy",
"esy": {
"buildsInSource": true,
"exportedEnv": {
"PKG_CONFIG_PATH": {
"scope": "global",
"val": "#{self.lib / 'pkgconfig' : \$PKG_CONFIG_PATH }"
}
},
"build": [
"chmod 755 ./configure",
"./configure --prefix=#{self.install} #{os == 'windows' ? '--host=x86_64-w64-mingw32' : ''}",
"make",
"make install"
]
},
"dependencies": {},
"resolutions": {}
}
EOF
}
PROJECT_ROOT=$PWD
# echo "Create project in $PROJECT_ROOT?"
# STTY_ORIG=`stty -g`
# stty -echo
# read -n1 PROCEED
# stty $STTY_ORIG
# case $PROCEED in
# [yY])
# main $PROJECT_ROOT
# ;;
# *)
# exit 0
# esac
main $PROJECT_ROOT $(basename "${PROJECT_ROOT}")