Skip to content

Commit a96fe76

Browse files
Merge pull request #1913 from Jarod42/fix_buildmessage_escaping
Fix Codelite/gmake2 `buildmessage` escaping.
2 parents fb89d40 + bd5da71 commit a96fe76

8 files changed

+109
-48
lines changed

modules/codelite/codelite_project.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
_p(3, '<PreBuild>')
326326
p.escaper(codelite.escElementText)
327327
if cfg.prebuildmessage then
328-
local command = os.translateCommandsAndPaths("@{ECHO} " .. cfg.prebuildmessage, cfg.project.basedir, cfg.project.location)
328+
local command = os.translateCommandsAndPaths("@{ECHO} " .. p.quote(cfg.prebuildmessage), cfg.project.basedir, cfg.project.location)
329329
_x(4, '<Command Enabled="yes">%s</Command>', command)
330330
end
331331
local commands = os.translateCommandsAndPaths(cfg.prebuildcommands, cfg.project.basedir, cfg.project.location)
@@ -342,7 +342,7 @@
342342
_p(3, '<PostBuild>')
343343
p.escaper(codelite.escElementText)
344344
if cfg.postbuildmessage then
345-
local command = os.translateCommandsAndPaths("@{ECHO} " .. cfg.postbuildmessage, cfg.project.basedir, cfg.project.location)
345+
local command = os.translateCommandsAndPaths("@{ECHO} " .. p.quote(cfg.postbuildmessage), cfg.project.basedir, cfg.project.location)
346346
_x(4, '<Command Enabled="yes">%s</Command>', command)
347347
end
348348
local commands = os.translateCommandsAndPaths(cfg.postbuildcommands, cfg.project.basedir, cfg.project.location)
@@ -398,7 +398,7 @@
398398
local outputs = project.getrelative(cfg.project, config.buildoutputs[1])
399399
local buildmessage = ""
400400
if config.buildmessage then
401-
buildmessage = "\t@{ECHO} " .. config.buildmessage .. "\n"
401+
buildmessage = "\t@{ECHO} " .. p.quote(config.buildmessage) .. "\n"
402402
end
403403
local commands = table.implode(config.buildcommands,"\t","\n","")
404404
table.insert(makefilerules, os.translateCommandsAndPaths(outputs .. ": " .. filename .. inputs .. "\n" .. buildmessage .. commands, cfg.project.basedir, cfg.project.location))

modules/codelite/tests/test_codelite_additional_rules.lua

