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

Fix Codelite/gmake2 buildmessage escaping. #1913

Merged
merged 2 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 3 additions & 3 deletions modules/codelite/codelite_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
_p(3, '<PreBuild>')
p.escaper(codelite.escElementText)
if cfg.prebuildmessage then
local command = os.translateCommandsAndPaths("@{ECHO} " .. cfg.prebuildmessage, cfg.project.basedir, cfg.project.location)
local command = os.translateCommandsAndPaths("@{ECHO} " .. p.quote(cfg.prebuildmessage), cfg.project.basedir, cfg.project.location)
_x(4, '<Command Enabled="yes">%s</Command>', command)
end
local commands = os.translateCommandsAndPaths(cfg.prebuildcommands, cfg.project.basedir, cfg.project.location)
Expand All @@ -342,7 +342,7 @@
_p(3, '<PostBuild>')
p.escaper(codelite.escElementText)
if cfg.postbuildmessage then
local command = os.translateCommandsAndPaths("@{ECHO} " .. cfg.postbuildmessage, cfg.project.basedir, cfg.project.location)
local command = os.translateCommandsAndPaths("@{ECHO} " .. p.quote(cfg.postbuildmessage), cfg.project.basedir, cfg.project.location)
_x(4, '<Command Enabled="yes">%s</Command>', command)
end
local commands = os.translateCommandsAndPaths(cfg.postbuildcommands, cfg.project.basedir, cfg.project.location)
Expand Down Expand Up @@ -398,7 +398,7 @@
local outputs = project.getrelative(cfg.project, config.buildoutputs[1])
local buildmessage = ""
if config.buildmessage then
buildmessage = "\t@{ECHO} " .. config.buildmessage .. "\n"
buildmessage = "\t@{ECHO} " .. p.quote(config.buildmessage) .. "\n"
end
local commands = table.implode(config.buildcommands,"\t","\n","")
table.insert(makefilerules, os.translateCommandsAndPaths(outputs .. ": " .. filename .. inputs .. "\n" .. buildmessage .. commands, cfg.project.basedir, cfg.project.location))
Expand Down
42 changes: 31 additions & 11 deletions modules/codelite/tests/test_codelite_additional_rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@
<CustomPostBuild/>
<CustomPreBuild>test.obj test2.obj
test.obj: test.rule
@echo Rule-ing test.rule
@echo "Rule-ing test.rule"
dorule -p "test.rule"

test2.obj: test2.rule
@echo Rule-ing test2.rule
@echo "Rule-ing test2.rule"
dorule -p -p2 "test2.rule"
</CustomPreBuild>
</AdditionalRules>
Expand Down Expand Up @@ -156,19 +156,19 @@ test2.obj: test2.rule
<CustomPostBuild/>
<CustomPreBuild>test.obj test2.obj test3.obj test4.obj
test.obj: test.rule
@echo Rule-ing test.rule
@echo "Rule-ing test.rule"
dorule testValue1 testValue2 "test.rule"

test2.obj: test2.rule
@echo Rule-ing test2.rule
@echo "Rule-ing test2.rule"
dorule -StestValue1 -StestValue2 "test2.rule"

test3.obj: test3.rule
@echo Rule-ing test3.rule
@echo "Rule-ing test3.rule"
dorule testValue1,testValue2 "test3.rule"

test4.obj: test4.rule
@echo Rule-ing test4.rule
@echo "Rule-ing test4.rule"
dorule -OtestValue1,testValue2 "test4.rule"
</CustomPreBuild>
</AdditionalRules>
Expand Down Expand Up @@ -197,11 +197,11 @@ test4.obj: test4.rule
<CustomPostBuild/>
<CustomPreBuild>test.obj test2.obj
test.obj: test.rule
@echo Rule-ing test.rule
@echo "Rule-ing test.rule"
dorule S0 "test.rule"

