Created
September 26, 2010 20:34
-
-
Save fornwall/598299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# attach-android-source.py - script to attach android source to a SDK folder using symlinks | |
# See http://mobilepearls.com/labs/viewing-android-source-code-in-eclipse/ | |
# | |
# Use as: | |
# python attach-android-src.py $PATH_TO_SRC $PATH_TO_SDK_PLATFORM | |
# where $PATH_TO_SRC is the path to an android source checkout (the folder you run "repo init" in if | |
# you follow the instructions on http://source.android.com/source/download.html) and | |
# $PATH_TO_SDK_PLATFORM is to a platform folder inside the android sdk folder | |
import os, re, sys | |
def die(message): | |
sys.stderr.write("Error: " + message + "\n") | |
sys.exit(1) | |
if len(sys.argv) != 3: die("Arguments needed (sdk and platform path)") | |
repo_path = os.path.abspath(sys.argv[1]) | |
platform_path = os.path.abspath(sys.argv[2]) | |
sources_path = os.path.join(platform_path, 'sources') | |
package_regexp = re.compile('\s*package\s+([a-zA-Z0-9\._]+);') | |
if not os.path.exists(repo_path): die("repo path does not exist: " + repo_path) | |
if not os.path.exists(platform_path): die("Platform path does not exist: " + platform_path) | |
for dirpath, dirnames, filenames in os.walk(repo_path): | |
for filename in filenames: | |
if not filename.endswith('.java'): continue | |
filepath = os.path.join(dirpath, filename) | |
if 'android_stubs_current_intermediates' in filepath: continue | |
with open(filepath) as f: | |
for line in f: | |
match = package_regexp.match(line) | |
if not match: continue | |
relpath = match.group(1).replace('.', '/') + '/' + filename | |
destination_file = os.path.join(sources_path, relpath) | |
destination_dir = os.path.dirname(destination_file) | |
if not os.path.exists(destination_dir): os.makedirs(destination_dir) | |
if os.path.exists(destination_file): os.remove(destination_file) | |
os.symlink(filepath, destination_file) | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# checkout-android.sh - shell script illustrating how to checkout the android source code | |
# Extracted from http://source.android.com/source/download.html | |
REPO_DIR=~/android-src # change this to your liking | |
curl http://android.git.kernel.org/repo > ~/bin/repo | |
chmod a+x ~/bin/repo | |
mkdir $REPO_DIR | |
cd $REPO_DIR | |
repo init -u git://android.git.kernel.org/platform/manifest.git | |
repo sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment