Browse Source

Fix use of cmake. Show more output.

master
poikilos 5 years ago
parent
commit
c4f8fca70e
  1. 102
      mtcompile-program-local.py
  2. 39
      utilities/mtcompile-program-local.pl

102
mtcompile-program-local.py

@ -215,6 +215,29 @@ mtcompile-program.pl.
# program parameters # program parameters
#--------------------------------------------------------------------- #---------------------------------------------------------------------
def streamEdit(inPath, replacements):
"""
Replace parts similarly to sed ("stream editor").
See David Miller's Dec 13, 2010 answer edited by dpb Jul 23, 2013
on <https://stackoverflow.com/questions/4427542/how-to-do-sed-like-
text-replace-with-python>
Sequential arguments:
inPath -- Edit then save the file at this path.
replacements -- a replacements dict where the key is the string or
regex, and the value is the new string to use in cases of]
matches.
"""
with open(inPath, "r") as sources:
lines = sources.readlines()
with open(inPath, "w") as sources:
for rawLine in lines:
line = rawLine
for k, v in replacements.items():
line = re.sub(k, v, line)
sources.write(line)
def _UNUSED_evalSed(line, sedStr): def _UNUSED_evalSed(line, sedStr):
""" """
@ -316,20 +339,53 @@ def popd():
os.chdir(DirStack[-1]) os.chdir(DirStack[-1])
def RunCmd(cmdParts, exitOnFail=True): def execute(cmd, shell=True):
"""
Iterate output of a command.
See tokland's Dec 11, 2010 answer on <https://stackoverflow.com/
questions/4417546/constantly-print-subprocess-output-while-
process-is-running>
"""
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,
universal_newlines=True,
shell=shell)
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line
popen.stdout.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
def RunCmd(cmdParts, exitOnFail=True, shell=True):
# Popen can get confused when arguments contain quotes # Popen can get confused when arguments contain quotes
# (see <https://stackoverflow.com/questions/14928860/passing-double- # (see <https://stackoverflow.com/questions/14928860/passing-double-
# quote-shell-commands-in-python-to-subprocess-popen>) such as # quote-shell-commands-in-python-to-subprocess-popen>) such as
# in "-DCMAKE_CXX_FLAG="+XCFLAGS where XCFLAGS contains quotes. # in "-DCMAKE_CXX_FLAG="+XCFLAGS where XCFLAGS contains quotes.
child = subprocess.Popen(cmdParts, shell=True, # child = subprocess.Popen(cmdParts, shell=shell,
stdout=subprocess.PIPE) # stdout=subprocess.PIPE,
streamdata = child.communicate()[0] # universal_newlines=True)
rc = child.returncode # streamdata = child.communicate()[0]
if rc != 0: # rc = child.returncode
# Instead of communicate, read the lines (See def execute)
# if rc != 0:
# if exitOnFail:
# exit(rc)
# else:
# print("WARNING: {} failed".format(' '.join(cmdParts)))
try:
for line in execute(cmdParts, shell=shell):
print(line, end="")
except subprocess.CalledProcessError as ex:
msg = ("The process '{}' ended with error code {}."
"".format(" ".join(ex.cmd), ex.returncode))
if exitOnFail: if exitOnFail:
exit(rc) print("ERROR: " + msg)
exit(ex.returncode)
else: else:
print("WARNING: {} failed".format(' '.join(cmdParts))) print("WARNING: " + msg)
def FixStr(s): def FixStr(s):
@ -940,33 +996,36 @@ again.
cmdParts.append("-DCMAKE_CXX_FLAGS=\"{}\"".format(XCFLAGS)) cmdParts.append("-DCMAKE_CXX_FLAGS=\"{}\"".format(XCFLAGS))
cmdParts.append("-DCMAKE_C_FLAGS_RELEASE=\"{}\"".format(XCFLAGS)) cmdParts.append("-DCMAKE_C_FLAGS_RELEASE=\"{}\"".format(XCFLAGS))
cmdParts.append("-DCMAKE_CXX_FLAGS_RELEASE=\"{}\"".format(XCFLAGS)) cmdParts.append("-DCMAKE_CXX_FLAGS_RELEASE=\"{}\"".format(XCFLAGS))
cmdParts.append(".")
print("") print("")
print("") print("")
print("Running cmake in {}:".format(os.getcwd())) print("* running cmake in {}:".format(os.getcwd()))
print(" ".join(cmdParts)) print(" ".join(cmdParts))
print("") print("")
print("") print("")
RunCmd(cmdParts); RunCmd(cmdParts[:1] + [" ".join(cmdParts[1:])], shell=False)
# ^ must be false to avoid inserting quotes automatically
# TODO: use some absolute pathnames as the Perl version does # TODO: use some absolute pathnames as the Perl version does
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Replace some "-l..." switches with absolute pathnames. # Replace some "-l..." switches with absolute pathnames.
# cmd = << "END" replacements = {
# sed -e "s:-lIrrlicht:$IRRLICHT_LIBRARY:g" "-lIrrlicht": IRRLICHT_LIBRARY,
# -e "s:-lleveldb:$LEVELDB_LIBRARY:g" "-lleveldb": LEVELDB_LIBRARY,
# -e "s:-lluajit-5.1:$LUA_LIBRARY:g" "-lluajit-5.1": LUA_LIBRARY,
# -e "s:-lsqlite3:$SQLITE3_LIBRARY:g" "-lsqlite3": SQLITE3_LIBRARY,
# END }
# cmd . = << 'END' for root, dirs, files in os.walk(PRODDIR):
# -i `find . -type f -name link.txt` for name in files:
# END subPath = os.path.join(root, name)
# cmd = &FixStr ( + cmd + ) if name == "link.txt":
# RunCmd (cmd.split(" ")) #TODO use cmdParts after editing it streamEdit(subPath, replacements)
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Build the program. # Build the program.
NUMJOBS = 3 NUMJOBS = 3
print("* running make in {}...".format(os.getcwd()))
RunCmd(["make", "clean"]) RunCmd(["make", "clean"])
RunCmd("make", "-j{}".format(NUMJOBS)) RunCmd("make", "-j{}".format(NUMJOBS))
serverlistDir = os.path.join(PRODDIR, "client", "serverlist") serverlistDir = os.path.join(PRODDIR, "client", "serverlist")
@ -997,6 +1056,7 @@ again.
# Bucket_Game and do nothing else differently? # Bucket_Game and do nothing else differently?
# See mtcompile-program.pl # See mtcompile-program.pl
gameNames.append("Bucket_Game") gameNames.append("Bucket_Game")
gamePaths = [os.path.join(PRODDIR, gName) for gName in gameNames]
print("* purging gamepaths: {}".format(gamePaths)) print("* purging gamepaths: {}".format(gamePaths))
for gameName in gameNames: for gameName in gameNames:
gamePath = os.path.join(PRODDIR, gameName) gamePath = os.path.join(PRODDIR, gameName)

