xref: /aosp_15_r20/build/bazel/json_module_graph/findModulesCrossPkgBoundary.jq (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1# CMD: Finds all modules whose input files cross package boundaries.
2
3include "library";
4
5def getBlueprintDirPaths:
6[.[] | .Blueprint | getDirPath] | sort_by(.) | unique | map({(.):""}) | add
7;
8
9def getNonNullActionModules:
10[.[] | select(nonNullAction)]
11;
12
13def getOutputsOfModule:
14[.Module.Actions | .[] | .Outputs | if . == null then [] else . end | .[]]
15;
16
17def getOutputsOfModules($nonNullActionModules):
18$nonNullActionModules | map({(.Name):getOutputsOfModule}) | add
19;
20
21def getDepOutputs($outputsOfModules):
22. as $depName |
23if in($outputsOfModules) then ($outputsOfModules | ."\($depName)")
24else [] end | .[]
25;
26
27def getDepOutputsOfModule($outputsOfModules):
28[.Deps | .[] | .Name | getDepOutputs($outputsOfModules)]
29| map({(.):""}) | add
30;
31
32def isDirPathMatch($blueprintDirPath; $allBlueprintDirPaths):
33  def _isDirPathMatch($blueprintDirPath; $allBlueprintDirPaths):
34    # True if there's a Blueprint file in the path and the path isn't
35    # equal to $blueprintDirPath of the module.
36    if in($allBlueprintDirPaths) and . != $blueprintDirPath then true
37    # Stops checking if the current path is already the $blueprintDirPath.
38    elif . == $blueprintDirPath then false
39    # Usually it should not hit this logic as it stops when the path is
40    # equal to $blueprintDirPath.
41    elif (contains("/") | not) then false
42    else (getDirPath | _isDirPathMatch($blueprintDirPath; $allBlueprintDirPaths))
43    end
44  ;
45  _isDirPathMatch($blueprintDirPath; $allBlueprintDirPaths)
46;
47
48def isActionInputMatch($outputsOfModules; $allBlueprintDirPaths):
49. as $moduleVariant | .Blueprint | getDirPath as $blueprintDirPath |
50$moduleVariant | getDepOutputsOfModule($outputsOfModules) as $depOutputs |
51$moduleVariant | getActionInputs | select(in($depOutputs) | not) |
52select(startswith($blueprintDirPath)) | getDirPath |
53isDirPathMatch($blueprintDirPath; $allBlueprintDirPaths)
54;
55
56getBlueprintDirPaths as $allBlueprintDirPaths |
57getNonNullActionModules as $nonNullActionModules |
58getOutputsOfModules($nonNullActionModules) as $outputsOfModules |
59[$nonNullActionModules | .[] |
60select(isActionInputMatch($outputsOfModules; $allBlueprintDirPaths)) |
61.Name] | sort_by(.) | unique
62