Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rdp #15

Open
wants to merge 37 commits into
base: sheriff/show-only-api-txns
Choose a base branch
from
Open

Rdp #15

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e198009
Remove warning from file not found
piyushgarg-juspay Jun 24, 2024
4fb7188
Add rule wise exception list
piyushgarg-juspay Jun 24, 2024
8eb0372
fix getting exception rules in errors
piyushgarg-juspay Jun 24, 2024
baf9e26
Add module exceptions to the rules
piyushgarg-juspay Jun 24, 2024
9238e40
Fix configurable rules and module exceptions
piyushgarg-juspay Jun 24, 2024
f0f0c9f
moved rdp and large-records for ordering
Jun 25, 2024
0fbb3a8
fixed tests
Jun 25, 2024
0b747fb
tests fixed
Jun 25, 2024
43bb027
handled
Jun 25, 2024
c62efb1
build fix
Jun 25, 2024
6db5657
bumped large-records
Jun 25, 2024
9c51929
Major changes related to exceptions
piyushgarg-juspay Jun 25, 2024
493e967
Merge branch 'main' of github.com:juspay/spider into sheriff/enhancem…
piyushgarg-juspay Jun 25, 2024
4f02488
adding srcLoc
Jun 26, 2024
66663b6
fixed srcLoc
Jun 26, 2024
11d0c2b
added srcSpan in name to have uniqueness
Jun 26, 2024
87129b2
build issue
Jun 27, 2024
f1cbce9
merging code_string from parser dump
Jun 27, 2024
b4e4d09
creating dir
Jun 27, 2024
e8807c4
added cabal flag enable-lr-plugins
Jun 27, 2024
f72dca1
added cabal flag enable-lr-plugins for fieldInspector
Jun 27, 2024
844b7e8
evaluate added in fdep
Jun 27, 2024
0cfa17a
Add option to use file read IO operation to extract the original code…
piyushgarg-juspay Jun 28, 2024
e2bfbc9
removed beautified strings collection from TC
Jul 1, 2024
f6906c3
fieldInspector cabal issue
Jul 1, 2024
c3a0ea4
filtering duplicates
Jul 4, 2024
ed18ef5
handled case extraction of types
Jul 4, 2024
0f9cf85
changed to Text and removed forkIO at toplevel
Jul 5, 2024
2ad5b7c
added SHOULD_FORK env
Jul 5, 2024
9e4e692
Merge pull request #16 from juspay/sheriff/enhancements
aravindgopall Jul 6, 2024
31f3569
enabled forkIO in fdep bydefault
Jul 10, 2024
460f4f0
moved logs to under env
Jul 10, 2024
fe96532
added python code to merge fdep output
Jul 10, 2024
e84d86a
fixied CPP file path issue
Jul 11, 2024
92e3771
added env to generate fdep GENERATE_FDEP
Jul 12, 2024
5075813
added runClient under try
Jul 12, 2024
8420efa
Merge branch 'main' of https://github.com/juspay/spider into rdp
Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist-*
result
cabal.project.local
cabal.project.local
tmp*
8 changes: 8 additions & 0 deletions fdep/fdep.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ library
, extra
, aeson-pretty
, streamly
, async
, time
, text
, binary
, conduit
, deepseq
, websockets
, network
hs-source-dirs: src
default-language: Haskell2010

Expand Down
118 changes: 118 additions & 0 deletions fdep/fdep_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import json
import os
import concurrent.futures
import sys

base_dir_path = "/tmp/fdep/"
fdep = dict()
def replace_all(text, replacements):
for old, new in replacements:
text = text.replace(old, new)
return text

def get_module_name(base_dir_path, path, to_replace=""):
path = path.replace(base_dir_path, "")
patterns = [
("src/", "src/"),
("src-generated/", "src-generated/"),
("src-extras/", "src-extras/")
]
for pattern, split_pattern in patterns:
if pattern in path:
path = path.split(split_pattern)[-1]
break
module_name = replace_all(path, [("/", "."), (to_replace, "")])
return module_name

def list_files_recursive(directory):
files_list = []
for root, dirs, files in os.walk(directory):
for file in files:
if ".hs.json" in file:
files_list.append(os.path.join(root, file))
return files_list

def process_each_fdep_module(obj,code_string_dict):
local_fdep = {}

def update_nested_key(d,keys, value):
current = d
try:
for key in keys[:-1]:
if current != None:
if current.get(key) == None:
current[key] = {}
current[key]["where_functions"] = {}
else:
if current[key].get("where_functions") == None:
current[key]["where_functions"] = {}
current = current[key]
else:
current = {}
current["where_functions"] = {}
current["where_functions"][keys[-1]] = value
except Exception as e:
print("update_nested_key",e)

