下载Android源代码时,出现这个错误
Fetching project platform/hardware/intel/img/psb_video
Fetching projects: 99% (452/456) Fetching project platform/external/vogar
Fetching projects: 100% (456/456), done.
error: unable to create file tests/P_str_escape/str\\escape.rs (No such file or directory)
正在检出文件: 100% (541/541), 完成.
Traceback (most recent call last):
File "/cygdrive/d/AndroidSrc/android6.0/.repo/repo/main.py", line 531, in
_Main(sys.argv[1:])
File "/cygdrive/d/AndroidSrc/android6.0/.repo/repo/main.py", line 507, in _Main
result = repo._Run(argv) or 0
File "/cygdrive/d/AndroidSrc/android6.0/.repo/repo/main.py", line 180, in _Run
result = cmd.Execute(copts, cargs)
File "/cygdrive/d/AndroidSrc/android6.0/.repo/repo/subcmds/sync.py", line 762, in Execute
project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
File "/cygdrive/d/AndroidSrc/android6.0/.repo/repo/project.py", line 1246, in Sync_LocalHalf
self._InitWorkTree(force_sync=force_sync)
File "/cygdrive/d/AndroidSrc/android6.0/.repo/repo/project.py", line 2387, in _InitWorkTree
raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree
tests
在哪个目录从log来看,
error: unable to create file tests/P_str_escape/str\escape.rs (No such file or directory)
这个文件路径tests/P_str_escape/str\\escape.rs
比较怪异,没有创建成功。
但是这个文件的具体路径是什么?tests
目录在哪个目录中?
如果找到tests
所在的目录,可以尝试在那个目录中按照tests/P_str_escape/str\\escape.rs
要求创建tests/P_str_escape/str/escape.rs
从log来看,.repo/repo/project.py
是要关注的地方,其2387行代码如下:
raise GitError("cannot initialize work tree")
其所在的函数为_InitWorkTree
_InitWorkTree
完整的代码如下:
def _InitWorkTree(self, force_sync=False):
dotgit = os.path.join(self.worktree, '.git')
print("dotgit is {0}".format(dotgit))
print(self.gitdir)
init_dotgit = not os.path.exists(dotgit)
try:
if init_dotgit:
os.makedirs(dotgit)
self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True,
copy_all=False)
try:
self._CheckDirReference(self.gitdir, dotgit, share_refs=True)
except GitError as e:
if force_sync:
try:
shutil.rmtree(dotgit)
return self._InitWorkTree(force_sync=False)
except:
raise e
raise e
if init_dotgit:
_lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId())
cmd = ['read-tree', '--reset', '-u']
cmd.append('-v')
cmd.append(HEAD)
if GitCommand(self, cmd).Wait() != 0:
raise GitError("cannot initialize work tree")
self._CopyAndLinkFiles()
except Exception:
if init_dotgit:
shutil.rmtree(dotgit)
raise
为了找到当前出错时,git正在处理哪个目录,我在_InitWorkTree
函数中加了2句log信息:
print("dotgit is {0}".format(dotgit))
print(self.gitdir)
def _InitWorkTree(self, force_sync=False):
dotgit = os.path.join(self.worktree, '.git')
print("dotgit is {0}".format(dotgit))
print(self.gitdir)
init_dotgit = not os.path.exists(dotgit)
try:
if init_dotgit:
os.makedirs(dotgit)
...
...
...
打印出来的log如下:
dotgit is /cygdrive/d/AndroidSrc/android6.0/frameworks/compile/slang/.git
/cygdrive/d/AndroidSrc/android6.0/.repo/projects/frameworks/compile/slang.git
error: unable to create file tests/P_str_escape/str\\escape.rs (No such file or directory)
略
可见当前git正在获取frameworks/compile/slang
目录下的文件。
repo
的 --trace
参数还有一个方法可以确定当前git正在处理哪个目录:
即用repo
的 --trace
参数
repo --trace sync
打印结果如下:
: parsing /cygdrive/d/AndroidSrc/android6.0/.repo/projects/frameworks/compile/slang.git/config
: export GIT_DIR=/cygdrive/d/AndroidSrc/android6.0/.repo/projects/frameworks/compile/slang.git
: git rev-parse --verify refs/tags/android-6.0.1_r1^0 1>| 2>|
: cd /cygdrive/d/AndroidSrc/android6.0/frameworks/compile/slang
: git read-tree --reset -u -v HEAD 1>| 2>|
error: unable to create file tests/P_str_escape/str\\escape.rs (No such file or directory)
可以看到,当前git正在处理 frameworks/compile/slang
目录。
tests/P_str_escape/str\\escape.rs
实际要创建的文件并不是tests/P_str_escape/str\\escape.rs
而是tests/P_str_escape/str/escape.rs
这一级目录已经存在了,只需要创建str
目录,并在str
目录中创建 escape.rs
文件(文件内容为空)。
再次repo --trace sync
可以下载到完整的Android源代码了。
PS: 我下载的是Android 6.0.1 r1版本的代码:
repo init -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r1
repo --trace sync