summaryrefslogtreecommitdiffstats
path: root/configgen/bin/make-config.pl
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /configgen/bin/make-config.pl
Publish
Diffstat (limited to 'configgen/bin/make-config.pl')
-rwxr-xr-xconfiggen/bin/make-config.pl134
1 files changed, 134 insertions, 0 deletions
diff --git a/configgen/bin/make-config.pl b/configgen/bin/make-config.pl
new file mode 100755
index 00000000000..4629e6e3240
--- /dev/null
+++ b/configgen/bin/make-config.pl
@@ -0,0 +1,134 @@
+#!/usr/local/bin/perl
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#
+# This script transforms a .def file into a .h and .cpp file for config
+#
+# TODO: Remove this script and use the java code directly. BTW, why
+# does this script have the same limitations as the old make-config.pl
+# in that the .def-file must reside in the root directory? The java
+# code supports reading the .def-file from any directory. This script
+# should have the same input parameters as the java code, and just
+# map them directly to the java system properties
+
+# BEGIN perl environment bootstrap section
+# Do not edit between here and END as this section should stay identical in all scripts
+
+use File::Basename;
+use File::Path;
+
+sub findpath {
+ my $myfullname = ${0};
+ my($myname, $mypath) = fileparse($myfullname);
+
+ return $mypath if ( $mypath && -d $mypath );
+ $mypath=`pwd`;
+
+ my $pwdfullname = $mypath . "/" . $myname;
+ return $mypath if ( -f $pwdfullname );
+ return 0;
+}
+
+# Returns the argument path if it seems to point to VESPA_HOME, 0 otherwise
+sub is_vespa_home {
+ my($VESPA_HOME) = shift;
+ my $COMMON_ENV="libexec/vespa/common-env.sh";
+ if ( $VESPA_HOME && -d $VESPA_HOME ) {
+ my $common_env = $VESPA_HOME . "/" . $COMMON_ENV;
+ return $VESPA_HOME if -f $common_env;
+ }
+ return 0;
+}
+
+# Returns the home of Vespa, or dies if it cannot
+sub findhome {
+ # Try the VESPA_HOME env variable
+ return $ENV{'VESPA_HOME'} if is_vespa_home($ENV{'VESPA_HOME'});
+ if ( $ENV{'VESPA_HOME'} ) { # was set, but not correctly
+ die "FATAL: bad VESPA_HOME value '" . $ENV{'VESPA_HOME'} . "'\n";
+ }
+
+ # Try the ROOT env variable
+ $ROOT = $ENV{'ROOT'};
+ return $ROOT if is_vespa_home($ROOT);
+
+ # Try the script location or current dir
+ my $mypath = findpath();
+ if ($mypath) {
+ while ( $mypath =~ s|/[^/]*$|| ) {
+ return $mypath if is_vespa_home($mypath);
+ }
+ }
+ die "FATAL: Missing VESPA_HOME environment variable\n";
+}
+
+BEGIN {
+ my $tmp = findhome();
+ if ( $tmp !~ m{[/]$} ) { $tmp .= "/"; }
+ $ENV{'VESPA_HOME'} = $tmp;
+}
+my $VESPA_HOME = $ENV{'VESPA_HOME'};
+
+# END perl environment bootstrap section
+
+use lib $ENV{'VESPA_HOME'} . '/lib/perl5/site_perl';
+use Yahoo::Vespa::Defaults;
+readConfFile();
+
+require 5.006_001;
+use strict;
+use warnings;
+
+use Cwd 'abs_path';
+
+# Now this uses the new java codegen library. But the script still exist to
+# map be able to call java the right way, setting the necessary properties
+
+my ($root, $def) = @ARGV;
+
+if (!defined $root || !defined $def) {
+ print "Usage make-config.pl <source root dir> <def file>\n";
+ exit(1);
+}
+
+#print "Root: $root\n"
+# . "Def: $def\n";
+
+my $subdir = &getRelativePath($root, &getPath($def));
+
+my $cmd = "java"
+ . " -Dconfig.spec=$def"
+ . " -Dconfig.dest=$root"
+ . " -Dconfig.lang=cppng"
+ . " -Dconfig.requireNamespace=false"
+ . " -Dconfig.subdir=$subdir"
+ . " -Dconfig.dumpTree=false"
+ . " -Xms64m -Xmx64m"
+ . " -jar $VESPA_HOME/lib/jars/configgen.jar";
+
+print "Generating config: $cmd\n";
+exec($cmd);
+
+exit(0); # Will never be called due to exec above, but just to indicate end
+
+sub getRelativePath {
+ my ($from, $to) = @_;
+
+ $from = abs_path($from);
+ $to = abs_path($to);
+
+ # Escape $from so it can contain regex special characters in path
+ $from =~ s/([\+\*\(\)\{\}\.\?\[\]\$\&])/\\$1/g;
+
+ $to =~ /^$from\/(.*)$/
+ or die "The def file must be contained within the root";
+ return $1;
+}
+
+sub getPath {
+ my $file = $_[0];
+ if ($file =~ /^(.*)\/[^\/]*$/) {
+ return $1;
+ } else {
+ return ".";
+ }
+}