+31-11
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@
111111
<CustomPostBuild/>
112112
<CustomPreBuild>test.obj test2.obj
113113
test.obj: test.rule
114-
@echo Rule-ing test.rule
114+
@echo "Rule-ing test.rule"
115115
dorule -p "test.rule"
116116
117117
test2.obj: test2.rule
118-
@echo Rule-ing test2.rule
118+
@echo "Rule-ing test2.rule"
119119
dorule -p -p2 "test2.rule"
120120
</CustomPreBuild>
121121
</AdditionalRules>
@@ -156,19 +156,19 @@ test2.obj: test2.rule
156156
<CustomPostBuild/>
157157
<CustomPreBuild>test.obj test2.obj test3.obj test4.obj
158158
test.obj: test.rule
159-
@echo Rule-ing test.rule
159+
@echo "Rule-ing test.rule"
160160
dorule testValue1 testValue2 "test.rule"
161161
162162
test2.obj: test2.rule
163-
@echo Rule-ing test2.rule
163+
@echo "Rule-ing test2.rule"
164164
dorule -StestValue1 -StestValue2 "test2.rule"
165165
166166
test3.obj: test3.rule
167-
@echo Rule-ing test3.rule
167+
@echo "Rule-ing test3.rule"
168168
dorule testValue1,testValue2 "test3.rule"
169169
170170
test4.obj: test4.rule
171-
@echo Rule-ing test4.rule
171+
@echo "Rule-ing test4.rule"
172172
dorule -OtestValue1,testValue2 "test4.rule"
173173
</CustomPreBuild>
174174
</AdditionalRules>
@@ -197,11 +197,11 @@ test4.obj: test4.rule
197197
<CustomPostBuild/>
198198
<CustomPreBuild>test.obj test2.obj
199199
test.obj: test.rule
200-
@echo Rule-ing test.rule
200+
@echo "Rule-ing test.rule"
201201
dorule S0 "test.rule"
202202
203203
test2.obj: test2.rule
204-
@echo Rule-ing test2.rule
204+
@echo "Rule-ing test2.rule"
205205
dorule S1 "test2.rule"
206206
</CustomPreBuild>
207207
</AdditionalRules>
@@ -221,7 +221,27 @@ test2.obj: test2.rule
221221
<CustomPostBuild/>
222222
<CustomPreBuild>toto.c
223223
toto.c: toto.txt extra_dependency
224-
@echo Some message
224+
@echo "Some message"
225+
test
226+
test toto.c
227+
</CustomPreBuild>
228+
</AdditionalRules>]]
229+
end
230+
231+
function suite.buildCommand_escaping()
232+
files {"foo.txt", "bar.txt"}
233+
buildinputs { "toto.txt", "extra_dependency" }
234+
buildoutputs { "toto.c" }
235+
buildcommands { "test", "test toto.c" }
236+
buildmessage '"Some message"'
237+
prepare()
238+
codelite.project.additionalRules(cfg)
239+
test.capture [[
240+
<AdditionalRules>
241+
<CustomPostBuild/>
242+
<CustomPreBuild>toto.c
243+
toto.c: toto.txt extra_dependency
244+
@echo "\"Some message\""
225245
test
226246
test toto.c
227247
</CustomPreBuild>
@@ -242,12 +262,12 @@ toto.c: toto.txt extra_dependency
242262
<CustomPostBuild/>
243263
<CustomPreBuild>bar.c foo.c
244264
bar.c: bar.txt bar.h extra_dependency
245-
@echo Some message
265+
@echo "Some message"
246266
test
247267
test bar
248268
249269
foo.c: foo.txt foo.h extra_dependency
250-
@echo Some message
270+
@echo "Some message"
251271
test
252272
test foo
253273
</CustomPreBuild>

modules/codelite/tests/test_codelite_config.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
codelite.project.preBuild(cfg)
205205
test.capture [[
206206
<PreBuild>
207-
<Command Enabled="yes">@echo test</Command>
207+
<Command Enabled="yes">@echo "test"</Command>
208208
</PreBuild>
209209
]]
210210
end
@@ -215,7 +215,7 @@
215215
codelite.project.postBuild(cfg)
216216
test.capture [[
217217
<PostBuild>
218-
<Command Enabled="yes">@echo test</Command>
218+
<Command Enabled="yes">@echo "test"</Command>
219219
</PostBuild>
220220
]]
221221
end

modules/gmake2/gmake2_cpp.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@
748748
_p('%s: %s', file.buildoutputs[1], dependencies)
749749

750750
if file.buildmessage then
751-
_p('\t@echo %s', file.buildmessage)
751+
_p('\t@echo %s', p.quote(file.buildmessage))
752752
end
753753

754754
if file.buildcommands then

modules/gmake2/gmake2_utility.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@
370370
_p('%s: %s', outputs, dependencies)
371371

372372
if file.buildmessage then
373-
_p('\t@echo %s', file.buildmessage)
373+
_p('\t@echo %s', p.quote(file.buildmessage))
374374
end
375375

376376
if file.buildcommands then

modules/gmake2/tests/test_gmake2_file_rules.lua

+55-23
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@
9393
# #############################################
9494
9595
$(OBJDIR)/hello.o: src/greetings/hello.cpp
96-
@echo $(notdir $<)
96+
@echo "$(notdir $<)"
9797
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
9898
$(OBJDIR)/hello1.o: src/hello.cpp
99-
@echo $(notdir $<)
99+
@echo "$(notdir $<)"
100100
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
101101
102102
]]
@@ -115,10 +115,10 @@ $(OBJDIR)/hello1.o: src/hello.cpp
115115
# #############################################
116116
117117
$(OBJDIR)/hello.o: src/hello.c
118-
@echo $(notdir $<)
118+
@echo "$(notdir $<)"
119119
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
120120
$(OBJDIR)/test.o: src/test.cpp
121-
@echo $(notdir $<)
121+
@echo "$(notdir $<)"
122122
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
123123
124124
]]
@@ -138,10 +138,10 @@ $(OBJDIR)/test.o: src/test.cpp
138138
# #############################################
139139
140140
$(OBJDIR)/hello.o: src/hello.c
141-
@echo $(notdir $<)
141+
@echo "$(notdir $<)"
142142
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
143143
$(OBJDIR)/test.o: src/test.c
144-
@echo $(notdir $<)
144+
@echo "$(notdir $<)"
145145
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
146146
]]
147147
end
@@ -160,17 +160,17 @@ $(OBJDIR)/test.o: src/test.c
160160
# #############################################
161161
162162
$(OBJDIR)/test.o: src/test.c
163-
@echo $(notdir $<)
163+
@echo "$(notdir $<)"
164164
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
165165
166166
ifeq ($(config),debug)
167167
$(OBJDIR)/hello.o: src/hello.c
168-
@echo $(notdir $<)
168+
@echo "$(notdir $<)"
169169
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
170170
171171
else ifeq ($(config),release)
172172
$(OBJDIR)/hello.o: src/hello.c
173-
@echo $(notdir $<)
173+
@echo "$(notdir $<)"
174174
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
175175
176176
endif
@@ -198,20 +198,52 @@ endif
198198
199199
ifeq ($(config),debug)
200200
obj/Debug/hello.obj: hello.x
201-
@echo Compiling hello.x
201+
@echo "Compiling hello.x"
202202
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
203203
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
204204
205205
else ifeq ($(config),release)
206206
obj/Release/hello.obj: hello.x
207-
@echo Compiling hello.x
207+
@echo "Compiling hello.x"
208208
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
209209
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
210210
211211
endif
212212
]]
213213
end
214214

215+
--
216+
-- If a custom build rule is supplied, it should be used.
217+
--
218+
219+
function suite.customBuildRuleWithEscaping()
220+
files { "hello.x" }
221+
filter "files:**.x"
222+
buildmessage '"Compiling %{file.name}"'
223+
buildcommands {
224+
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
225+
}
226+
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
227+
prepare()
228+
test.capture [[
229+
# File Rules
230+
# #############################################
231+
232+
ifeq ($(config),debug)
233+
obj/Debug/hello.obj: hello.x
234+
@echo "\"Compiling hello.x\""
235+
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
236+
237+
else ifeq ($(config),release)
238+
obj/Release/hello.obj: hello.x
239+
@echo "\"Compiling hello.x\""
240+
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
241+
242+
endif
243+
]]
244+
end
245+
246+
215247
function suite.customBuildRuleWithAdditionalInputs()
216248
files { "hello.x" }
217249
filter "files:**.x"
@@ -229,13 +261,13 @@ endif
229261
230262
ifeq ($(config),debug)
231263
obj/Debug/hello.obj: hello.x hello.x.inc hello.x.inc2
232-
@echo Compiling hello.x
264+
@echo "Compiling hello.x"
233265
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
234266
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
235267
236268
else ifeq ($(config),release)
237269
obj/Release/hello.obj: hello.x hello.x.inc hello.x.inc2
238-
@echo Compiling hello.x
270+
@echo "Compiling hello.x"
239271
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
240272
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
241273
@@ -259,14 +291,14 @@ endif
259291
260292
ifeq ($(config),debug)
261293
obj/Debug/hello.obj: hello.x
262-
@echo Compiling hello.x
294+
@echo "Compiling hello.x"
263295
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
264296
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
265297
obj/Debug/hello.other obj/Debug/hello.another: obj/Debug/hello.obj
266298
267299
else ifeq ($(config),release)
268300
obj/Release/hello.obj: hello.x
269-
@echo Compiling hello.x
301+
@echo "Compiling hello.x"
270302
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
271303
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
272304
obj/Release/hello.other obj/Release/hello.another: obj/Release/hello.obj
@@ -296,10 +328,10 @@ endif
296328
# #############################################
297329
298330
test.obj: test.rule
299-
@echo Rule-ing test.rule
331+
@echo "Rule-ing test.rule"
300332
$(SILENT) dorule -p "test.rule"
301333
test2.obj: test2.rule
302-
@echo Rule-ing test2.rule
334+
@echo "Rule-ing test2.rule"
303335
$(SILENT) dorule -p -p2 "test2.rule"
304336
]]
305337
end
@@ -335,16 +367,16 @@ test2.obj: test2.rule
335367
# #############################################
336368
337369
test.obj: test.rule
338-
@echo Rule-ing test.rule
370+
@echo "Rule-ing test.rule"
339371
$(SILENT) dorule testValue1\ testValue2 "test.rule"
340372
test2.obj: test2.rule
341-
@echo Rule-ing test2.rule
373+
@echo "Rule-ing test2.rule"
342374
$(SILENT) dorule -StestValue1\ -StestValue2 "test2.rule"
343375
test3.obj: test3.rule
344-
@echo Rule-ing test3.rule
376+
@echo "Rule-ing test3.rule"
345377
$(SILENT) dorule testValue1,testValue2 "test3.rule"
346378
test4.obj: test4.rule
347-
@echo Rule-ing test4.rule
379+
@echo "Rule-ing test4.rule"
348380
$(SILENT) dorule -OtestValue1,testValue2 "test4.rule"
349381
]]
350382
end
@@ -370,10 +402,10 @@ test4.obj: test4.rule
370402
# #############################################
371403
372404
test.obj: test.rule
373-
@echo Rule-ing test.rule
405+
@echo "Rule-ing test.rule"
374406
$(SILENT) dorule S0 "test.rule"
375407
test2.obj: test2.rule
376-
@echo Rule-ing test2.rule
408+
@echo "Rule-ing test2.rule"
377409
$(SILENT) dorule S1 "test2.rule"
378410
]]
379411
end