test2.obj: test2.rule
@echo Rule-ing test2.rule
@echo "Rule-ing test2.rule"
dorule S1 "test2.rule"
</CustomPreBuild>
</AdditionalRules>
Expand All @@ -221,7 +221,27 @@ test2.obj: test2.rule
<CustomPostBuild/>
<CustomPreBuild>toto.c
toto.c: toto.txt extra_dependency
@echo Some message
@echo "Some message"
test
test toto.c
</CustomPreBuild>
</AdditionalRules>]]
end

function suite.buildCommand_escaping()
files {"foo.txt", "bar.txt"}
buildinputs { "toto.txt", "extra_dependency" }
buildoutputs { "toto.c" }
buildcommands { "test", "test toto.c" }
buildmessage '"Some message"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should avoid hijacking existing tests, you should create a new test explicitly for testing the escaping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roll backed.
Dedicated test done.

prepare()
codelite.project.additionalRules(cfg)
test.capture [[
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild>toto.c
toto.c: toto.txt extra_dependency
@echo "\"Some message\""
test
test toto.c
</CustomPreBuild>
Expand All @@ -242,12 +262,12 @@ toto.c: toto.txt extra_dependency
<CustomPostBuild/>
<CustomPreBuild>bar.c foo.c
bar.c: bar.txt bar.h extra_dependency
@echo Some message
@echo "Some message"
test
test bar

foo.c: foo.txt foo.h extra_dependency
@echo Some message
@echo "Some message"
test
test foo
</CustomPreBuild>
Expand Down
4 changes: 2 additions & 2 deletions modules/codelite/tests/test_codelite_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
codelite.project.preBuild(cfg)
test.capture [[
<PreBuild>
<Command Enabled="yes">@echo test</Command>
<Command Enabled="yes">@echo "test"</Command>
</PreBuild>
]]
end
Expand All @@ -215,7 +215,7 @@
codelite.project.postBuild(cfg)
test.capture [[
<PostBuild>
<Command Enabled="yes">@echo test</Command>
<Command Enabled="yes">@echo "test"</Command>
</PostBuild>
]]
end
Expand Down
2 changes: 1 addition & 1 deletion modules/gmake2/gmake2_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@
_p('%s: %s', file.buildoutputs[1], dependencies)

if file.buildmessage then
_p('\t@echo %s', file.buildmessage)
_p('\t@echo %s', p.quote(file.buildmessage))
end

if file.buildcommands then
Expand Down
2 changes: 1 addition & 1 deletion modules/gmake2/gmake2_utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
_p('%s: %s', outputs, dependencies)

if file.buildmessage then
_p('\t@echo %s', file.buildmessage)
_p('\t@echo %s', p.quote(file.buildmessage))
end

if file.buildcommands then
Expand Down
78 changes: 55 additions & 23 deletions modules/gmake2/tests/test_gmake2_file_rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
# #############################################

$(OBJDIR)/hello.o: src/greetings/hello.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/hello1.o: src/hello.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

]]
Expand All @@ -115,10 +115,10 @@ $(OBJDIR)/hello1.o: src/hello.cpp
# #############################################

$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/test.o: src/test.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

]]
Expand All @@ -138,10 +138,10 @@ $(OBJDIR)/test.o: src/test.cpp
# #############################################

$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/test.o: src/test.c
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
Expand All @@ -160,17 +160,17 @@ $(OBJDIR)/test.o: src/test.c
# #############################################

$(OBJDIR)/test.o: src/test.c
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

ifeq ($(config),debug)
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

else ifeq ($(config),release)
$(OBJDIR)/hello.o: src/hello.c
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

endif
Expand Down Expand Up @@ -198,20 +198,52 @@ endif

ifeq ($(config),debug)
obj/Debug/hello.obj: hello.x
@echo Compiling hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"

else ifeq ($(config),release)
obj/Release/hello.obj: hello.x
@echo Compiling hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"

endif
]]
end

