-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstall.cobra
More file actions
529 lines (428 loc) · 16.1 KB
/
install.cobra
File metadata and controls
529 lines (428 loc) · 16.1 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
"""
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.
On Windows and Mac, this program will install the addin for Xamarin Studio instead.
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
So what does this program do? It generates the addin assemblies and copies them
to the <OS-dependent>/MonoDevelop-5.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.
"""
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
# needs to match the version defined in CobraBinding.addin.xml
var _version = "0.6.1"
# workaround an issue when trying to install from a drive other than C:\
var _defaultWindowsPaths = [
r"C:\Cobra\bin"
]
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",
"CacheManager.cobra",
"CompilerManager.cobra",
"Extensions.cobra",
"Project[__s]CobraCompilerParameters.cobra",
"Project[__s]CobraProjectParameters.cobra",
"Project[__s]CompilerBuildOptionsPanel.cobra",
"Project[__s]GeneralBuildOptionsPanel.cobra",
"TypeSystem[__s]Parser.cobra",
"TypeSystem[__s]LineInformation.cobra",
"TypeSystem[__s]CobraModuleVisitor.cobra",
"TypeSystem[__s]ParsedCobraDocument.cobra",
"Tooltips[__s]Extensions.cobra",
"Tooltips[__s]TooltipProvider.cobra",
"Tooltips[__s]KeywordData.cobra",
"Formatting[__s]CobraIndentationTextEditorExtension.cobra",
"Completion[__s]CobraCompletionList.cobra",
"Completion[__s]CobraCompletionTextEditorExtension.cobra",
"Completion[__s]CobraParameterDataProvider.cobra",
"Completion[__s]DataFactory.cobra",
"Completion[__s]Icons.cobra",
"Completion[__s]NamedNodeData.cobra",
"Completion[__s]NameSpaceDeclsList.cobra",
"Completion[__s]BoxMembersList.cobra",
"Completion[__s]MethodVarsList.cobra",
"Completion[__s]KeywordCompletionData.cobra",
"Commands[__s]CommandId.cobra",
"Commands[__s]GoToDeclarationHandler.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"\Xamarin Studio\bin\MonoDevelop.Core.dll",
r"\Xamarin Studio\bin\MonoDevelop.Ide.dll",
r"\Xamarin Studio\bin\Mono.TextEditor.dll",
r"\Xamarin Studio\bin\MonoDevelop.Projects.Formats.MSBuild.dll",
r"\Xamarin Studio\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\gdk-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",
r"\GtkSharp\2.12\lib\gtk-sharp-2.0\pango-sharp.dll",
r"\GtkSharp\2.12\lib\Mono.Cairo\Mono.Cairo.dll",
]
var _macRefs = [
"/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/MonoDevelop.Core.dll",
"/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/MonoDevelop.Ide.dll",
"/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/ICSharpCode.NRefactory.dll",
"/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/Mono.TextEditor.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)
cmdLineArgs = List<of String>(Environment.getCommandLineArgs)
executingName = cmdLineArgs[0]
cmdLineArgs.removeAt(0)
buildMPack = cmdLineArgs.remove("package")
compileOnly = cmdLineArgs.remove("compile") or buildMPack
displayHelp = cmdLineArgs.remove("/?") or cmdLineArgs.remove("/h") or cmdLineArgs.remove("-h") or cmdLineArgs.remove("--help")
if cmdLineArgs.count > 0
print "Unknown arguments: [cmdLineArgs]"
print
.showUsage(executingName)
CobraCore.exit(1)
if displayHelp
.showUsage(executingName)
CobraCore.exit(0)
outPath = .getAddinPath
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)
# compile the addin
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]"
output = c.runAndCaptureOutput
if c.exitCode <> 0
print "Failed!"
print "std out:\n[output.standardOutput]"
print "std err:\n[output.errorOutput]"
print
print "The addin was not installed due to compilation errors."
CobraCore.exit(c.exitCode)
if buildMPack
print "The addin was successfully compiled."
print
print "Building MonoDevelop package..."
print "Copying assemblies..."
try
.copyAddinFiles("Package[__s]")
catch e as Exception
print "Failed!"
print e.message
print
print "The addin was compiled but was not packaged due to I/O errors."
CobraCore.exit(1)
cmd = .getMDToolCmd
print "Running [cmd.startInfo.fileName]..."
if v >= 1, print " args: [cmd.startInfo.arguments]"
output = cmd.runAndCaptureOutput
if cmd.exitCode <> 0
print "Failed!"
print "std out:\n[output.standardOutput]"
print "std err:\n[output.errorOutput]"
print
print "The addin was not packaged due to packaging errors."
CobraCore.exit(cmd.exitCode)
print "Removing temporary files..."
try
Directory.delete("Package", true)
catch e as Exception
print "Failed!"
print e.message
print
print "The addin was packaged but temporary files were not cleaned up due to I/O errors."
CobraCore.exit(1)
print "The MonoDevelop package was successfully built."
CobraCore.exit(0)
else if compileOnly
print "The addin was successfully compiled."
CobraCore.exit(0)
# install the addin
print "Copying assemblies..."
try
.copyAddinFiles(outPath)
.removeOtherVersions(outPath)
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 showUsage(executingPath as String)
print "An installation tool for the MonoDevelop Cobra language binding."
print
print "Usage: [Path.getFileName(executingPath)] \[compile|package\]"
print
print "Arguments:"
print " compile: Build the addin, but don't install."
print " package: Build the addin and package it into a MonoDevelop package."
print
print "By default, if neither 'compile' nor 'package' is supplied, it will build and"
print "install the addin."
print
def copyAddinFiles(outPath as String)
"""
Copies all files required for the addin to function to the specified location
"""
require
outPath.endsWith(__s)
ensure
Directory.exists(outPath)
Directory.getFiles(outPath).length == 5
body
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)
name = "CobraBinding.addin.xml"
File.copy("CobraBinding[__s][name]", outPath + name, true)
def removeOtherVersions(pathToLatest as String)
require Directory.exists(pathToLatest)
ensure Directory.exists(pathToLatest)
latestDir = DirectoryInfo(pathToLatest)
parentDir = latestDir.parent
for folder in parentDir.getDirectories("*CobraBinding*")
if folder.name == latestDir.name
# don't delete the folder we just installed the add-in into
continue
if folder.name == "CobraBinding" _
or folder.name.startsWith("MonoDevelop.CobraBinding.")
try
folder.delete(true)
catch
print "Warning! Failed to delete other version located at: [folder.fullName]"
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 CobraCore.isRunningOnWindows
app = "XamarinStudio"
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
app = "XamarinStudio"
path = "[home]/Library/Application Support"
else
app = "MonoDevelop"
path = "[home]/.local/share"
return path + "[__s][app]-5.0[__s]LocalInstall[__s]Addins[__s]MonoDevelop.CobraBinding.[_version][__s]"
def getMDToolCmd as Process
"""
Returns the command that will build the MonoDevelop package.
"""
body
info = _createProcessStartInfo
if CobraCore.isRunningOnWindows
progFiles = Environment.getEnvironmentVariable("PROGRAMFILES")
if File.exists(progFiles + r" (x86)\Xamarin Studio\bin\mdtool.exe")
# 32-bit on 64-bit Windows
progFiles += " (x86)"
info.fileName = progFiles + r"\Xamarin Studio\bin\mdtool.exe"
else if CobraCore.isRunningOnMac
info.fileName = "/Applications/Xamarin Studio.app/Contents/MacOS/mdtool"
else
info.fileName = "mdtool"
info.arguments = "setup pack -d:.. CobraBinding.addin.xml"
info.workingDirectory += "Package"
return Process(startInfo = info)
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 CobraCore.isRunningOnWindows
# 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 >= 3, info.arguments += " /verbosity:diagnostic"
else if _verbosity >= 2, info.arguments += " /verbosity:detailed"
else if _verbosity >= 1, info.arguments += " /verbosity:normal"
info.workingDirectory += "Gui"
cmds.add(Process(startInfo = info))
# and we'll use cobra to compile the CobraBinding project
info = _createProcessStartInfo
if _verbosity >= 3
info.environmentVariables['MONO_LOG_LEVEL'] = "debug"
info.environmentVariables['MONO_LOG_MASK'] = "dll"
if CobraCore.isRunningOnMono
# let the script have Mono run the actual EXE
info.fileName = CobraCommand.find.path
else
# Run the EXE directly
info.fileName = CobraCommand.findExe(_defaultWindowsPaths).path
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()
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.
"""
name = 'MonoDevelop.CobraBinding'
cobraArgs = StringBuilder(
'-compile -copy-core -target:lib -namespace:[name] -out:"bin[__s]Debug[__s][name].dll"'
)
cobraArgs.append(' -turbo:yes')
cobraArgs.append(' -debug:pdbonly')
if _verbosity > 0
cobraArgs.append(' -verbose -verbosity-ref:[_verbosity]')
for r in _refs
cobraArgs.append(" -ref:[r]")
if CobraCore.isRunningOnWindows
# 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)\Xamarin Studio\bin\MonoDevelop.Core.dll")
# 32-bit on 64-bit Windows
progFiles += " (x86)"
for p in _winRefsPartialPaths
cobraArgs.append(' -ref:"[progFiles][p]"')
else if CobraCore.isRunningOnMac
cobraArgs.append(" -pkg:gtk-sharp-2.0")
# on Mac, a bug prevents monodevelop package resolution due to a space in the path
for r in _macRefs
cobraArgs.append(' -ref:"[r]"')
else # Linux
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
CobraCommand.findExe(_defaultWindowsPaths) <> nil
CobraCommand.findExe(_defaultWindowsPaths).path.length > 0
ensure
result.endsWith("Cobra.Compiler.dll")
test
installer = CobraBindingAddinInstaller()
path = installer._getCobraCompilerDllPath
assert File.exists(path)
body
cobraExe = CobraCommand.findExe(_defaultWindowsPaths).path
cobraDir = Path.getDirectoryName(cobraExe)
return cobraDir + __s + "Cobra.Compiler.dll"