Skip to content

Commit

Permalink
Merge pull request #1081 from smartdevicelink/bugfix/issue_1062_script
Browse files Browse the repository at this point in the history
Add Windows Symlink builder script
  • Loading branch information
bilal-alsharifi authored Jun 4, 2019
2 parents 5601d61 + a2ab690 commit 5b60f51
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ javaSE/local.properties
javaEE/out/
javaEE/build/
javaEE/local.properties
baseAndroid/windows/


##############################
Expand Down
17 changes: 16 additions & 1 deletion android/sdl_android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
import org.apache.tools.ant.taskdefs.condition.Os


android {
compileSdkVersion 28
Expand Down Expand Up @@ -34,10 +36,23 @@ android {
}

sourceSets {
main.java.srcDirs += '../../baseAndroid/src/main/java'
if(Os.isFamily(Os.FAMILY_WINDOWS)){
//The buildWindowsSymLinks task must be run first if this is
//being compiled on a Windows machine
main.java.srcDirs += '../../baseAndroid/windows/src/main/java'
}else{
main.java.srcDirs += '../../baseAndroid/src/main/java'
}
}
}

task buildWindowSymLinks(type:Exec){

workingDir '../../baseAndroid'

commandLine 'cmd', '/c', 'make_symlinks.lnk'
}

dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.smartdevicelink:bson_java_port:1.2.0'
Expand Down
7 changes: 6 additions & 1 deletion baseAndroid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

The Base Android folder symbolically links files used by the Android project that are in the Base folder.

This folder does not need to be imported. Please refer to the installation instructions in the Android, JavaSE, or JavaEE readme's.
This folder does not need to be imported. Please refer to the installation instructions in the Android, JavaSE, or JavaEE README's.

### Windows

The original symbolic links were created for a Unix based operating system. If compiling with Windows the symbolic links will have to be created before compiling the SDL Android project. There is a gradle task added to the `build.gradle` file in the `sdl_android` project that contains a task called `buildWindowSymLinks`. Please note, this task and the supplied script require admin privileges and python to be installed to run. After running this task, Android Studio will recognize the new folder path as the `build.gradle` file contains the necessary conditional that will pick the correct source set to use.

If you are not building the project with the supplied gradle files, you will need to point to the correct path based on the operating system in which you are building the project.
69 changes: 69 additions & 0 deletions baseAndroid/make_symbolic_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import pathlib
from pathlib import Path
import re


def has_admin():
if os.name == 'nt':
try:
# only windows users with admin privileges can read the C:\windows\temp
temp = os.listdir(os.sep.join([os.environ.get('SystemRoot', 'C:\\windows'), 'temp']))
except:
return os.environ['USERNAME'],False
else:
return os.environ['USERNAME'],True
else:
if 'SUDO_USER' in os.environ and os.geteuid() == 0:
return os.environ['SUDO_USER'],True
else:
return os.environ['USERNAME'],False


print('Script Start')

isAdmin = has_admin()
print('Running As Admin - ', isAdmin[1])
if not isAdmin[1]:
print('Can\'t run without admin privileges')
exit()

pathlist = Path('src/').glob('**/*')
# Delete the old directory
os.system('echo y | rmdir windows /s')

for path in pathlist:
path_in_str = str(path)
if os.path.isfile(path):
# check if it's a link to a file or folder
source_link_str = path_in_str
source_link_str = '..\\base\\' + source_link_str
# Remove the root folder for the actual link
print(source_link_str)

testDest = 'windows\\' + path_in_str

directory = pathlib.Path(testDest).parent
print(str(directory))
prefixDir = (re.sub(r"\\+[^\\]*", r"\\..", str(directory))+'\\..\\')[8:] # 8 to remove windows/
# Change all the directory paths into .. so that it will properly move up a folder.

os.system('mkdir %s' % directory)
os.system('icacls %s /grant Everyone:(f)' % directory)

# Now we need to go through each destination directory and understand that's how many ../ we have to add
if path_in_str.endswith('.java'):
print('Java file link found')

command = 'mklink "%s" "%s%s"' % (testDest, prefixDir, source_link_str)
print('Performing command %s' % command)
os.system(command)
else:
print('Directory link found')
command = 'mklink /D "%s" "%s%s"' % (testDest, prefixDir, source_link_str)
print('Performing command %s' % command)
os.system(command)

print('Script Ends')


Binary file added baseAndroid/make_symlinks.lnk
Binary file not shown.
4 changes: 4 additions & 0 deletions baseAndroid/run_as_admin_symlink_script.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pushd %~dp0
python make_symbolic_links.py
popd
pause

0 comments on commit 5b60f51

Please sign in to comment.