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

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

View File

@@ -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()

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.

View File

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