Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 35269e2

Browse files
committed
Initial import.
0 parents  commit 35269e2

File tree

712 files changed

+108599
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

712 files changed

+108599
-0
lines changed

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SwiftToolchain-*
2+
Constants.cs
3+
Pack-Man/*
4+
*.csproj.user
5+
stconfig.inc
6+
devicetests-build

Diff for: BUILDING.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Building Binding Tools for Swift from sources
2+
3+
## Requirements
4+
5+
### Install Xcode
6+
7+
There are two options to installing Xcode:
8+
9+
1. Use automatic provisioning. This is done by executing `make provision` in `maccore/tools/tom-swifty`, but it may take a while to download Xcode unless you're in the Boston office, in which case it might be better to download Xcode manually (next option).
10+
11+
2. Download Xcode manually from https://download.developer.apple.com/Developer_Tools/Xcode_9.2/Xcode_9.2.xip
12+
13+
1. Extract and copy Xcode_9.2.xip to `/Applications/Xcode_9.2.app` (if you already have Xcode 9.2 in `/Applications/Xcode92.app`, you can just create a symlink: `ln -s /Applications/Xcode92.app /Applications/Xcode_9.2.app`)
14+
2. `sudo xcode-select -s /Applications/Xcode_9.2.app/`
15+
16+
### Notes
17+
18+
* there are other requirements (e.g. `cmake`, `ninja`) that I already have, most of them are likely needed to build `xamarin-macios`. It’s possible that I have some for others reasons too. Please update this document if you find any missing requirements.
19+
20+
21+
## Building
22+
23+
Create a directory to dedicate to Binding Tools for Swift, e.g.
24+
25+
1. `mkdir ~/git/binding-tools-for-swift`
26+
2. `cd ~/git/binding-tools-for-swift`
27+
28+
Clone maccore
29+
30+
1. `git clone [email protected]:xamarin/maccore`
31+
32+
Build everything. This will build the swift dependency (only if needed [1]) and binding-tools-for-swift.
33+
34+
1. `cd tools/tom-swifty`
35+
2. `make`
36+
37+
[1] The build script will first check if a prepackaged version of the swift
38+
toolchain is available in Azure, and if so, download and use that version.
39+
This behavior can be overriden by doing `export FORCE_SWIFT_BUILD=1`.
40+
41+
### Notes
42+
43+
The above steps are doing a **full debug** build for swift. [build-script](https://github.com/xamarin/swift/blob/swift-4.0-branch-tomswifty/utils/build-script) can also produce different builds, e.g.
44+
45+
* `-d | --debug`: full debug (like above)
46+
* `-R | --release`: release
47+
* `-r | --release-debuginfo`: release with debug info
48+
49+
Running `build-script` takes a **very long** time, so building extraneous local configurations is optional.
50+
51+
### Running Unit Tests
52+
53+
1. `cd maccore/tools/tom-swifty/tests/tom-swifty-test/`
54+
2. `make`
55+
56+
### Notes
57+
58+
* The new (incompatible but much more powerful) NUnit 3 runner means using the usual `FIXTURES` variable has to use a [different syntax](https://github.com/nunit/docs/wiki/Test-Selection-Language). E.g. to run a single test case from the command line you would do
59+
60+
```
61+
FIXTURES="--where=test=SwiftReflector.LinkageTests.TestMissingNSObject" make
62+
```
63+
64+
65+
## Generated Source Files
66+
- `SwiftReflector/IOUtils/SwiftModuleList.g.cs` is generated via the `update_module_list.csharp` script.
67+
- `./update_module_list.csharp SwiftToolchain-v2-8efccc1464890d6c906fb2c40f909b5324da950d`

Diff for: Constants.cs.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
static class Constants {
2+
public const string Version = "@VERSION@";
3+
public const string Branch = "@BRANCH@";
4+
public const string Hash = "@HASH@";
5+
}

Diff for: Dynamo/CodeElementCollection.cs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Dynamo {
6+
public class CodeElementCollection<T> : List<T>, ICodeElementSet where T : ICodeElement {
7+
public CodeElementCollection () : base ()
8+
{
9+
}
10+
11+
#region ICodeElem implementation
12+
13+
public event EventHandler<WriteEventArgs> Begin = (s, e) => { };
14+
15+
public event EventHandler<WriteEventArgs> End = (s, e) => { };
16+
17+
public virtual object BeginWrite (ICodeWriter writer)
18+
{
19+
OnBeginWrite (new WriteEventArgs (writer));
20+
return null;
21+
}
22+
23+
protected virtual void OnBeginWrite (WriteEventArgs args)
24+
{
25+
Begin (this, args);
26+
}
27+
28+
public virtual void Write (ICodeWriter writer, object o)
29+
{
30+
}
31+
32+
public virtual void EndWrite (ICodeWriter writer, object o)
33+
{
34+
OnEndWrite (new WriteEventArgs (writer));
35+
}
36+
37+
protected virtual void OnEndWrite (WriteEventArgs args)
38+
{
39+
End.FireInReverse (this, args);
40+
}
41+
42+
43+
#endregion
44+
45+
#region ICodeElemSet implementation
46+
47+
public System.Collections.Generic.IEnumerable<ICodeElement> Elements {
48+
get {
49+
return this.Cast<ICodeElement> ();
50+
}
51+
}
52+
53+
#endregion
54+
55+
}
56+
}
57+

Diff for: Dynamo/CodeWriter.cs

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using System;
2+
using System.Globalization;
3+
using System.IO;
4+
5+
namespace Dynamo {
6+
public class CodeWriter : ICodeWriter {
7+
int charsWrittenThisLine;
8+
bool indentedThisLine;
9+
10+
const int kSpacesPerIndent = 4;
11+
const int kWrapPoint = 60;
12+
13+
public CodeWriter (Stream stm)
14+
: this (new StreamWriter (Exceptions.ThrowOnNull (stm, "stm")))
15+
{
16+
}
17+
18+
public CodeWriter (TextWriter tw)
19+
{
20+
TextWriter = Exceptions.ThrowOnNull (tw, "tw");
21+
charsWrittenThisLine = 0;
22+
IndentLevel = 0;
23+
IsAtLineStart = true;
24+
}
25+
26+
public static void WriteToFile (string fileName, ICodeElement element)
27+
{
28+
using (var stm = new FileStream (fileName, FileMode.Create)) {
29+
CodeWriter writer = new CodeWriter (stm);
30+
element.WriteAll (writer);
31+
writer.TextWriter.Flush ();
32+
}
33+
}
34+
35+
public static Stream WriteToStream (ICodeElement element)
36+
{
37+
var stm = new MemoryStream ();
38+
var codeWriter = new CodeWriter (stm);
39+
element.WriteAll (codeWriter);
40+
codeWriter.TextWriter.Flush ();
41+
stm.Flush ();
42+
stm.Seek (0, SeekOrigin.Begin);
43+
return stm;
44+
}
45+
46+
public static string WriteToString (ICodeElement element)
47+
{
48+
using (var reader = new StreamReader (WriteToStream (element)))
49+
return reader.ReadToEnd ();
50+
}
51+
52+
public TextWriter TextWriter { get; private set; }
53+
54+
#region ICodeWriter implementation
55+
56+
public void BeginNewLine (bool prependIndents)
57+
{
58+
Write (Environment.NewLine, false);
59+
if (prependIndents)
60+
WriteIndents ();
61+
IsAtLineStart = true;
62+
}
63+
64+
public void EndLine ()
65+
{
66+
charsWrittenThisLine = 0;
67+
if (indentedThisLine) {
68+
indentedThisLine = false;
69+
// strictly speaking, this test shouldn't be necessary
70+
if (IndentLevel > 0)
71+
Exdent ();
72+
}
73+
}
74+
75+
public bool IsAtLineStart { get; private set; }
76+
77+
public void Write (string code, bool allowSplit)
78+
{
79+
var characterEnum = StringInfo.GetTextElementEnumerator (code);
80+
while (characterEnum.MoveNext ()) {
81+
string c = characterEnum.GetTextElement ();
82+
WriteUnicode (c, allowSplit);
83+
}
84+
}
85+
86+
public void Write (char c, bool allowSplit)
87+
{
88+
Write (c.ToString (), allowSplit);
89+
}
90+
91+
void WriteUnicode (string c, bool allowSplit)
92+
{
93+
var info = new StringInfo (c);
94+
if (info.LengthInTextElements > 1)
95+
throw new ArgumentOutOfRangeException (nameof (c), $"Expected a single unicode value but got '{c}'");
96+
WriteNoBookKeeping (c);
97+
IsAtLineStart = false;
98+
charsWrittenThisLine++;
99+
if (allowSplit && charsWrittenThisLine > kWrapPoint && IsWhiteSpace (c)) {
100+
if (!indentedThisLine) {
101+
Indent ();
102+
indentedThisLine = true;
103+
}
104+
WriteNoBookKeeping (Environment.NewLine);
105+
charsWrittenThisLine = 0;
106+
WriteIndents ();
107+
IsAtLineStart = true;
108+
}
109+
}
110+
111+
bool IsWhiteSpace (string c) {
112+
return c.Length == 1 && Char.IsWhiteSpace (c[0]);
113+
114+
}
115+
116+
void WriteNoBookKeeping (string s)
117+
{
118+
TextWriter.Write (s);
119+
}
120+
121+
void WriteIndents ()
122+
{
123+
int totalSpaces = IndentLevel * kSpacesPerIndent;
124+
// know what's embarrassing? When your indents cause breaks which generates more indents.
125+
for (int i = 0; i < totalSpaces; i++)
126+
Write (" ", false);
127+
}
128+
129+
public void Indent ()
130+
{
131+
IndentLevel++;
132+
}
133+
134+
public void Exdent ()
135+
{
136+
if (IndentLevel == 0)
137+
throw new Exception ("IndentLevel is at 0.");
138+
IndentLevel--;
139+
}
140+
141+
public int IndentLevel { get; private set; }
142+
143+
#endregion
144+
}
145+
}
146+

Diff for: Dynamo/CommaListElementCollection.cs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Dynamo {
5+
public class CommaListElementCollection<T> : List<T>, ICodeElement where T : ICodeElement {
6+
public CommaListElementCollection ()
7+
: this ("", "")
8+
{
9+
}
10+
11+
12+
public CommaListElementCollection (IEnumerable<T> objs)
13+
: this ("", "", objs)
14+
{
15+
}
16+
17+
public CommaListElementCollection (string prefix, string suffix)
18+
: base ()
19+
{
20+
Prefix = Exceptions.ThrowOnNull (prefix, nameof (prefix));
21+
Suffix = Exceptions.ThrowOnNull (suffix, nameof (suffix));
22+
}
23+
24+
public CommaListElementCollection (string prefix, string suffix, IEnumerable<T> objs, bool newlineAfterEach = false)
25+
: this (prefix, suffix)
26+
{
27+
AddRange (Exceptions.ThrowOnNull (objs, nameof (objs)));
28+
NewlineAfterEach = newlineAfterEach;
29+
}
30+
31+
32+
public string Prefix { get; private set; }
33+
public string Suffix { get; private set; }
34+
public bool NewlineAfterEach { get; private set; }
35+
36+
#region ICodeElem implementation
37+
38+
public event EventHandler<WriteEventArgs> Begin = (s, e) => { };
39+
40+
public event EventHandler<WriteEventArgs> End = (s, e) => { };
41+
42+
public object BeginWrite (ICodeWriter writer)
43+
{
44+
OnBegin (new WriteEventArgs (writer));
45+
return null;
46+
}
47+
48+
protected virtual void OnBegin (WriteEventArgs args)
49+
{
50+
Begin (this, args);
51+
}
52+
53+
public void Write (ICodeWriter writer, object o)
54+
{
55+
writer.Write (Prefix, true);
56+
for (int i = 0; i < Count; i++) {
57+
this [i].WriteAll (writer);
58+
if (i < Count - 1)
59+
writer.Write (", ", true);
60+
if (NewlineAfterEach && !writer.IsAtLineStart) {
61+
writer.BeginNewLine (true);
62+
}
63+
}
64+
writer.Write (Suffix, true);
65+
}
66+
67+
public void EndWrite (ICodeWriter writer, object o)
68+
{
69+
OnEnd (new WriteEventArgs (writer));
70+
}
71+
72+
73+
protected virtual void OnEnd (WriteEventArgs args)
74+
{
75+
End.FireInReverse (this, args);
76+
}
77+
78+
#endregion
79+
}
80+
}
81+

0 commit comments

Comments
 (0)