태그 보관물: tip

Bare git으로 부터 source code 복사하기

Android에 기반한 project를 repo로 mirror로 만들때는 –mirror option을 주어서 bare git을 만든다(지난 posting 참조). 만약 이렇게 만들어진 bare repository로 부터 일반적인 형태의 source repository를 생성하려 한다면 어떻게 해야 할까? 이 posting에서는 git-daemon등을 설치 하지 않고 local에 있는 bare git으로 부터 source 구조를 만들어 내는 방법을 설명한다.

Repo Init

$ repo init help
Usage: repo init -u url [options]

repo init 명령을 수행할 때 -u 뒤에 url을 적어준다. 일반적으로 이 부분에 ‘git://’이나 ‘ssh://’ protocol로 시작하는 주소를 적지만 우리가 하려는 것은 file 복사 이므로 ‘file://’을 적어서 repo init을 수행한다.

$ repo init -u file://PATH_TO_MIRROR -b BRANCH -m MANIFEST_XML

놀랍게도(!) init이 수행되면서 .repo directory가 생성된다.

Fetch Address 수정

.repo/manifests에서 fetch address를 가지고 있는 xml file을 찾아서 접근 address를 file경로로 수정한다.

  <!-- 
  <remote name="REMOTE_NAME" fetch="ssh://SERVER_IP" review="REVIEW_ADDRESS:8080"/> 
  -->
  <remote name="REMOTE_NAME" fetch="file://<path_to_mirror>/" review="REVIEW_ADDRESS:8080"/>

init이 완료 되고 난 후에는 일반적인 것과 같이 repo sync 명령어를 수행하면 된다. file://로 수정한 xml file들을 원래 상태로 되돌리는 건 다들 아실테고 … 😉

bash에서 자동완성할 때 공백 문자 들어가는 문제

언제부터 였는지는 모르겠지만, ubuntu (12.04)의 bash shell에서 자동완성을 하려고 <tab> key를 누르면 공백문자가 하나씩 추가되는 문제가 생겼다. 여러 단계로 되어 있는 file에 접근하려고 할 때 매번 <tab> key를 누르고 <backspace>로 공백문자를 지워줘야 하기 때문에 무척 불편했는데 좀 찾아보니 bash_completion file을 수정해서 이 문제를 해결 할 수 있었다.

sudo vi /etc/bash_completion
# makeinfo and texi2dvi are defined elsewhere.
for i in a2ps awk bash bc bison cat colordiff cp csplit \
    curl cut date df diff dir du enscript env expand fmt fold gperf gprof \
    grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
    mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
    sed seq sha{,1,224,256,384,512}sum shar sort split strip tac tail tee \
    texindex touch tr uname unexpand uniq units vdir wc wget who; do
    have $i && complete -F _longopt -o default $i
done
unset i

1587 line의 ‘_longopt -o default‘ 부분을 다음과 같이’ _longopt -o filenames‘로 변경한 후 다시 shell을 다시 열고 사용하면 된다.

 have $i && complete -F _longopt -o filenames $i

(참조 링크)

Android NDK build architecture 변경하기

아무 설정 없이 ndk를 build 하면 다음과 같이 arm용 library가 만들어진다.

$ <NDK_PATH>/ndk-build 
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Compile thumb  : hello-jni <= hello-jni.c
SharedLibrary  : libhello-jni.so
Install        : libhello-jni.so => libs/armeabi/libhello-jni.so
$ file obj/local/armeabi/libhello-jni.so 
obj/local/armeabi/libhello-jni.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped

NDK에서 build되는 binary의 architecture를 변경하려면 APP_ABI를 선언해 주어야 하는데, Android.mk에 추가해서는 제대로 동작하지 않는다. JNI directory 아래에 Application.mk file을 만들고  APP_ABI값에 build할 architecture를 설정해 준다. 다음은 x86 바이너리를 생성하는 예제이다.

$ cat jni/Application.mk 
APP_ABI := x86
$ <NDK_PATH>/ndk-build 
Gdbserver      : [x86-4.6] libs/x86/gdbserver
Gdbsetup       : libs/x86/gdb.setup
Compile x86    : hello-jni <= hello-jni.c
SharedLibrary  : libhello-jni.so
Install        : libhello-jni.so => libs/x86/libhello-jni.so
$ file obj/local/x86/libhello-jni.so 
obj/local/x86/libhello-jni.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped

* Build에 사용되는 toolchain은 <NDK_PATH>/toolchains/<architecture>-<version>의 형태로 위치한다.