--
-- If a custom build rule is supplied, it should be used.
--

function suite.customBuildRuleWithEscaping()
files { "hello.x" }
filter "files:**.x"
buildmessage '"Compiling %{file.name}"'
buildcommands {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
}
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
prepare()
test.capture [[
# File Rules
# #############################################

ifeq ($(config),debug)
obj/Debug/hello.obj: hello.x
@echo "\"Compiling hello.x\""
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"

else ifeq ($(config),release)
obj/Release/hello.obj: hello.x
@echo "\"Compiling hello.x\""
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"

endif
]]
end


function suite.customBuildRuleWithAdditionalInputs()
files { "hello.x" }
filter "files:**.x"
Expand All @@ -229,13 +261,13 @@ endif

ifeq ($(config),debug)
obj/Debug/hello.obj: hello.x hello.x.inc hello.x.inc2
@echo Compiling hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"

else ifeq ($(config),release)
obj/Release/hello.obj: hello.x hello.x.inc hello.x.inc2
@echo Compiling hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"

Expand All @@ -259,14 +291,14 @@ endif

ifeq ($(config),debug)
obj/Debug/hello.obj: hello.x
@echo Compiling hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
obj/Debug/hello.other obj/Debug/hello.another: obj/Debug/hello.obj

else ifeq ($(config),release)
obj/Release/hello.obj: hello.x
@echo Compiling hello.x
@echo "Compiling hello.x"
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
obj/Release/hello.other obj/Release/hello.another: obj/Release/hello.obj
Expand Down Expand Up @@ -296,10 +328,10 @@ endif
# #############################################

test.obj: test.rule
@echo Rule-ing test.rule
@echo "Rule-ing test.rule"
$(SILENT) dorule -p "test.rule"
test2.obj: test2.rule
@echo Rule-ing test2.rule
@echo "Rule-ing test2.rule"
$(SILENT) dorule -p -p2 "test2.rule"
]]
end
Expand Down Expand Up @@ -335,16 +367,16 @@ test2.obj: test2.rule
# #############################################

test.obj: test.rule
@echo Rule-ing test.rule
@echo "Rule-ing test.rule"
$(SILENT) dorule testValue1\ testValue2 "test.rule"
test2.obj: test2.rule
@echo Rule-ing test2.rule
@echo "Rule-ing test2.rule"
$(SILENT) dorule -StestValue1\ -StestValue2 "test2.rule"
test3.obj: test3.rule
@echo Rule-ing test3.rule
@echo "Rule-ing test3.rule"
$(SILENT) dorule testValue1,testValue2 "test3.rule"
test4.obj: test4.rule
@echo Rule-ing test4.rule
@echo "Rule-ing test4.rule"
$(SILENT) dorule -OtestValue1,testValue2 "test4.rule"
]]
end
Expand All @@ -370,10 +402,10 @@ test4.obj: test4.rule
# #############################################

test.obj: test.rule
@echo Rule-ing test.rule
@echo "Rule-ing test.rule"
$(SILENT) dorule S0 "test.rule"
test2.obj: test2.rule
@echo Rule-ing test2.rule
@echo "Rule-ing test2.rule"
$(SILENT) dorule S1 "test2.rule"
]]
end
12 changes: 6 additions & 6 deletions modules/gmake2/tests/test_gmake2_pch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
# #############################################

$(OBJDIR)/a.o: a.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
Expand Down Expand Up @@ -193,10 +193,10 @@ PCH = ../../../../src/host/premake.h
# #############################################

$(OBJDIR)/a.o: a.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
Expand All @@ -215,10 +215,10 @@ $(OBJDIR)/b.o: b.cpp
# #############################################

$(OBJDIR)/a.o: a.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/b.o: b.cpp
@echo $(notdir $<)
@echo "$(notdir $<)"
$(SILENT) $(CXX) -include $(PCH_PLACEHOLDER) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
]]
end
Loading