From c1e097cc680733cd5fa7cc12faa6b3aa037c7950 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jan 2018 17:03:46 +0100 Subject: [PATCH 1/5] Update CMake files list Regenerate the file that was forgotten before by the changes of 48a5d6c5f835ce70d7b06a89a51a164b58c19dad (see #18038) and 95b28abfdf6ad32a62884112d495076f38ec6e5b (see https://github.com/wxWidgets/wxWidgets/pull/541). --- build/cmake/files.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index ee77fecdb2..018fd0b30d 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -509,6 +509,7 @@ set(BASE_CMN_HDR wx/event.h wx/eventfilter.h wx/evtloop.h + wx/evtloopsrc.h wx/except.h wx/features.h wx/flags.h @@ -1009,7 +1010,6 @@ set(GUI_CMN_HDR wx/docmdi.h wx/docview.h wx/effects.h - wx/evtloopsrc.h wx/fdrepdlg.h wx/filectrl.h wx/filehistory.h @@ -1054,6 +1054,7 @@ set(GUI_CMN_HDR wx/paper.h wx/persist.h wx/persist/bookctrl.h + wx/persist/dataview.h wx/persist/splitter.h wx/persist/toplevel.h wx/persist/treebook.h From 9a75103d9aa24620678f8cfac2c48d4cab9537bb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jan 2018 18:33:26 +0100 Subject: [PATCH 2/5] Fix upmake bug with conditions in bakefile files Don't strip the tags from bakefile variables (this bug fix is actually in Makefile::Update Perl module, but is incorporated here by reference) and remove these tags which somehow made it into upmake input file, as they make no sense there. Note also that upmake was recreated using a different version of fatpack (0.010007), which accounts for many other differences in this file. --- build/files | 4 - build/upmake | 580 ++++++++++++++++++++------------------------------- 2 files changed, 222 insertions(+), 362 deletions(-) diff --git a/build/files b/build/files index d450ec7464..e6d0c67a6d 100644 --- a/build/files +++ b/build/files @@ -2067,7 +2067,6 @@ DFB_LOWLEVEL_HDR = OSX_LOWLEVEL_SRC = # Shared wxMac and wxCocoa files - src/osx/artmac.cpp src/osx/brush.cpp src/osx/dialog_osx.cpp @@ -2091,12 +2090,10 @@ OSX_LOWLEVEL_SRC = src/osx/core/printmac.cpp src/osx/core/timer.cpp src/osx/core/utilsexc_cf.cpp - OSX_LOWLEVEL_HDR = OSX_COMMON_SRC = - # Common controls implementation src/osx/anybutton_osx.cpp src/osx/bmpbuttn_osx.cpp @@ -2169,7 +2166,6 @@ OSX_COMMON_SRC = src/generic/prntdlgg.cpp src/generic/statusbr.cpp src/generic/textmeasure.cpp - # Header files like wx/osx/foo.h which include wx/osx/carbon/foo.h OSX_SHARED_HDR = diff --git a/build/upmake b/build/upmake index d74de1d71e..e6dffcd114 100755 --- a/build/upmake +++ b/build/upmake @@ -18,9 +18,44 @@ $fatpacked{"Makefile/Update.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<< our @EXPORT = qw(read_files_list upmake); - our $VERSION = '0.3'; # VERSION + # VERSION + =head1 SYNOPSIS + use Makefile::Update; + my $vars = read_files_list('files.lst'); + upmake('foo.vcxproj', $vars->{sources}, $vars->{headers}); + + =cut + + =func read_files_list + + Reads the file containing the file lists definitions and returns a hash ref + with variable names as keys and refs to arrays of the file names as values. + + Takes an (open) file handle as argument. + + The file contents is supposed to have the following very simple format: + + # Comments are allowed and ignored. + # + # The variable definitions must always be in the format shown below, + # i.e. whitespace is significant and there should always be a single + # file per line. + sources = + file1.cpp + file2.cpp + + headers = + file1.h + file2.h + + # It is also possible to define variables in terms of other variables + # defined before it in the file (no forward references): + everything = + $sources + $headers + =cut sub read_files_list { @@ -55,6 +90,41 @@ $fatpacked{"Makefile/Update.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<< return \%vars; } + =func upmake + + Update a file in place using the specified function and passing it the rest of + the arguments. + + The first parameter is either just the file path or a hash reference which may + contain the following keys: + + =over + + =item C + + The path to the file to be updated, required. + + =item C + + If true, give more messages about what is being done. + + =item C + + If true, don't output any non-error messages. + + =item C + + If true, don't really update the file but just output whether it would have + been updated or not. If C is also true, also output the diff of the + changes that would have been done. + + =back + + This is meant to be used with C defined in different + Makefile::Update::Xxx modules. + + Returns 1 if the file was changed or 0 otherwise. + =cut sub upmake { @@ -137,104 +207,6 @@ $fatpacked{"Makefile/Update.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<< } 1; - - __END__ - - =pod - - =encoding UTF-8 - - =head1 NAME - - Makefile::Update - Update make files. - - =head1 VERSION - - version 0.3 - - =head1 SYNOPSIS - - use Makefile::Update; - my $vars = read_files_list('files.lst'); - upmake('foo.vcxproj', $vars->{sources}, $vars->{headers}); - - =head1 FUNCTIONS - - =head2 read_files_list - - Reads the file containing the file lists definitions and returns a hash ref - with variable names as keys and refs to arrays of the file names as values. - - Takes an (open) file handle as argument. - - The file contents is supposed to have the following very simple format: - - # Comments are allowed and ignored. - # - # The variable definitions must always be in the format shown below, - # i.e. whitespace is significant and there should always be a single - # file per line. - sources = - file1.cpp - file2.cpp - - headers = - file1.h - file2.h - - # It is also possible to define variables in terms of other variables - # defined before it in the file (no forward references): - everything = - $sources - $headers - - =head2 upmake - - Update a file in place using the specified function and passing it the rest of - the arguments. - - The first parameter is either just the file path or a hash reference which may - contain the following keys: - - =over - - =item C - - The path to the file to be updated, required. - - =item C - - If true, give more messages about what is being done. - - =item C - - If true, don't output any non-error messages. - - =item C - - If true, don't really update the file but just output whether it would have - been updated or not. If C is also true, also output the diff of the - changes that would have been done. - - =back - - This is meant to be used with C defined in different - Makefile::Update::Xxx modules. - - Returns 1 if the file was changed or 0 otherwise. - - =head1 AUTHOR - - Vadim Zeitlin - - =head1 COPYRIGHT AND LICENSE - - This software is copyright (c) 2015 by Vadim Zeitlin. - - This is free software; you can redistribute it and/or modify it under - the same terms as the Perl 5 programming language system itself. - - =cut MAKEFILE_UPDATE $fatpacked{"Makefile/Update/Bakefile0.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'MAKEFILE_UPDATE_BAKEFILE0'; @@ -247,9 +219,32 @@ $fatpacked{"Makefile/Update/Bakefile0.pm"} = '#line '.(1+__LINE__).' "'.__FILE__ use strict; use warnings; - our $VERSION = '0.3'; # VERSION + # VERSION + =head1 SYNOPSIS + This is used exclusively to update wxWidgets C and is probably not + useful outside of wxWidgets project. + + use Makefile::Update::Bakefile0; + Makefile::Update::upmake('bakefiles/files.bkl', \&update_bakefile_0, $vars); + + =head1 SEE ALSO + + Makefile::Update + + =cut + + =func update_bakefile_0 + + Update file with variable definitions in bakefile-0 format with the data + from the hash ref containing all the file lists. + + Takes the (open) file handles of the files to read and to write and the file + lists hash ref as arguments. + + Returns 1 if any changes were made. + =cut sub update_bakefile_0 { @@ -275,6 +270,8 @@ $fatpacked{"Makefile/Update/Bakefile0.pm"} = '#line '.(1+__LINE__).' "'.__FILE__ s///; s/^\s+//; s/\s+$//; + s{]+>}{}; + s{}{}; if (m{}) { # Check if we have any new files. # @@ -311,57 +308,6 @@ $fatpacked{"Makefile/Update/Bakefile0.pm"} = '#line '.(1+__LINE__).' "'.__FILE__ $changed } - - __END__ - - =pod - - =encoding UTF-8 - - =head1 NAME - - Makefile::Update::Bakefile0 - Update bakefile-0.x files list. - - =head1 VERSION - - version 0.3 - - =head1 SYNOPSIS - - This is used exclusively to update wxWidgets C and is probably not - useful outside of wxWidgets project. - - use Makefile::Update::Bakefile0; - Makefile::Update::upmake('bakefiles/files.bkl', \&update_bakefile_0, $vars); - - =head1 FUNCTIONS - - =head2 update_bakefile_0 - - Update file with variable definitions in bakefile-0 format with the data - from the hash ref containing all the file lists. - - Takes the (open) file handles of the files to read and to write and the file - lists hash ref as arguments. - - Returns 1 if any changes were made. - - =head1 SEE ALSO - - Makefile::Update - - =head1 AUTHOR - - Vadim Zeitlin - - =head1 COPYRIGHT AND LICENSE - - This software is copyright (c) 2015 by Vadim Zeitlin. - - This is free software; you can redistribute it and/or modify it under - the same terms as the Perl 5 programming language system itself. - - =cut MAKEFILE_UPDATE_BAKEFILE0 $fatpacked{"Makefile/Update/MSBuild.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'MAKEFILE_UPDATE_MSBUILD'; @@ -374,9 +320,34 @@ $fatpacked{"Makefile/Update/MSBuild.pm"} = '#line '.(1+__LINE__).' "'.__FILE__." use strict; use warnings; - our $VERSION = '0.3'; # VERSION + # VERSION + =head1 SYNOPSIS + Given an MSBuild project C and its associated filters file + C, the functions in this module can be used to update + the list of files in them to correspond to the given ones. + + use Makefile::Update::MSBuild; + upmake_msbuild_project('project.vcxproj', \@sources, \@headers); + + =head1 SEE ALSO + + Makefile::Update, Makefile::Update::VCProj + + =cut + + =func update_msbuild_project + + Update sources and headers in an MSBuild project and filter files. + + Pass the path of the project to update or a hash with the same keys as used by + C as the first parameter and the references to the + sources and headers arrays as the subsequent ones. + + Returns 1 if any changes were made, either to the project itself or to its + associated C<.filters> file. + =cut sub update_msbuild_project { @@ -405,6 +376,15 @@ $fatpacked{"Makefile/Update/MSBuild.pm"} = '#line '.(1+__LINE__).' "'.__FILE__." } + =func update_msbuild + + Update sources and headers in an MSBuild project. + + Parameters: input and output file handles and array references to the sources + and the headers to be used in this project. + + Returns 1 if any changes were made. + =cut sub update_msbuild { @@ -508,6 +488,16 @@ $fatpacked{"Makefile/Update/MSBuild.pm"} = '#line '.(1+__LINE__).' "'.__FILE__." $changed } + =func update_msbuild_filters + + Update sources and headers in an MSBuild filters file. + + Parameters: input and output file handles, array references to the sources + and the headers to be used in this project and a callback used to determine + the filter for the new files. + + Returns 1 if any changes were made. + =cut sub update_msbuild_filters { @@ -635,78 +625,6 @@ $fatpacked{"Makefile/Update/MSBuild.pm"} = '#line '.(1+__LINE__).' "'.__FILE__." $changed } - - __END__ - - =pod - - =encoding UTF-8 - - =head1 NAME - - Makefile::Update::MSBuild - Update list of sources and headers in MSBuild projects. - - =head1 VERSION - - version 0.3 - - =head1 SYNOPSIS - - Given an MSBuild project C and its associated filters file - C, the functions in this module can be used to update - the list of files in them to correspond to the given ones. - - use Makefile::Update::MSBuild; - upmake_msbuild_project('project.vcxproj', \@sources, \@headers); - - =head1 FUNCTIONS - - =head2 update_msbuild_project - - Update sources and headers in an MSBuild project and filter files. - - Pass the path of the project to update or a hash with the same keys as used by - C as the first parameter and the references to the - sources and headers arrays as the subsequent ones. - - Returns 1 if any changes were made, either to the project itself or to its - associated C<.filters> file. - - =head2 update_msbuild - - Update sources and headers in an MSBuild project. - - Parameters: input and output file handles and array references to the sources - and the headers to be used in this project. - - Returns 1 if any changes were made. - - =head2 update_msbuild_filters - - Update sources and headers in an MSBuild filters file. - - Parameters: input and output file handles, array references to the sources - and the headers to be used in this project and a callback used to determine - the filter for the new files. - - Returns 1 if any changes were made. - - =head1 SEE ALSO - - Makefile::Update, Makefile::Update::VCProj - - =head1 AUTHOR - - Vadim Zeitlin - - =head1 COPYRIGHT AND LICENSE - - This software is copyright (c) 2015 by Vadim Zeitlin. - - This is free software; you can redistribute it and/or modify it under - the same terms as the Perl 5 programming language system itself. - - =cut MAKEFILE_UPDATE_MSBUILD $fatpacked{"Makefile/Update/Makefile.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'MAKEFILE_UPDATE_MAKEFILE'; @@ -719,9 +637,53 @@ $fatpacked{"Makefile/Update/Makefile.pm"} = '#line '.(1+__LINE__).' "'.__FILE__. use strict; use warnings; - our $VERSION = '0.3'; # VERSION + # VERSION + =head1 SYNOPSIS + This can be used to update the contents of a variable containing a list of + files in a makefile. + + use Makefile::Update::Makefile; + Makefile::Update::upmake('GNUmakefile', \&update_makefile, $vars); + + =head1 SEE ALSO + + Makefile::Update + + =cut + + =func update_makefile + + Update variable definitions in a makefile format with the data from the hash + ref containing all the file lists. + + Only most straightforward cases of variable or target definitions are + recognized here, i.e. just "var := value", "var = value" or "target: value". + In particular we don't support any GNU make extensions such as "export" or + "override" without speaking of anything more complex. + + On top of it, currently the value should contain a single file per line with + none at all on the first line (but this restriction could be relaxed later if + needed), i.e. the only supported case is + + var = \ + foo \ + bar \ + baz + + and it must be followed by an empty line, too. + + Notice that if any of the "files" in the variable value looks like a makefile + variable, i.e. has "$(foo)" form, it is ignored by this function, i.e. not + removed even if it doesn't appear in the list of files (which will never be + the case normally). + + Takes the (open) file handles of the files to read and to write and the file + lists hash ref as arguments. + + Returns 1 if any changes were made. + =cut sub update_makefile { @@ -1002,78 +964,6 @@ $fatpacked{"Makefile/Update/Makefile.pm"} = '#line '.(1+__LINE__).' "'.__FILE__. $changed } - - __END__ - - =pod - - =encoding UTF-8 - - =head1 NAME - - Makefile::Update::Makefile - Update lists of files in makefile variables. - - =head1 VERSION - - version 0.3 - - =head1 SYNOPSIS - - This can be used to update the contents of a variable containing a list of - files in a makefile. - - use Makefile::Update::Makefile; - Makefile::Update::upmake('GNUmakefile', \&update_makefile, $vars); - - =head1 FUNCTIONS - - =head2 update_makefile - - Update variable definitions in a makefile format with the data from the hash - ref containing all the file lists. - - Only most straightforward cases of variable or target definitions are - recognized here, i.e. just "var := value", "var = value" or "target: value". - In particular we don't support any GNU make extensions such as "export" or - "override" without speaking of anything more complex. - - On top of it, currently the value should contain a single file per line with - none at all on the first line (but this restriction could be relaxed later if - needed), i.e. the only supported case is - - var = \ - foo \ - bar \ - baz - - and it must be followed by an empty line, too. - - Notice that if any of the "files" in the variable value looks like a makefile - variable, i.e. has "$(foo)" form, it is ignored by this function, i.e. not - removed even if it doesn't appear in the list of files (which will never be - the case normally). - - Takes the (open) file handles of the files to read and to write and the file - lists hash ref as arguments. - - Returns 1 if any changes were made. - - =head1 SEE ALSO - - Makefile::Update - - =head1 AUTHOR - - Vadim Zeitlin - - =head1 COPYRIGHT AND LICENSE - - This software is copyright (c) 2015 by Vadim Zeitlin. - - This is free software; you can redistribute it and/or modify it under - the same terms as the Perl 5 programming language system itself. - - =cut MAKEFILE_UPDATE_MAKEFILE $fatpacked{"Makefile/Update/VCProj.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'MAKEFILE_UPDATE_VCPROJ'; @@ -1086,9 +976,32 @@ $fatpacked{"Makefile/Update/VCProj.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\ use strict; use warnings; - our $VERSION = '0.3'; # VERSION + # VERSION + =head1 SYNOPSIS + The function L can be used to update the list of headers and + sources in the given Visual C++ project file C: + + use Makefile::Update::VCProj; + upmake_msbuild_project('project.vcproj', \@sources, \@headers); + + =head1 SEE ALSO + + Makefile::Update, Makefile::Update::MSBuild + + =cut + + =func update_vcproj + + Update sources and headers in a VC++ project. + + Parameters: input and output file handles, array references to the sources + and the headers to be used in this project and a callback used to determine + the filter for the new files. + + Returns 1 if any changes were made. + =cut sub update_vcproj { @@ -1252,57 +1165,6 @@ $fatpacked{"Makefile/Update/VCProj.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\ $changed } - - __END__ - - =pod - - =encoding UTF-8 - - =head1 NAME - - Makefile::Update::VCProj - Update list of sources and headers in Visual C++ projects. - - =head1 VERSION - - version 0.3 - - =head1 SYNOPSIS - - The function L can be used to update the list of headers and - sources in the given Visual C++ project file C: - - use Makefile::Update::VCProj; - upmake_msbuild_project('project.vcproj', \@sources, \@headers); - - =head1 FUNCTIONS - - =head2 update_vcproj - - Update sources and headers in a VC++ project. - - Parameters: input and output file handles, array references to the sources - and the headers to be used in this project and a callback used to determine - the filter for the new files. - - Returns 1 if any changes were made. - - =head1 SEE ALSO - - Makefile::Update, Makefile::Update::MSBuild - - =head1 AUTHOR - - Vadim Zeitlin - - =head1 COPYRIGHT AND LICENSE - - This software is copyright (c) 2015 by Vadim Zeitlin. - - This is free software; you can redistribute it and/or modify it under - the same terms as the Perl 5 programming language system itself. - - =cut MAKEFILE_UPDATE_VCPROJ s/^ //mg for values %fatpacked; @@ -1313,15 +1175,17 @@ no strict 'refs'; if ($] < 5.008) { *{"${class}::INC"} = sub { - if (my $fat = $_[0]{$_[1]}) { - return sub { - return 0 unless length $fat; - $fat =~ s/^([^\n]*\n?)//; - $_ = $1; - return 1; - }; - } - return; + if (my $fat = $_[0]{$_[1]}) { + my $pos = 0; + my $last = length $fat; + return (sub { + return 0 if $pos == $last; + my $next = (1 + index $fat, "\n", $pos) || $last; + $_ .= substr $fat, $pos, $next - $pos; + $pos = $next; + return 1; + }); + } }; } From d7fbf1f820778710277fa419dd76e2fa291ee4e3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jan 2018 18:43:01 +0100 Subject: [PATCH 3/5] Output the message about bakefile_gen by default in upmake This message shouldn't be given only when --verbose is given, it's useful as a reminder and you shouldn't have to remember to give a special option to get this reminder. --- build/upmake | 2 +- build/upmake_script.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/upmake b/build/upmake index e6dffcd114..c02001348d 100755 --- a/build/upmake +++ b/build/upmake @@ -1257,7 +1257,7 @@ my $vars = read_files_list($files); if (!$only_msvs) { if (call_upmake("$Bin/bakefiles/files.bkl", \&update_bakefile_0, $vars)) { - print qq{Don't forget to run "bakefile_gen -b wx.bkl".\n} if $verbose; + print qq{Don't forget to run "bakefile_gen -b wx.bkl".\n}; } } diff --git a/build/upmake_script.pl b/build/upmake_script.pl index 75939c8407..a0855b04e6 100755 --- a/build/upmake_script.pl +++ b/build/upmake_script.pl @@ -53,7 +53,7 @@ my $vars = read_files_list($files); if (!$only_msvs) { if (call_upmake("$Bin/bakefiles/files.bkl", \&update_bakefile_0, $vars)) { - print qq{Don't forget to run "bakefile_gen -b wx.bkl".\n} if $verbose; + print qq{Don't forget to run "bakefile_gen -b wx.bkl".\n}; } } From b2a8c2188f00d4bb2dcb84f5ffab82395c3c9476 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jan 2018 19:19:29 +0100 Subject: [PATCH 4/5] Remove duplicate wx/scrolbar.h from CMake files list This will avoid warnings when regenerating it the next time. --- build/cmake/files.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index 018fd0b30d..265b868059 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -952,7 +952,6 @@ set(GUI_CMN_HDR wx/renderer.h wx/richmsgdlg.h wx/scrolbar.h - wx/scrolbar.h wx/scrolwin.h wx/selstore.h wx/settings.h From 267067aa8af98ff92ca79c33dcf4f570b8aa4df8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jan 2018 22:29:42 +0100 Subject: [PATCH 5/5] Regenerate CMake files list from upmake too Replace the specialized Python script used for it before (and which was actually forgotten to run a couple of times already) with a newer version of upmake, which can now update CMake variable definitions too. --- build/cmake/files.cmake | 2 +- build/cmake/update_files.py | 77 --------------------- build/upmake | 131 ++++++++++++++++++++++++++++++++++++ build/upmake_script.pl | 5 ++ 4 files changed, 137 insertions(+), 78 deletions(-) delete mode 100755 build/cmake/update_files.py diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index 265b868059..82690419f8 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -1,4 +1,4 @@ -# Automatically generated from build/files by update_files.py +# Automatically generated from build/files by build/upmake # DO NOT MODIFY MANUALLY ! set(BASE_UNIX_AND_DARWIN_SRC diff --git a/build/cmake/update_files.py b/build/cmake/update_files.py deleted file mode 100755 index aea703b253..0000000000 --- a/build/cmake/update_files.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python - -############################################################################# -# Name: build/cmake/update_files.py -# Purpose: Convert build/files to files.cmake -# Author: Tobias Taschner -# Created: 2016-09-20 -# Copyright: (c) 2016 wxWidgets development team -# Licence: wxWindows licence -############################################################################# - -import os -import re - -outpath = os.path.dirname(os.path.abspath(__file__)) - -infile = open(outpath + "/../files", "r") -outfile = open(outpath + "/files.cmake", "w") -outfile.write("# Automatically generated from build/files by " + os.path.basename(__file__) + "\n") -outfile.write("# DO NOT MODIFY MANUALLY !\n\n") - -# Compile regular expressions -var_ex = re.compile('([\w]+)[\s]*=') -comment_ex = re.compile('^[#]+') -evar_ex = re.compile('\$\(([\w]+)\)') -cmd_ex = re.compile('^<') - -files = None -var_name = None - -def write_file_list(): - # Write current list of files to output file - if not var_name: - return - - outfile.write('set(' + var_name + '\n') - for file in files: - outfile.write(' ') - vm = evar_ex.match(file) - if vm: - # Convert variable reference to cmake variable reference - outfile.write('${'+vm.group(1)+'}') - else: - outfile.write(file) - outfile.write('\n') - - outfile.write(')\n\n') - -for line in infile.readlines(): - # Ignore comment lines - m = comment_ex.match(line) - if m: - continue - m = cmd_ex.match(line.strip()) - if m: - # Ignore bake file commands but note them in the target file in - # case we might need them - line = '#TODO: ' + line - - # Check for variable declaration - m = var_ex.match(line) - if m: - write_file_list() - - var_name = m.group(1) - files = [] - else: - # Collect every file entry - file = line.strip() - if file and var_name: - files.append(file) - -# Write last variable -write_file_list() - -infile.close() -outfile.close() diff --git a/build/upmake b/build/upmake index c02001348d..8a10b35d62 100755 --- a/build/upmake +++ b/build/upmake @@ -310,6 +310,132 @@ $fatpacked{"Makefile/Update/Bakefile0.pm"} = '#line '.(1+__LINE__).' "'.__FILE__ } MAKEFILE_UPDATE_BAKEFILE0 +$fatpacked{"Makefile/Update/CMakefile.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'MAKEFILE_UPDATE_CMAKEFILE'; + package Makefile::Update::CMakefile; + # ABSTRACT: Update lists of files in CMake variables. + + use Exporter qw(import); + our @EXPORT = qw(update_cmakefile); + + use strict; + use warnings; + + # VERSION + + =head1 SYNOPSIS + + This can be used to update the contents of a variable containing a list of + files in a CMake file. + + use Makefile::Update::CMakefile; + Makefile::Update::upmake('CMakeLists.txt', \&update_cmakefile, $vars); + + =head1 SEE ALSO + + Makefile::Update + + =cut + + # Variables in our input files use make-like $(var) syntax while CMake uses + # shell-like ${var}, so convert to the target format. + sub _var_to_cmake + { + my ($var) = @_; + $var =~ s/\((\w+)\)/{$1}/g; + $var; + } + + =func update_cmakefile + + Update variable definitions in a CMake file with the data from the hash + ref containing all the file lists. + + The variables are supposed to be defined in the following format: + + set(var + foo + bar + baz + ) + + Notably, each file has to be on its own line, including the first one. + + Takes the (open) file handles of the files to read and to write and the file + lists hash ref as arguments. + + Returns 1 if any changes were made. + =cut + + sub update_cmakefile + { + my ($in, $out, $vars) = @_; + + # Variable whose contents is being currently replaced. + my $var; + + # Hash with files defined for the specified variable as keys and 0 or 1 + # depending on whether we have seen them in the input file as values. + my %files; + + # Set to 1 if we made any changes. + my $changed = 0; + while (<$in>) { + # Preserve the original line to be able to output it with any comments + # that we strip below. + my $line_orig = $_; + + # Get rid of white space and comments. + chomp; + s/^\s+//; + s/\s+$//; + s/ *#.*$//; + + # Are we inside a variable definition? + if (defined $var) { + if (/^\)$/) { + # End of variable definition, check if we have any new files. + # + # TODO Insert them in alphabetical order. + while (my ($file, $seen) = each(%files)) { + if (!$seen) { + # This file wasn't present in the input, add it. + # TODO Use proper indentation. + print $out " $file\n"; + + $changed = 1; + } + } + + undef $var; + } elsif ($_) { + # We're inside a variable definition. + if (not exists $files{$_}) { + # This file was removed. + $changed = 1; + next; + } + + if ($files{$_}) { + warn qq{Duplicate file "$_" in the definition of the } . + qq{variable "$var" at line $.\n} + } else { + $files{$_} = 1; + } + } + } elsif (/^set *\( *(\w+)$/ && exists $vars->{$1}) { + # Start of a new variable definition. + $var = $1; + + %files = map { _var_to_cmake($_) => 0 } @{$vars->{$var}}; + } + + print $out $line_orig; + } + + $changed + } +MAKEFILE_UPDATE_CMAKEFILE + $fatpacked{"Makefile/Update/MSBuild.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'MAKEFILE_UPDATE_MSBUILD'; package Makefile::Update::MSBuild; # ABSTRACT: Update list of sources and headers in MSBuild projects. @@ -1214,6 +1340,7 @@ use FindBin qw($Bin); use Makefile::Update; use Makefile::Update::Bakefile0; +use Makefile::Update::CMakefile; use Makefile::Update::MSBuild; use Makefile::Update::VCProj; @@ -1261,6 +1388,10 @@ if (!$only_msvs) { } } +if (!$only_msvs && !$only_bkl) { + call_upmake("$Bin/cmake/files.cmake", \&update_cmakefile, $vars); +} + if (!$only_bkl) { # Path to the project root directory from the directory containing the # projects. diff --git a/build/upmake_script.pl b/build/upmake_script.pl index a0855b04e6..f11bbeaf72 100755 --- a/build/upmake_script.pl +++ b/build/upmake_script.pl @@ -10,6 +10,7 @@ use FindBin qw($Bin); use Makefile::Update; use Makefile::Update::Bakefile0; +use Makefile::Update::CMakefile; use Makefile::Update::MSBuild; use Makefile::Update::VCProj; @@ -57,6 +58,10 @@ if (!$only_msvs) { } } +if (!$only_msvs && !$only_bkl) { + call_upmake("$Bin/cmake/files.cmake", \&update_cmakefile, $vars); +} + if (!$only_bkl) { # Path to the project root directory from the directory containing the # projects.