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.
This commit is contained in:
Vadim Zeitlin
2018-01-07 22:29:42 +01:00
parent b2a8c2188f
commit 267067aa8a
4 changed files with 137 additions and 78 deletions

View File

@@ -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.