Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
vinivendra committed Jun 26, 2022
2 parents e39ee01 + 8bab1ae commit b364565
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 175 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM swift:5.5.1
FROM swift:5.6.1


# Update, upgrade and install a few useful tools
Expand Down
27 changes: 22 additions & 5 deletions Package.swift
Expand Up @@ -28,7 +28,13 @@ import PackageDescription
// url: "https://github.com/apple/swift-syntax.git",
// .revision("release/5.6")) // <- git branch name

#if swift(>=5.5)
// Which SwiftSyntax version to use
#if swift(>=5.6)
let swiftSyntaxPackage = Package.Dependency.package(
name: "SwiftSyntax",
url: "https://github.com/apple/swift-syntax.git",
.exact("0.50600.1"))
#elseif swift(>=5.5)
let swiftSyntaxPackage = Package.Dependency.package(
name: "SwiftSyntax",
url: "https://github.com/apple/swift-syntax.git",
Expand All @@ -50,6 +56,20 @@ let swiftSyntaxPackage = Package.Dependency.package(
.exact("0.50200.0"))
#endif

// Which modules to import from SwiftSyntax (and SourceKitten)
#if swift(>=5.6)
let gryphonLibDependencies: [Target.Dependency] = [
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
.product(name: "SwiftSyntaxParser", package: "SwiftSyntax"),
.product(name: "SourceKittenFramework", package: "SourceKitten")
]
#else
let gryphonLibDependencies: [Target.Dependency] = [
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
.product(name: "SourceKittenFramework", package: "SourceKitten")
]
#endif

let package = Package(
name: "Gryphon",
platforms: [
Expand All @@ -68,10 +88,7 @@ let package = Package(
targets: [
.target(
name: "GryphonLib",
dependencies: [
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
.product(name: "SourceKittenFramework", package: "SourceKitten")
]),
dependencies: gryphonLibDependencies),
.target(
name: "Gryphon",
dependencies: ["GryphonLib"]),
Expand Down
39 changes: 33 additions & 6 deletions Scripts/runBootstrappingTests.sh
@@ -1,5 +1,30 @@
#!/bin/bash

if [[ $(swift --version | grep "5.5") ]];
then
echo "Using Swift 5.5"
else
echo "🚨 Only Swift 5.5 is supported for bootstrapping tests."
exit -1
fi

isVerbose=""

while test $# -gt 0
do
case "$1" in
"-v")
isVerbose="-v"
;;
*)
echo "Skipping unknown argument '$1'"
;;
esac

shift
done


echo "➡️ [1/7] Updating Gryphon (old)..."

set -e
Expand Down Expand Up @@ -52,7 +77,7 @@ cd ../../..

echo "➡️ [4/7] Transpiling the Gryphon (old) source files to Kotlin..."

if bash Scripts/transpileGryphonSources.sh
if bash Scripts/transpileGryphonSources.sh $isVerbose
then
echo "✅ Done."
echo ""
Expand Down Expand Up @@ -90,15 +115,17 @@ fi

echo "➡️ [7/7] Comparing Gryphon (old) with Gryphon (old) transpiled..."

for file in Test\ cases/*.swift
libraryFile="ASTDumps-Swift-5.5/gryphon/GryphonTemplatesLibrary.swiftASTDump"

for file in ASTDumps-Swift-5.5/Test\ cases/*.swiftASTDump
do
if [[ $file == *"errors.swift" ]]; then
if [[ $file == *"errors.swift"* ]]; then
echo " ↪️ Skipping $file..."
else
echo " ↪️ Testing $file..."

defaultFinal="";
if [[ $file == *"-default-final.swift" ]]; then
if [[ $file == *"-default-final.swift"* ]]; then
defaultFinal="--default-final";
fi

Expand All @@ -110,7 +137,7 @@ do

java -jar Bootstrap/kotlin.jar \
--indentation=t -avoid-unicode $representation $defaultFinal --write-to-console \
"$file" > .gryphon/generatedResult.txt 2> .gryphon/errors.txt
"$file" "$libraryFile" > .gryphon/generatedResult.txt 2> .gryphon/errors.txt

if [[ $? -ne 0 ]]; then
echo "🚨 failed to generate bootstrap results!"
Expand All @@ -120,7 +147,7 @@ do

./.build/debug/Gryphon \
--indentation=t -avoid-unicode $representation $defaultFinal --write-to-console \
"$file" > .gryphon/expectedResult.txt 2> .gryphon/errors.txt
"$file" "$libraryFile" > .gryphon/expectedResult.txt 2> .gryphon/errors.txt

if [[ $? -ne 0 ]]; then
echo "🚨 failed to generate expected results!"
Expand Down
8 changes: 6 additions & 2 deletions Scripts/runTests.sh
Expand Up @@ -7,6 +7,7 @@ unitTests=0
acceptanceTests=0
bootstrapTests=0
xcodeTests=0
isVerbose=""

while test $# -gt 0
do
Expand All @@ -22,6 +23,9 @@ do
;;
"-x")
xcodeTests=1
;;
"-v")
isVerbose="-v"
;;
*)
echo "Skipping unknown argument '$1'"
Expand Down Expand Up @@ -182,7 +186,7 @@ if [[ $bootstrapTests -ne 0 ]]; then
exec 4>&1
exec 1> >(paste /dev/null -)

if bash Scripts/runBootstrappingTests.sh
if bash Scripts/runBootstrappingTests.sh $isVerbose
then
echo "✅ Bootstrapping tests succeeded."
echo ""
Expand All @@ -202,7 +206,7 @@ if [[ $xcodeTests -ne 0 ]]; then
exec 4>&1
exec 1> >(paste /dev/null -)

if bash Scripts/runXcodeTests.sh
if bash Scripts/runXcodeTests.sh $isVerbose
then
echo "✅ Xcode tests succeeded."
echo ""
Expand Down
44 changes: 38 additions & 6 deletions Scripts/runXcodeTests.sh
@@ -1,4 +1,25 @@
#!/bin/bash

####################################################################################################
# Read the arguments

isVerbose=""

while test $# -gt 0
do
case "$1" in
"-v")
isVerbose="--verbose"
;;
*)
echo "Skipping unknown argument '$1'"
;;
esac

shift
done

####################################################################################################
set -e

if uname -s | grep "Darwin"
Expand Down Expand Up @@ -35,7 +56,8 @@ echo "sdk.dir=/Users/$USER/Library/Android/sdk" > \

# Remove Gryphon-generated files
cd "Test Files/XcodeTests/iOS"
gryphon clean
gryphon clean $isVerbose
rm -rf "build"
rm -f "gryphonInputFiles.xcfilelist"
rm -f "local.config"

Expand All @@ -53,7 +75,7 @@ echo ""
echo "➡️ [2/8] Initializing the Xcode project..."

# Initialize the Xcode project
gryphon init "GryphoniOSTest.xcodeproj"
gryphon init "GryphoniOSTest.xcodeproj" $isVerbose

# Add the "Model.swift" file to the list of files to be translated
echo "GryphoniOSTest/Model.swift" > "gryphonInputFiles.xcfilelist"
Expand All @@ -72,15 +94,25 @@ rm -f ../Android/app/src/main/java/com/gryphon/gryphonandroidtest/Model.kt
# Remove file that stores errors and warnings
rm -f output.txt


# Run the Gryphon target
if [[ $(xcodebuild -project GryphoniOSTest.xcodeproj/ -scheme Gryphon > output.txt) ]];
set +e
xcodebuild -project GryphoniOSTest.xcodeproj/ -scheme Gryphon > output.txt

# If there was an error
if [ $? -ne 0 ];
then
echo ""
echo ""
echo "🚨 Error running Gryphon target. Printing xcodebuild output:"
cat output.txt || true
sleep 3 # Wait for cat to finish printing before exiting
exit -1
fi

set -e


# Check if Gryphon raised warnings or errors for the Model.swift file
if [[ $(grep -E "Model\.swift:[0-9]+:[0-9]+: error" output.txt) ]];
then
Expand Down Expand Up @@ -113,7 +145,7 @@ echo ""
echo "➡️ [4/8] Resetting the Xcode project..."

# Remove Gryphon-generated files
gryphon clean
gryphon clean $isVerbose
rm -f "gryphonInputFiles.xcfilelist"
rm -f "local.config"

Expand All @@ -131,7 +163,7 @@ echo ""
echo "➡️ [5/8] Initializing the Xcode project with '--target'..."

# Initialize the Xcode project
gryphon init "GryphoniOSTest.xcodeproj" --target=GryphoniOSTest
gryphon init "GryphoniOSTest.xcodeproj" --target=GryphoniOSTest $isVerbose

# Add the "Model.swift" file to the list of files to be translated
echo "GryphoniOSTest/Model.swift" > "gryphonInputFiles.xcfilelist"
Expand Down Expand Up @@ -217,7 +249,7 @@ rm -f output.txt
cp "../ModelWithErrors.swift" "GryphoniOSTest/Model.swift"

# Transpile the model file
gryphon "GryphoniOSTest/Model.swift"
gryphon "GryphoniOSTest/Model.swift" $isVerbose

# Run the Kotlin target
if [[ $(xcodebuild -project GryphoniOSTest.xcodeproj/ -scheme Kotlin > output.txt 2> /dev/null) ]];
Expand Down
19 changes: 18 additions & 1 deletion Scripts/transpileGryphonSources.sh
@@ -1,9 +1,27 @@
#!/bin/bash

isVerbose=""

while test $# -gt 0
do
case "$1" in
"-v")
isVerbose="--verbose"
;;
*)
echo "Skipping unknown argument '$1'"
;;
esac

shift
done

./.build/debug/Gryphon \
--indentation=4 \
-print-ASTs-on-error \
--continue-on-error \
$isVerbose \
--sync \
Test\ Files/Bootstrap/gryphon-old/Sources/GryphonLib/ASTDumpDecoder.swift \
Test\ Files/Bootstrap/gryphon-old/Sources/GryphonLib/AuxiliaryFileContents.swift \
Test\ Files/Bootstrap/gryphon-old/Sources/GryphonLib/Compiler.swift \
Expand All @@ -22,7 +40,6 @@
Test\ Files/Bootstrap/gryphon-old/Sources/GryphonLib/SwiftTranslator.swift \
Test\ Files/Bootstrap/gryphon-old/Sources/GryphonLib/TranspilationContext.swift \
Test\ Files/Bootstrap/gryphon-old/Sources/GryphonLib/TranspilationPass.swift \
Test\ Files/Bootstrap/gryphon-old/Tests/GryphonLibTests/AcceptanceTest.swift \
Test\ Files/Bootstrap/gryphon-old/Tests/GryphonLibTests/ASTDumpDecoderTest.swift \
Test\ Files/Bootstrap/gryphon-old/Tests/GryphonLibTests/CompilerTest.swift \
Test\ Files/Bootstrap/gryphon-old/Tests/GryphonLibTests/DriverTest.swift \
Expand Down
31 changes: 27 additions & 4 deletions Sources/GryphonLib/AuxiliaryFileContents.swift
Expand Up @@ -504,16 +504,25 @@ public struct _ListSlice<Element>: Collection,
return list[position]
}
// MutableCollection
// For MutableCollection
set {
list._setElement(newValue, atIndex: position)
}
}
public subscript(bounds: Range<Index>) -> _ListSlice<Element> {
// From Collection.swift
_failEarlyRangeCheck(bounds, bounds: startIndex..<endIndex)
return _ListSlice(list: list, range: bounds)
get {
// From Collection.swift
_failEarlyRangeCheck(bounds, bounds: startIndex..<endIndex)
return _ListSlice(list: list, range: bounds)
}
// For MutableCollection
set {
for i in bounds {
list._setElement(newValue[i], atIndex: i)
}
}
}
public func index(after i: Int) -> Int {
Expand Down Expand Up @@ -809,6 +818,20 @@ public class MutableList<Element>: List<Element>,
}
}
public override subscript(bounds: Range<Index>) -> _ListSlice<Element> {
get {
// From Collection.swift
_failEarlyRangeCheck(bounds, bounds: startIndex..<endIndex)
return _ListSlice(list: self, range: bounds)
}
set {
for i in bounds {
array[i] = newValue[i]
}
}
}
// RangeReplaceableCollection
override public required init() {
super.init([])
Expand Down

0 comments on commit b364565

Please sign in to comment.