-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.diff
More file actions
107 lines (97 loc) · 4.96 KB
/
Copy pathmain.diff
File metadata and controls
107 lines (97 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- PCART-original/main.py 2026-04-15 21:36:13
+++ PCART-modified/main.py 2026-04-15 21:36:13
@@ -32,7 +32,7 @@
# @return (ansDict,fileRelativePath,invokedAPINum) ansDict: API parameter compatibility issue detection and repair results; fileRelativePath: The detected and repaired project file; invokedAPINum: The number of invoked APIs
def backwardTask(args):
ansDict={} #保存每个文件处理的情况
- projName,libName,file,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath,lock,sharedDict,coverSet=args
+ projName,libName,file,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath,lock,sharedDict,coverSet,config=args
# fileName=file.split('/')[-1][0:-3]
fileName = os.path.basename(file)[:-3]
@@ -58,6 +58,13 @@
invokedAPINum=len(callAPIDict)
# errorLog=f"Report/{projName}_fixed_log.txt"
errorLog = os.path.join('Report', f'{projName}_fixed_log.txt')
+ if config:
+ _subDir = os.path.dirname(config)
+ _logDir = os.path.join('Log', 'findDiffer', _subDir)
+ else:
+ _logDir = os.path.join('Log', 'findDiffer')
+ os.makedirs(_logDir, exist_ok=True)
+ logErrorLog = os.path.join(_logDir, f'{projName}_fixed_log.txt')
for key,formatAPI in callAPIDict.items():
errLst=[] #记录错误信息
ansDict[key]={}
@@ -102,7 +109,22 @@
ansDict[key][f"Definition @{targetVersion} <{targetMatch['matchMethod']}>"]=str(targetMatch['match'])
#step4:变更分析,若不兼容则返回需要修复的操作
- repairLst=isCompatible(currentMatch,targetMatch) #repairLst中每个元素都是tuple
+ isCompatibleContext = {
+ 'callAPI': callAPI,
+ 'currentVersion': currentVersion,
+ 'targetVersion': targetVersion,
+ 'fileRelativePath': fileRelativePath,
+ 'lineNum': lineNum,
+ 'config': config,
+ # findDifferHybrid 所需的额外字段
+ 'apiCall': callAPI,
+ 'oldVersion': f"{libName}@{currentVersion}",
+ 'newVersion': f"{libName}@{targetVersion}",
+ 'jsonPrefix': '.',
+ 'oldMatchDict': currentMatch,
+ 'newMatchDict': targetMatch,
+ }
+ repairLst=isCompatible(currentMatch,targetMatch,context=isCompatibleContext) #repairLst中每个元素都是tuple
if repairLst==None:
ansDict[key]['Compatible']="Unknown"
if len(errLst)>0:
@@ -110,6 +132,7 @@
# print(errorMsg)
with lock:
updateErrorLst(errorLog,errLst)
+ updateErrorLst(logErrorLog,errLst)
continue
if len(repairLst)==0: #若返回修复字典的个数为零,则一定是兼容的
@@ -138,6 +161,7 @@
# print(errorMsg)
with lock:
updateErrorLst(errorLog,errLst)
+ updateErrorLst(logErrorLog,errLst)
#将修改操作更新到代码源文件
@@ -159,7 +183,7 @@
# @param targetEnv Target version's virtual environment
# @param runCommand The run command of the project
# @param runPath The relative path of the run file
-def backward(projPath,libName,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath):
+def backward(projPath,libName,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath,config):
pathObj=Path('DF')
pathObj.getPath(projPath)
filePath=[it for it in pathObj.path if it.endswith('py')] #保留项目中的.py文件
@@ -224,7 +248,7 @@
manager=Manager()
lock=manager.Lock() #创建一个共享锁
sharedDict=manager.dict() #创建一个共享字典
- tasks=[(projName,libName,file,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath,lock,sharedDict,coverSet) for file in filePath]
+ tasks=[(projName,libName,file,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath,lock,sharedDict,coverSet,config) for file in filePath]
pool=Pool(processes=1)
resultLst=pool.map(backwardTask,tasks)
pool.close() #关闭进程池,使其不再接受新的任务
@@ -232,6 +256,14 @@
runCommand=f"python {runCommand}"
# save2txt(resultLst,libName,runCommand,f"Report/{projName}.txt")
save2txt(resultLst, libName, runCommand, os.path.join('Report', f'{projName}.txt'))
+
+ if config:
+ subDir = os.path.dirname(config)
+ logDir = os.path.join('Log', 'findDiffer', subDir)
+ else:
+ logDir = os.path.join('Log', 'findDiffer')
+ os.makedirs(logDir, exist_ok=True)
+ save2txt(resultLst, libName, runCommand, os.path.join(logDir, f'{projName}.txt'))
@@ -254,7 +286,7 @@
print("Code preprocess complete")
#执行主逻辑
- backward(projPath,libName,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath)
+ backward(projPath,libName,currentVersion,currentEnv,targetVersion,targetEnv,runCommand,runPath,config)
end=time.time()
print(f"Total run time={int(end-start)}s")