Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/183 #273

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Logos-Xcode/src/AdditionalLanguages.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Xcode.SourceCodeLanguage.Logos</key>
<dict>
<key>languageSpecification</key>
<string>xcode.lang.logos</string>
<key>fileDataType</key>
<array>
<dict>
<key>identifier</key>
<string>com.apple.xcode.logos-source</string>
</dict>
</array>
<key>id</key>
<string>Xcode.SourceCodeLanguage.Logos</string>
<key>point</key>
<string>Xcode.SourceCodeLanguage</string>
<key>languageName</key>
<string>Logos</string>
<key>version</key>
<string>1.0</string>
<key>documentationAbbreviation</key>
<string>logos</string>
<key>conformsTo</key>
<array>
<dict>
<key>identifier</key>
<string>Xcode.SourceCodeLanguage.Generic</string>
</dict>
</array>
<key>name</key>
<string>Logos Language</string>
</dict>
</dict>
</plist>
Empty file added Logos-Xcode/src/Logos.xc
Empty file.
15 changes: 15 additions & 0 deletions Logos-Xcode/src/Logos.xcspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Logos.xcspec: Xcode file type for Logos
*
**/

(
{
Type = FileType;
Identifier = sourcecode.logos;
BasedOn = sourcecode;
Name = "Logos file";
Extensions = ( xm );
Language = "xcode.lang.logos";
}
)
74 changes: 74 additions & 0 deletions Logos-Xcode/src/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

#
# pr0crustes version.
# Edited version of the work of Tiago Bastos and Alex Karahalios.
# Last edited 15/9/2018
#

set -e

# Path were this script is located
Script_Path="/opt/MonkeyDev/Logos-Xcode/src"
# "$(dirname "$(realpath "$0")")"

# Checks if has enought permission
echo "Checking Permissions..."
if [ $EUID -ne 0 ]; then
echo "$0 needs to be run as root."
echo " Check README for info."
echo " Aborting..."
exit 2
fi

# Assumes Xcode 4+.
echo "Checking Xcode..."
XCODE_MAJOR_VERSION=`xcodebuild -version | awk 'NR == 1 {print int($2)}'`
if [ "$XCODE_MAJOR_VERSION" -lt "4" ]; then
echo "Xcode 4+ not found."
exit 1
fi

# Check if Logos.xclangspec is present in the same folder
echo "Finding Logos.xclangspec..."
if [ ! -f $Script_Path/Logos.xclangspec ]; then
echo "Logos.xclangspec was not found."
echo "You probably forgot to run 'python(3) xclangspec_generator.py'"
exit 1
fi


echo "It's highly recommended that, if you are installing for the first time, you make a backup of the folder /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources"
while true; do
read -p "Do you wish to continue? (Y)es, (N)o " yn
case $yn in
[Yy]*)
# This framework is found withing the Xcode.app package and is used when Xcode is a monolithic install (all contained in Xcode.app)
DVTFountain_Path="/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/"

# Backup
cp "$DVTFountain_Path/DVTFoundation.xcplugindata" "$DVTFountain_Path/DVTFoundation.xcplugindata.bak"

# Now merge in the additonal languages to DVTFoundation.xcplugindata
echo "Merging..."
/usr/libexec/PlistBuddy "$DVTFountain_Path/DVTFoundation.xcplugindata" -c "Merge $Script_Path/AdditionalLanguages.plist plug-in:extensions"

# Copy in the xclangspecs for the languages (assumes in same directory as this shell script)
cp "$Script_Path/Logos.xclangspec" "$DVTFountain_Path"