modules/gmake2/tests/test_gmake2_pch.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
# #############################################
7070
7171
$(OBJDIR)/a.o: a.cpp
72-
@echo $(notdir $<)
72+
@echo "$(notdir $<)"
7373
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
7474
$(OBJDIR)/b.o: b.cpp
75-
@echo $(notdir $<)
75+
@echo "$(notdir $<)"
7676
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
7777
]]
7878
end
@@ -193,10 +193,10 @@ PCH = ../../../../src/host/premake.h
193193
# #############################################
194194
195195
$(OBJDIR)/a.o: a.cpp
196-
@echo $(notdir $<)
196+
@echo "$(notdir $<)"
197197
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
198198
$(OBJDIR)/b.o: b.cpp
199-
@echo $(notdir $<)
199+
@echo "$(notdir $<)"
200200
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
201201
]]
202202
end
@@ -215,10 +215,10 @@ $(OBJDIR)/b.o: b.cpp
215215
# #############################################
216216
217217
$(OBJDIR)/a.o: a.cpp
218-
@echo $(notdir $<)
218+
@echo "$(notdir $<)"
219219
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
220220
$(OBJDIR)/b.o: b.cpp
221-
@echo $(notdir $<)
221+
@echo "$(notdir $<)"
222222
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
223223
]]
224224
end

0 commit comments

Comments
 (0)