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