forked from ramon-rocha/MonoDevelop.CobraBinding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.cobra
More file actions
391 lines (322 loc) · 12.3 KB
/
install.cobra
File metadata and controls
391 lines (322 loc) · 12.3 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
"""
This is the installation program for the Cobra Language Binding addin for MonoDevelop.
It is not part of the addin itself and is intended to simplify the initial compilation.
To compile and install the addin, enter the following at the command prompt:
cd <path/to>/install.cobra
cobra install
Where <path/to> is the folder where you have downloaded the addin source code to.
The installer will check some things and then prompt you for confirmation to install.
To just compile the addin and not install the generated assemblies, do this instead:
cobra install -run-args compile
If you are running on 64-bit Windows 7, include the -clr-platform:x86 option. See the
NOTE below or the README.md file for more details.
So what does this program do? It generates the addin assemblies and copies them
to the <OS-dependent>/MonoDevelop-3.0/LocalInstall/Addins folder. If you just compile
the addin, the DLL files will be in the bin/Debug folders of each project.
Once installed, you will be able to create, run, and debug programs written in Cobra
using MonoDevelop.
NOTE: If you want to be able to use this addin on Windows 7 64-bit, you need to:
* Install (or reinstall) Cobra using the -x86 option
* Make sure to target your programs for the x86 platform when running
* Use the .NET runtime if you have .NET 4.5 installed
This is due to a limitation of loading some 32-bit dependencies using System.Reflection.
Alternatively, you can build MonoDevelop from source.
"""
use System.Diagnostics
class CobraBindingAddinInstaller
shared
# needs to be shared so we can use in list initializers
var __s = Path.directorySeparatorChar.toString
var _verbosity = 0
var _isWindows = Environment.osVersion.toString.startsWith("Microsoft Windows")
var _embeddedResources = [
"CobraBinding.addin.xml",
"CobraSyntaxMode.xml",
"templates[__s]ConsoleProject.xpt.xml",
"templates[__s]EmptyCobraFile.xft.xml",
"templates[__s]EmptyProject.xpt.xml",
"templates[__s]GtkSharp2Project.xpt.xml",
"templates[__s]LibraryProject.xpt.xml"
]
var _filesToCompile = [
"AssemblyInfo.cs",
"CobraLanguageBinding.cobra",
"Project[__s]CobraCompilerParameters.cobra",
"Project[__s]CompilerBuildOptionsPanel.cobra",
"TypeSystem[__s]Parser.cobra",
"TypeSystem[__s]LineInformation.cobra"
]
var _refs = [
"System.Core",
"Cobra.Compiler",
"..[__s]Gui[__s]bin[__s]Debug[__s]MonoDevelop.CobraBinding.Gui.dll"
]
var _pkgs = [
"monodevelop",
"gtk-sharp-2.0"
]
var _winRefsPartialPaths = [
r"\MonoDevelop\bin\MonoDevelop.Core.dll",
r"\MonoDevelop\bin\MonoDevelop.Ide.dll",
r"\MonoDevelop\bin\ICSharpCode.NRefactory.dll",
r"\GtkSharp\2.12\lib\gtk-sharp-2.0\gtk-sharp.dll",
r"\GtkSharp\2.12\lib\gtk-sharp-2.0\glib-sharp.dll",
r"\GtkSharp\2.12\lib\gtk-sharp-2.0\atk-sharp.dll",
]
def main
v = _verbosity
if not .verifyWorkingDirectory
print
print "========================================================="
print "You must run this program from the addin solution folder."
print "========================================================="
print
CobraCore.exit(1)
outPath = .getAddinPath
cmdLineArgs = List<of String>(Environment.getCommandLineArgs)
compileOnly = "compile" in cmdLineArgs
if compileOnly
print "Compiling the Cobra Language Binding addin for MonoDevelop..."
else
print
print "==============================================================================="
print "This will compile and install the Cobra Language Binding addin for MonoDevelop."
print
print "The compiled assemblies will be copied to:"
print outPath
print "==============================================================================="
print
continueVar = Environment.getEnvironmentVariable('COBRA_BINDING_CONTINUE') ? ''
if continueVar.trim.toLower not in ['1', 'yes', 'true']
print "Do you wish to continue? \[Y/N\] "
response = Console.readLine
if not response.toLower.startsWith("y")
print
print "The addin was not installed."
CobraCore.exit(1)
cmds = .getCompilerCmds
for c in cmds
binDir = c.startInfo.workingDirectory + "[__s]bin[__s]Debug"
if not Directory.exists(binDir)
Directory.createDirectory(binDir)
print "Running [c.startInfo.fileName]..."
if v >= 1, print " args: [c.startInfo.arguments]"
#trace c.startInfo.arguments
c.start
if v >= 1, print '.waitForExit ...'
c.waitForExit
if v >= 1, print 'finished .waitForExit'
if v
# the output of the command is passed through, so not much to do
pass
else if c.exitCode <> 0
# print command output on failure of the command
print "Failed!"
print 'std out:'
print c.standardOutput.readToEnd
print 'std err:'
print c.standardError.readToEnd
if c.exitCode <> 0
print
print "The addin was not installed due to compilation errors."
CobraCore.exit(c.exitCode)
if compileOnly
print "The addin was successfully compiled."
CobraCore.exit(0)
print "Copying assemblies..."
try
if not Directory.exists(outPath)
Directory.createDirectory(outPath)
name = "MonoDevelop.CobraBinding.Gui.dll"
File.copy("Gui[__s]bin[__s]Debug[__s][name]", outPath + name, true)
name = "MonoDevelop.CobraBinding.dll"
File.copy("CobraBinding[__s]bin[__s]Debug[__s][name]", outPath + name, true)
name = "Cobra.Core.dll"
File.copy("CobraBinding[__s]bin[__s]Debug[__s][name]", outPath + name, true)
name = "Cobra.Compiler.dll"
File.copy(_getCobraCompilerDllPath, outPath + name, true)
catch e as Exception
print "Failed!"
print e.message
print
print "The addin was compiled but was not installed due to directory or file I/O errors."
CobraCore.exit(1)
print "The addin has been installed."
CobraCore.exit(0)
def verifyWorkingDirectory as bool
return File.exists("install.cobra") _
and Directory.exists("CobraBinding") _
and Directory.exists("Gui")
def getAddinPath as String
"""
Returns the path where the assemblies will be copied to.
"""
ensure
result.endsWith(__s)
body
if _isWindows
path = Environment.getEnvironmentVariable("LOCALAPPDATA")
if path == nil
# variable not defined before Vista
path = Environment.getEnvironmentVariable("USERPROFILE") + "\\Local Settings\\Application Data"
else
home = Environment.getEnvironmentVariable("HOME")
if CobraCore.isRunningOnMac
path = "[home]/Library/Application Support"
else
path = "[home]/.local/share"
return path + "[__s]MonoDevelop-3.0[__s]LocalInstall[__s]Addins[__s]CobraBinding[__s]"
def getCompilerCmds as List<of Process>
"""
Returns the commands that will compile the addin source code.
"""
test
procs = CobraBindingAddinInstaller().getCompilerCmds
for p in procs
i = p.startInfo
assert i.useShellExecute == false
assert i.createNoWindow == true
assert i.windowStyle == ProcessWindowStyle.Hidden
assert i.fileName.length > 0
assert i.arguments.length > 0
assert i.workingDirectory.length > 0
body
cmds = List<of Process>()
info = _createProcessStartInfo
if _isWindows
# We'll use msbuild to compile the Gui project
info.fileName = "msbuild"
# prefer a full path
root = Environment.getEnvironmentVariable("SYSTEMROOT")
msbuildPaths = @[
'[root][__s]Microsoft.NET[__s]Framework[__s]v4.0.30319[__s]MSBuild.exe',
'[root][__s]Microsoft.NET[__s]Framework[__s]v2.0.50727[__s]MSBuild.exe',
]
for filePath in msbuildPaths
if File.exists(filePath)
info.fileName = filePath
break
else
# We'll use xbuild when not on Windows
info.fileName = "xbuild"
info.arguments = "Gui.csproj /p:Configuration=Debug"
if _verbosity >= 2, info.arguments += " /verbosity:detailed"
else if _verbosity >= 1, info.arguments += " /verbosity:normal"
if _isWindows
progFiles = Environment.getEnvironmentVariable("PROGRAMFILES")
if progFiles.endsWith("(x86)")
# 32-bit on 64-bit Windows
info.arguments += " /p:Platform=x86"
else
info.arguments += " /p:Platform=anycpu"
info.workingDirectory += "Gui"
cmds.add(Process(startInfo = info))
# and we'll use cobra to compile the CobraBinding project
info = _createProcessStartInfo
if CobraCore.isRunningOnMono
/#
Workaround an inability of Mono to find the dependencies
of MonoDevelop.Ide.dll when loaded via reflection.
#/
if _isWindows
info.environmentVariables["MONO_PATH"] = "[progFiles]\\MonoDevelop\\bin"
else if CobraCore.isRunningOnMac
info.environmentVariables["MONO_PATH"] = "/Applications/MonoDevelop.app/Contents/MacOS/lib/monodevelop/bin"
monoDevPkgConfigPath = '/Applications/MonoDevelop.app/Contents/MacOS/lib/pkgconfig'
pkgConfigPath = Environment.getEnvironmentVariable('PKG_CONFIG_PATH') ? ''
if monoDevPkgConfigPath not in pkgConfigPath
if pkgConfigPath <> '', pkgConfigPath += ':'
info.environmentVariables["PKG_CONFIG_PATH"] = pkgConfigPath + monoDevPkgConfigPath
else
# Presumably Linux or BSD...
info.environmentVariables["MONO_PATH"] = "/usr/lib/monodevelop/bin"
if _verbosity >= 3
info.environmentVariables['MONO_LOG_LEVEL'] = "debug"
info.environmentVariables['MONO_LOG_MASK'] = "dll"
info.fileName = CobraCore.findCobraExe
info.arguments = _getCobraArguments
info.workingDirectory += "CobraBinding"
cmds.add(Process(startInfo = info))
return cmds
def _createProcessStartInfo as ProcessStartInfo
"""
Returns a ProcessStartInfo object that will cause a process to
spawn in a hidden window with ability to redirect its output.
"""
ensure
result.workingDirectory.endsWith(__s)
body
i = ProcessStartInfo()
if _verbosity == 0
i.redirectStandardOutput = i.redirectStandardError = true
i.useShellExecute = false
i.createNoWindow = true
i.windowStyle = ProcessWindowStyle.Hidden
i.workingDirectory = Directory.getCurrentDirectory + __s
i.environmentVariables["PATH"] = Environment.getEnvironmentVariable("PATH")
return i
def _getCobraArguments as String
"""
Returns the arguments that should be passed to the Cobra compiler
to compile the CobraBinding project.
"""
cobraArgs = StringBuilder(
'-compile -copy-core -target:lib -out:"bin[__s]Debug[__s]MonoDevelop.CobraBinding.dll"'
)
if _verbosity >= 2, cobraArgs.append(' -v -verbosity-ref:2')
else if _verbosity >= 1, cobraArgs.append(' -v -verbosity-ref:1')
for r in _refs
cobraArgs.append(" -ref:[r]")
if _isWindows
# on windows, we need to specify the full path to the MonoDevelop and Gtk libs
progFiles = Environment.getEnvironmentVariable("PROGRAMFILES")
if File.exists(progFiles + r" (x86)\MonoDevelop\bin\MonoDevelop.Core.dll")
# 32-bit on 64-bit Windows
progFiles += " (x86)"
for p in _winRefsPartialPaths
cobraArgs.append(' -ref:"[progFiles][p]"')
else
for p in _pkgs
cobraArgs.append(" -pkg:[p]")
cobraArgs.append(' -sharp-args:"')
sb = StringBuilder()
for resource in _embeddedResources
sb.append('-res:\\"[resource]\\" ')
cobraArgs.append(sb.toString.trimEnd)
cobraArgs.append('" ')
for fileName in _filesToCompile
cobraArgs.append("[fileName] ")
return cobraArgs.toString
def _getCobraCompilerDllPath as String
"""
Returns the path to Cobra.Compiler.dll
"""
require
CobraCore.findCobraExe <> nil
CobraCore.findCobraExe.length > 0
ensure
result.endsWith("Cobra.Compiler.dll")
test
installer = CobraBindingAddinInstaller()
path = installer._getCobraCompilerDllPath
assert File.exists(path)
body
/#
Get the location of cobra.exe, this will actually
return cobra.bat or a BASH script in most cases.
#/
cobraCmd = CobraCore.findCobraExe
# execute: 'cobra -path'
proc = System.Diagnostics.Process()
proc.startInfo.fileName = cobraCmd
proc.startInfo.arguments = "-path"
proc.startInfo.useShellExecute = false
proc.startInfo.createNoWindow = true
proc.startInfo.windowStyle = ProcessWindowStyle.Hidden
proc.startInfo.workingDirectory = Directory.getCurrentDirectory + __s
proc.startInfo.environmentVariables["PATH"] = Environment.getEnvironmentVariable("PATH")
# this should return something like '/usr/local/cobra/Cobra-0.9.0/bin/cobra.exe'
output = proc.runAndCaptureAllOutput.trim
cobraExeInfo = FileInfo(output)
cobraDir = cobraExeInfo.directoryName
return cobraDir + __s + "Cobra.Compiler.dll"