@@ -29,7 +29,7 @@ run(Configuration) ->
29
29
]},
30
30
fun grisp_tools_step :collect /1 ,
31
31
fun download /1 ,
32
- {prepare , [
32
+ {fun prepare / 1 , [
33
33
fun clean /1 ,
34
34
fun patch /1 ,
35
35
{copy , [
@@ -78,6 +78,26 @@ download(#{otp_version := {_,_,_,Ver}} = State0) ->
78
78
event (mapz :deep_put ([build , download ], false , State0 ), ['_skip' ])
79
79
end .
80
80
81
+ prepare (S0 ) ->
82
+ Drivers = maps :to_list (mapz :deep_get ([build , overlay , drivers ], S0 )),
83
+ NIFs = maps :to_list (mapz :deep_get ([build , overlay , nifs ], S0 )),
84
+ DriverFiles = [#{name => filename :basename (N , " .c" )} || {N , _P } <- Drivers ],
85
+ NIFFiles = [#{name => filename :basename (N , " .c" )} || {N , _P } <- NIFs ],
86
+
87
+ DrvPatchLineCount = 10 + length (DriverFiles ),
88
+ NifPatchLineCount = 9 + length (NIFFiles ),
89
+
90
+ Context = #{
91
+ erts_emulator_makefile_in => #{
92
+ driver_lines => DrvPatchLineCount ,
93
+ nif_lines => NifPatchLineCount ,
94
+ total_lines => DrvPatchLineCount + NifPatchLineCount ,
95
+ drivers => DriverFiles ,
96
+ nifs => NIFFiles
97
+ }
98
+ },
99
+ mapz :deep_put ([build , context ], Context , S0 ).
100
+
81
101
clean (#{build := #{flags := #{clean := true }}} = State0 ) ->
82
102
State1 = event (State0 , ['_run' ]),
83
103
BuildPath = mapz :deep_get ([paths , build ], State1 ),
@@ -89,25 +109,9 @@ clean(#{build := #{flags := #{clean := true}}} = State0) ->
89
109
clean (State0 ) ->
90
110
event (State0 , ['_skip' ]).
91
111
92
- patch (#{build := #{overlay := #{patches := Patches }}} = State0 ) ->
112
+ patch (#{build := #{overlay := #{patches := Patches }}} = S0 ) ->
93
113
Sorted = lists :sort (maps :to_list (Patches )),
94
-
95
- Drivers = maps :to_list (mapz :deep_get ([build , overlay , drivers ], State0 )),
96
- NIFs = maps :to_list (mapz :deep_get ([build , overlay , nifs ], State0 )),
97
-
98
- DrvPatchLineCount = 10 + length (Drivers ),
99
- NifPatchLineCount = 9 + length (NIFs ),
100
-
101
- Context = #{
102
- erts_emulator_makefile_in => #{
103
- driver_lines => DrvPatchLineCount ,
104
- nif_lines => NifPatchLineCount ,
105
- total_lines => DrvPatchLineCount + NifPatchLineCount ,
106
- drivers => [#{name => filename :basename (N , " .c" )} || {N , _P } <- Drivers ],
107
- nifs => [#{name => filename :basename (N , " .c" )} || {N , _P } <- NIFs ]
108
- }
109
- },
110
- lists :foldl (fun apply_patch /2 , mapz :deep_put ([build , patch_context ], Context , State0 ), Sorted ).
114
+ lists :foldl (fun apply_patch /2 , S0 , Sorted ).
111
115
112
116
files (State0 ) -> copy_files (State0 , files , " " ).
113
117
@@ -222,12 +226,11 @@ build_step(Command, Opts, State0) ->
222
226
223
227
% --- Internal ------------------------------------------------------------------
224
228
225
- apply_patch ({Name , #{ source : = File } = Patch }, State0 ) ->
229
+ apply_patch ({Name , Patch }, State0 ) ->
226
230
Dir = mapz :deep_get ([paths , build ], State0 ),
227
- Context = mapz :deep_get ([build , patch_context ], State0 ),
228
- Rendered = grisp_tools_template :render (File , Context ),
229
- ok = file :write_file (filename :join (Dir , Name ), Rendered ),
230
- State4 = case shell (State0 , " git apply " ++ Name ++ " --ignore-whitespace --reverse --check" ,
231
+ Context = mapz :deep_get ([build , context ], State0 ),
232
+ grisp_tools_util :write_file (Dir , Patch , Context ),
233
+ State4 = case shell (State0 , [" git apply " , Name , " --ignore-whitespace --reverse --check" ],
231
234
[{cd , Dir }, return_on_error ]) of
232
235
{{ok , _Output }, State1 } ->
233
236
event (State1 , [{skip , Patch }]);
@@ -249,9 +252,10 @@ sort_files(Apps, Files) ->
249
252
end ,
250
253
lists :sort (SortFiles , [F || {_ , F } <- maps :to_list (Files )]).
251
254
252
- copy_file (Root , #{ target : = Target , source : = Path } = File , State0 ) ->
255
+ copy_file (Root , File , State0 ) ->
253
256
State1 = event (State0 , [File ]),
254
- file :copy (Path , filename :join (Root , Target )),
257
+ Context = mapz :deep_get ([build , context ], State0 ),
258
+ grisp_tools_util :write_file (Root , File , Context ),
255
259
State1 .
256
260
257
261
run_hooks (S0 , Type , Opts ) ->
0 commit comments