[cmake-developers] [CMake 0013760]: file(STRINGS): very questionable (sufficiently certainly buggy?) behaviour for square brackets

Mantis Bug Tracker mantis at public.kitware.com
Thu Nov 29 16:13:26 EST 2012


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=13760 
====================================================================== 
Reported By:                Andreas Mohr
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   13760
Category:                   CMake
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2012-11-29 16:13 EST
Last Modified:              2012-11-29 16:13 EST
====================================================================== 
Summary:                    file(STRINGS): very questionable (sufficiently
certainly buggy?) behaviour for square brackets
Description: 
I just tried parsing a section that resembles an IDL file part (the format spec
of which has sections enclosed in '[',']').
I was rather very astonished about the result of file(STRINGS) on this
(after already having spent a sizeable chunk of the day about various other
file(STRINGS) specifics, to add insult to injury).

Why in h*ll would file(STRINGS) take such specific care about the format of the
text file?
Don't tell me that it's because of (quoting docs) "Intel  Hex and  Motorola 
S-record files", which could possibly happen to have certain '['-enclosed
sections. That would be a sad result for an otherwise (in the case of
non-Intel/Motorola files) supposedly(?) sufficiently generic file(STRINGS)
functionality.

Needless to say having any []-enclosed yet originally *multi-line* content
end up delivered as a *single* line within foreach() processing is very
problematic when contrasted against my expectations.
If it actually is correct handling (for certain aspects of "correct") and
there's no quite standard CMake mechanism explanation for this that I managed to
miss, then docs should definitely be corrected to mention this possibly
'['-specific handling.

Any ideas or comments about this?

Severity major since it's data corrupting (e.g. going line-by-line over a regex
with start-of-line/end-of-line constraints - ^$ - *will* cause headache or
worse).

Thank you!

Steps to Reproduce: 
cmake_minimum_required(VERSION 2.8)

project(file_strings_bug_test NONE)

macro(write_file _file _content)
  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_file}" "${_content}")
endmacro(write_file _file _content)

macro(read_file _file)
  file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/${_file}" _content_list)
  foreach(line_ ${_content_list})
    message("line ${_file}: ${line_}")
  endforeach(line_ ${_content_list})
endmacro(read_file _file)

set("content_ok" "Hello
World
My Worrying
Test")

set(content_ko "[${content_ok}]")
set(content_ko2 "Hi
There
[${content_ok}] ")

write_file(file_ok "${content_ok}")
write_file(file_ko "${content_ko}")
write_file(file_ko2 "${content_ko2}")

read_file(file_ok)
read_file(file_ko)
read_file(file_ko2)


Additional Information: 
$ cmake ..
line file_ok: Hello
line file_ok: World
line file_ok: My Worrying
line file_ok: Test
line file_ko: [Hello;World;My Worrying;Test]
line file_ko2: Hi
line file_ko2: There
line file_ko2: [Hello;World;My Worrying;Test] 
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/andi/prg/cmake_tests/file_strings_bug_test/build

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2012-11-29 16:13 Andreas Mohr   New Issue                                    
======================================================================




More information about the cmake-developers mailing list