39
utilities/mtcompile-program-local.pl

@ -270,7 +270,7 @@ sub GetProgDir
} }
my $cwd = getcwd(); my $cwd = getcwd();
chdir ($ProgTemp) || die; #chdir ($ProgTemp) || die;
my $ProgDir = getcwd(); my $ProgDir = getcwd();
chdir ($cwd) || die "$IE #048837\n"; chdir ($cwd) || die "$IE #048837\n";
$ProgDir; $ProgDir;
@ -648,27 +648,33 @@ END
} }
$cmd = << "END"; $cmd = << "END";
rm -fr $PRODDIR minetest-newline* || exit 1 rm -fr "$PRODDIR" minetest-newline* || exit 1
mkdir $PRODDIR minetest-newline || exit 1 mkdir "$PRODDIR" minetest-newline || exit 1
rmdir $PRODDIR minetest-newline || exit 1 rmdir "$PRODDIR" minetest-newline || exit 1
END END
my $CUSTOM_MT_SRC = "$ENV{'HOME'}/git/minetest"; my $CUSTOM_MT_SRC = "$ENV{'HOME'}/git/minetest";
if (-d $CUSTOM_MT_SRC) { if (-d $CUSTOM_MT_SRC) {
print("Using CUSTOM_MT_SRC $CUSTOM_MT_SRC as $PRODDIR\n"); print("Using CUSTOM_MT_SRC $CUSTOM_MT_SRC as $PRODDIR\n");
$cmd = << "END"; $cmd = << "END";
cp -R $CUSTOM_MT_SRC $PRODDIR || exit 1 rm -fr "$PRODDIR" minetest-newline* || exit 1
cp -R "$CUSTOM_MT_SRC" "$PRODDIR" || exit 1
END END
} }
else { else {
$cmd = << "END" if $FlagEdgy; $cmd = << "END" if $FlagEdgy;
tar jxf $BALLDIR/minetest-edgytest.tar.bz2 || exit 1 tar jxf "$BALLDIR/minetest-edgytest.tar.bz2" || exit 1
mv minetest-edgytest* $PRODDIR || exit 1 mv minetest-edgytest* "$PRODDIR" || exit 1
END END
$cmd = << "END" unless $FlagEdgy; $cmd = << "END" unless $FlagEdgy;
tar jxf $BALLDIR/minetest-newline.tar.bz2 || exit 1 tar jxf "$BALLDIR/minetest-newline.tar.bz2" || exit 1
mv minetest-newline* $PRODDIR || exit 1 mv minetest-newline* "$PRODDIR" || exit 1
END END
} }
print("Running (in ");
print(getcwd());
print("):");
print($cmd);
print("\n");
&RunCmd ($cmd); &RunCmd ($cmd);
} }
@ -885,6 +891,10 @@ $redis_line
. .
END END
$cmd = &FixStr ($cmd); $cmd = &FixStr ($cmd);
print("\n\nRunning (in ");
print(getcwd());
print("):");
print($cmd);
&RunCmd ($cmd); &RunCmd ($cmd);
#--------------------------------------------------------------------- #---------------------------------------------------------------------
@ -900,7 +910,18 @@ END
-i `find . -type f -name link.txt` -i `find . -type f -name link.txt`
END END
$cmd = &FixStr ($cmd); $cmd = &FixStr ($cmd);
print("\n\n\nBEFORE:\n");
&RunCmd ("find . -type f -name link.txt -exec tail +999 {} \\;");
print("\n\nRunning (in ");
print(getcwd());
print("):");
print($cmd);
&RunCmd ($cmd); &RunCmd ($cmd);
print("\n\n\nAFTER, in ");
print(getcwd());
print(":\n");
&RunCmd ("find . -type f -name link.txt -exec tail +999 {} \\;");
# die("breakpoint");
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Build the program. # Build the program.

Loading…
Cancel
Save