# Remove any cached Xcode plugins
rm -rf /private/var/folders/*/*/*/com.apple.DeveloperTools/*/Xcode/PlugInCache.xcplugincache

# Final message
echo "Sucessfully Installed."
echo "Syntax coloring must be manually selected from the Editor - Syntax Coloring menu in Xcode."
exit 0
;;
[Nn]*)
echo "Exiting..."
exit 1
;;
*)
;;
esac
done
91 changes: 91 additions & 0 deletions Logos-Xcode/src/xclangspec_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'''
#
# Run with python3
# Script that generates the Logos xclangspec
#
# xclangspec_generator is a script created by pr0crustes (https://github.com/pr0crustes)
# that is provided as it is, without any warranty.
# pr0crustes @ 2018 - all rights reserved.
#
'''
import os

global_new_keywords = [
"// Start Logos Keywords",
"%group",
"%hook",
"%new",
"%subclass",
"%property",
"%end",
"%config",
"%hookf",
"%ctor",
"%dtor",
"%init",
"%class",
"%c",
"%orig",
"%log",
"// End Logos Keywords",
"// Start Other Keywords",
"NSLog",
"NSString",
"NSInteger",
"NSObject",
"// End Other Keywords"
]


global_ident1 = "Words = ("
global_ident2 = "Chars = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\";"
global_ident3 = "StartChars = \"@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\";"


class XClangGenerator(object):

def __init__(self):
self.objc_spec_file = "/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/ObjectiveC.xclangspec"
self.objc_spec_content = []
self.new_lines = []

def __get_loaded_file(self):
print("Reading File...")
for line in open(self.objc_spec_file, 'r'):
if line.strip() and not line.strip().startswith("/"):
self.objc_spec_content.append(line)

def __get_parsed_file(self):
print("Parsing File...")
for i in range(len(self.objc_spec_content)):
line = self.objc_spec_content[i].replace("objc", "logos")
self.new_lines.append(line)
if global_ident1 in line and i > 3 and global_ident2 in self.objc_spec_content[i-1] and global_ident3 in self.objc_spec_content[i-2]:
print("Inserting Logos Keywords Into New File...")
for new_word in global_new_keywords:
if new_word.strip().startswith("//"):
self.new_lines.append("\t\t\t\t" + new_word + "\n")
else:
self.new_lines.append("\t\t\t\t\"" + new_word + "\",\n")

def __save_file(self):
print("Saving New File...")
with open("Logos.xclangspec", "w") as file:
file.write("// Logos xclangspec was generated by spec_gen\n")
file.write("// Script made by pr0crustes\n")
for line in self.new_lines:
file.write(line)

def execute(self):
self.__get_loaded_file()
self.__get_parsed_file()
self.__save_file()
print("XClangSpec Generator was successfully runned.")


if __name__ == '__main__':

os.rename("/opt/MonkeyDev/Logos-Xcode/src/Logos.xc", "/opt/MonkeyDev/Logos-Xcode/src/Logos.xclangspec")
gen = XClangGenerator()
gen.execute()

Binary file removed Resource/TargetApp.app/AppIcon60x60@2x.png
Binary file not shown.
Binary file removed Resource/TargetApp.app/AppIcon60x60@3x.png
Binary file not shown.
Binary file removed Resource/TargetApp.app/Assets.car
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed Resource/TargetApp.app/Info.plist
Binary file not shown.
1 change: 0 additions & 1 deletion Resource/TargetApp.app/PkgInfo

This file was deleted.

Binary file removed Resource/TargetApp.app/TargetApp
Binary file not shown.
60 changes: 58 additions & 2 deletions bin/md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export DefaultDeviceIP="localhost"
#默认端口号
export DefaultDevicePort="22"



export userName="${SUDO_USER-$USER}"
export userGroup=`id -g $userName`
export userHome=`eval echo ~$userName`
Expand Down Expand Up @@ -652,6 +654,19 @@ function Processor()
if [[ $currentDirectory =~ "Build/Products" ]] || [[ $currentDirectory =~ "Build/Intermediates" ]] || [[ $currentDirectory =~ "Index/DataStore" ]] || [[ $currentDirectory =~ "/LatestBuild/" ]]; then
return
fi

if [[ -f "$currentDirectory" ]] || [[ "${currentDirectory#*.}" == "mmi" ]]; then

specialDir="$(dirname "${currentDirectory}")"
specialFile="$(basename "${currentDirectory}")"

# used for .xmi files
echo "Logos Processor: $specialFile -> ${specialFile%.*}.mm..."
logosStdErr=$(("$logosProcessor" "$currentDirectory" > "${currentDirectory%.*}.mm") 2>&1) || \
panic $? "Failed Logos Processor: $logosStdErr"

return
fi

for file in `ls "$currentDirectory"`;
do
Expand Down Expand Up @@ -708,7 +723,48 @@ function xcodeBuildPhase_Logos() # no args

# for each *.xm project file, use Logos Processor to generate *.mm file

Processor "$logosProcessor" "$PROJECT_DIR"

if [[ "$MonkeyDevUseXMI" == "YES" ]]; then

# Search for the .xmi file
pathToXMI=$(find "$PROJECT_DIR" -type f -name "*.xmi" | head -n 1)
if [[ "$pathToXMI" == "" ]]; then
panic 1 "MonkeyDevUseXMI Setting is enabled, but no .xmi file found."
fi

#Preprocess .xmi and output to .mmi
specialDir="$(dirname "${pathToXMI}")"
specialFile="$(basename "${pathToXMI}")"
tempPathToMMI="$specialDir/${specialFile%.*}.mmi.temp"
pathToMMI="$specialDir/${specialFile%.*}.mmi"

# Replace '#import' with '//#import'
mod1Err=$((sed -e 's/#import/\/\/#import/g' "$pathToXMI" > "$tempPathToMMI") 2>&1) || \
panic $? "Replacing '#import' with '//#import' failed: $mod1Err"

# Preprocessing
logosStdErr=$((g++ -E -CC -P -x objective-c "$tempPathToMMI"> "$pathToMMI") 2>&1) || \
panic $? "Failed Preprocessing .xmi: $logosStdErr"

# Delete Temp File
rm "$tempPathToMMI"

# Replace '//#import' with '#import' (using perl bc sed creates a backup file)
mod2Err=$((perl -pi -e 's/\/\/#import/#import/g' "$pathToMMI") 2>&1) || \
panic $? "Replacing '//#import' with '#import' failed: $mod2Err"

Processor "$logosProcessor" "$pathToMMI"

# Delete .MMI File
rm "$pathToMMI"

else
Processor "$logosProcessor" "$PROJECT_DIR"
fi





echo "Note: If any *.xm or *.x file generated above by the Logos Processor (${projectXmFiles[@]}) is not being compiled below, then you must add it to the Xcode project to be compiled."

Expand Down Expand Up @@ -849,7 +905,7 @@ function xcodeBuildPhase() # no args
runFuncOnDevice "respring" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort"
else
echo "killall -9 $MonkeyDevkillProcessOnInstall"
runFuncOnDevice "killall -9 $MonkeyDevkillProcessOnInstall || echo skip" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort"
runFuncOnDevice "killall -9 $MonkeyDevkillProcessOnInstall || echo skip" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort"
fi
fi

Expand Down
14 changes: 14 additions & 0 deletions bin/md-install
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ function writeDictToSpecification(){ #args: filePath, content
/usr/libexec/PlistBuddy -x -c "merge $tempfile 0" "$filePath" > /dev/null
}

# 安裝Logos語法高亮
function installXcode10LogosSupports(){

echo "install Xcode10 Logos Supports..."
chmod +x $MonkeyDevPath/Logos-Xcode/src/xclangspec_generator.py
python $MonkeyDevPath/Logos-Xcode/src/xclangspec_generator.py
chmod +x $MonkeyDevPath/Logos-Xcode/src/install.sh
sudo sh -x $MonkeyDevPath/Logos-Xcode/src/install.sh

}


# start it
# 创建/opt/MonkeyDev
mkdir -p "$MonkeyDevPath" || \
Expand Down Expand Up @@ -374,4 +386,6 @@ if [[ $hasProductTypeForCommandLineTool != "true" ]]; then
writeDictToSpecification "$specificationFile" "$toolDict"
fi

installXcode10LogosSupports

exit 0
Loading