for (functionsName,functionData) in obj.items():
if not "::" in functionsName:
fName = functionsName.replace("$_in$","")
srcLoc = functionsName.replace("$_in$","").split("**")[1]
try:
if local_fdep != None and local_fdep.get(fName) == None:
local_fdep[fName] = {}
local_fdep[fName]["function_name"] = fName
local_fdep[fName]["src_loc"] = srcLoc
if code_string_dict.get(fName) != None:
local_fdep[fName]["stringified_code"] = code_string_dict.get(fName,{}).get("parser_stringified_code","")
for i in functionData:
if i != None and i.get("typeSignature") != None:
local_fdep[fName]["function_signature"] = i.get("typeSignature")
elif i != None and i.get("expr") != None:
if local_fdep[fName].get("functions_called") == None:
local_fdep[fName]["functions_called"] = []
local_fdep[fName]["functions_called"].append(i.get("expr"))
else:
local_fdep[fName]["functions_called"] = {}
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(e,fname, exc_tb.tb_lineno)
else:
parentFunctions = functionsName.replace("$_in$","").split("::")
(currentFunctionName,currentFunctionSrcLocation) = parentFunctions[(len(parentFunctions) - 1)].split("**")
currentFunctionDict = dict()
for i in functionData:
if i != None and i.get("typeSignature") != None:
currentFunctionDict["function_signature"] = i.get("typeSignature")
currentFunctionDict["src_log"] = currentFunctionSrcLocation
currentFunctionDict["function_name"] = currentFunctionName
elif i != None and i.get("expr") != None:
if currentFunctionDict.get("functions_called") == None:
currentFunctionDict["functions_called"] = []
currentFunctionDict["functions_called"].append(i.get("expr"))
update_nested_key(local_fdep,parentFunctions,currentFunctionDict)
return local_fdep

def process_fdep_output(file):
code_string_dict = dict()
if os.path.exists(file.replace(".hs.json",".hs.function_code.json")):
with open(file.replace(".hs.json",".hs.function_code.json")) as code_string:
code_string_dict = json.load(code_string)
with open(file,'r') as f:
return process_each_fdep_module(json.load(f),code_string_dict)

files = list_files_recursive("./euler-api-order/tmp/")

with concurrent.futures.ThreadPoolExecutor() as executor:
future_to_file = {executor.submit(process_fdep_output, file): file for file in files}
for future in concurrent.futures.as_completed(future_to_file):
file = future_to_file[future]
try:
module_name = get_module_name(base_dir_path,file,".hs.json")
fdep[module_name] = future.result()
except Exception as e:
print(f"Error reading {file}: {e}")

with open("data.json","w") as f:
json.dump(fdep,f,indent=4)
56 changes: 34 additions & 22 deletions fdep/src/Fdep/Group.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,42 @@ import System.Directory
import System.FilePath
import Control.Monad
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Maybe (fromMaybe)
import Data.List
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.List.Extra (replace,splitOn)
import System.Environment (lookupEnv)
import Fdep.Types
import qualified Data.HashMap.Strict as HM
import Data.Text (Text)
import qualified Data.Text as T


processDumpFile :: String -> FilePath -> IO (String,Map.Map String Function)
processDumpFile baseDirPath path = do
let module_name = replace ".hs.json" ""
$ replace "/" "."
$ if (("src/")) `isInfixOf` (path)
then last (splitOn ("src/") (replace baseDirPath "" path))
else if (("src-generated/")) `isInfixOf` (path)
then last (splitOn ("src-generated/") (replace baseDirPath "" path))
else if (("src-extras/")) `isInfixOf` (path)
then last (splitOn ("src-extras/") (replace baseDirPath "" path))
else replace baseDirPath "" path
putStrLn module_name
content <- B.readFile path
let d = Map.fromList $ filter (\x -> fst x /= "") $ map (\x -> (function_name x,x)) $ fromMaybe [] (Aeson.decode content :: Maybe [Function])
processDumpFile :: Text -> Text -> Text -> IO (Text,Map.Map Text Function)
processDumpFile toReplace baseDirPath path = do
let module_name = T.replace toReplace ""
$ T.replace "/" "."
$ if (("src/")) `T.isInfixOf` (path)
then last (T.splitOn ("src/") (T.replace baseDirPath "" path))
else if (("src-generated/")) `T.isInfixOf` (path)
then last (T.splitOn ("src-generated/") (T.replace baseDirPath "" path))
else if (("src-extras/")) `T.isInfixOf` (path)
then last (T.splitOn ("src-extras/") (T.replace baseDirPath "" path))
else T.replace baseDirPath "" path
parserCodeExists <- doesFileExist (T.unpack $ T.replace ".json" ".function_code.json" path)
contentHM <- if parserCodeExists
then do
parsercode <- B.readFile $ T.unpack $ T.replace ".json" ".function_code.json" path
case Aeson.decode parsercode of
(Just (x :: HM.HashMap Text PFunction)) -> pure $ x
Nothing -> pure $ HM.empty
else pure HM.empty
content <- B.readFile $ T.unpack path
decodedContent <- case Aeson.decode content of
(Just (x :: HM.HashMap Text Function)) -> pure $ x
Nothing -> pure $ HM.empty
let d = Map.fromList $ filter (\x -> fst x /= "") $ map (\(name,x) -> (name,updateCodeString (name) x contentHM)) $ HM.toList $ decodedContent
pure (module_name, d)
where
updateCodeString functionName functionObject contentHM =
case HM.lookup functionName contentHM of
Just val -> functionObject {stringified_code = (parser_stringified_code val)}
Nothing -> functionObject

run :: Maybe String -> IO ()
run bPath = do
Expand All @@ -38,8 +50,8 @@ run bPath = do
Just val -> val
_ -> "/tmp/fdep/"
files <- getDirectoryContentsRecursive baseDirPath
let jsonFiles = filter (\x -> (".hs.json" `isSuffixOf`) $ x) files
functionGraphs <- mapM (processDumpFile baseDirPath) jsonFiles
let jsonFiles = map T.pack $ filter (\x -> (".hs.json" `T.isSuffixOf`) $ T.pack x) files
(functionGraphs) <- mapM (processDumpFile ".hs.json" (T.pack baseDirPath)) jsonFiles
B.writeFile (baseDirPath <> "data.json") (encodePretty (Map.fromList functionGraphs))

getDirectoryContentsRecursive :: FilePath -> IO [FilePath]
Expand Down
Loading