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