2023-12-14 03:38:41 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2016-01-16 05:37:22 +08:00
|
|
|
# Copyright 2015-2016 The Meson development team
|
2015-11-05 02:00:04 +08:00
|
|
|
|
2022-09-14 09:22:35 +08:00
|
|
|
from __future__ import annotations
|
2015-11-05 02:00:04 +08:00
|
|
|
|
2015-11-05 02:59:02 +08:00
|
|
|
import sys, os
|
|
|
|
import pickle, subprocess
|
2020-08-30 03:23:43 +08:00
|
|
|
import typing as T
|
2020-09-02 01:36:21 +08:00
|
|
|
from ..coredata import CoreData
|
2021-04-19 02:25:46 +08:00
|
|
|
from ..backend.backends import RegenInfo
|
2020-12-05 09:01:45 +08:00
|
|
|
from ..mesonlib import OptionKey
|
2015-11-05 02:00:04 +08:00
|
|
|
|
|
|
|
# This could also be used for XCode.
|
|
|
|
|
2020-09-02 01:36:21 +08:00
|
|
|
def need_regen(regeninfo: RegenInfo, regen_timestamp: float) -> bool:
|
2015-11-05 02:59:02 +08:00
|
|
|
for i in regeninfo.depfiles:
|
|
|
|
curfile = os.path.join(regeninfo.build_dir, i)
|
|
|
|
curtime = os.stat(curfile).st_mtime
|
2016-02-26 06:09:44 +08:00
|
|
|
if curtime > regen_timestamp:
|
2015-11-05 02:59:02 +08:00
|
|
|
return True
|
2016-02-26 06:09:44 +08:00
|
|
|
# The timestamp file gets automatically deleted by MSBuild during a 'Clean' build.
|
|
|
|
# We must make sure to recreate it, even if we do not regenerate the solution.
|
|
|
|
# Otherwise, Visual Studio will always consider the REGEN project out of date.
|
|
|
|
print("Everything is up-to-date, regeneration of build files is not needed.")
|
2016-12-07 02:54:17 +08:00
|
|
|
from ..backend.vs2010backend import Vs2010Backend
|
2016-02-26 06:09:44 +08:00
|
|
|
Vs2010Backend.touch_regen_timestamp(regeninfo.build_dir)
|
2015-11-05 02:59:02 +08:00
|
|
|
return False
|
|
|
|
|
2020-09-02 01:36:21 +08:00
|
|
|
def regen(regeninfo: RegenInfo, meson_command: T.List[str], backend: str) -> None:
|
2017-11-21 05:38:26 +08:00
|
|
|
cmd = meson_command + ['--internal',
|
|
|
|
'regenerate',
|
|
|
|
regeninfo.build_dir,
|
|
|
|
regeninfo.source_dir,
|
|
|
|
'--backend=' + backend]
|
2015-11-05 02:59:02 +08:00
|
|
|
subprocess.check_call(cmd)
|
|
|
|
|
2020-08-30 03:23:43 +08:00
|
|
|
def run(args: T.List[str]) -> int:
|
2016-02-26 06:09:44 +08:00
|
|
|
private_dir = args[0]
|
|
|
|
dumpfile = os.path.join(private_dir, 'regeninfo.dump')
|
2020-08-30 03:23:43 +08:00
|
|
|
coredata_file = os.path.join(private_dir, 'coredata.dat')
|
2016-08-25 07:29:11 +08:00
|
|
|
with open(dumpfile, 'rb') as f:
|
2020-09-02 01:36:21 +08:00
|
|
|
regeninfo = pickle.load(f)
|
|
|
|
assert isinstance(regeninfo, RegenInfo)
|
2020-08-30 03:23:43 +08:00
|
|
|
with open(coredata_file, 'rb') as f:
|
2016-08-25 07:29:11 +08:00
|
|
|
coredata = pickle.load(f)
|
2020-09-02 01:36:21 +08:00
|
|
|
assert isinstance(coredata, CoreData)
|
2020-12-05 09:01:45 +08:00
|
|
|
backend = coredata.get_option(OptionKey('backend'))
|
2020-09-02 01:36:21 +08:00
|
|
|
assert isinstance(backend, str)
|
2016-02-26 06:09:44 +08:00
|
|
|
regen_timestamp = os.stat(dumpfile).st_mtime
|
|
|
|
if need_regen(regeninfo, regen_timestamp):
|
Set the meson command to use when we know what it is
Instead of using fragile guessing to figure out how to invoke meson,
set the value when meson is run. Also rework how we pass of
meson_script_launcher to regenchecker.py -- it wasn't even being used
With this change, we only need to guess the meson path when running
the tests, and in that case:
1. If MESON_EXE is set in the env, we know how to run meson
for project tests.
2. MESON_EXE is not set, which means we run the configure in-process
for project tests and need to guess what meson to run, so either
- meson.py is found next to run_tests.py, or
- meson, meson.py, or meson.exe is in PATH
Otherwise, you can invoke meson in the following ways:
1. meson is installed, and mesonbuild is available in PYTHONPATH:
- meson, meson.py, meson.exe from PATH
- python3 -m mesonbuild.mesonmain
- python3 /path/to/meson.py
- meson is a shell wrapper to meson.real
2. meson is not installed, and is run from git:
- Absolute path to meson.py
- Relative path to meson.py
- Symlink to meson.py
All these are tested in test_meson_commands.py, except meson.exe since
that involves building the meson msi and installing it.
2018-06-01 15:30:17 +08:00
|
|
|
regen(regeninfo, coredata.meson_command, backend)
|
2020-08-30 03:23:43 +08:00
|
|
|
return 0
|
2016-01-16 05:37:22 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-08-30 03:23:43 +08:00
|
|
|
sys.exit(run(sys.argv[1:]))
|