diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-11-16 22:03:26 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-11-18 17:37:35 -0500 |
commit | a01919976eb08277bad78bb22937601cf5a862e0 (patch) | |
tree | e366cba35d5e16664c5e3557fd44eb5f17149b07 | |
parent | 996f4d89f3d60731306a6a72b339eb5c2dbb5020 (diff) | |
download | meson-a01919976eb08277bad78bb22937601cf5a862e0.zip meson-a01919976eb08277bad78bb22937601cf5a862e0.tar.gz meson-a01919976eb08277bad78bb22937601cf5a862e0.tar.bz2 |
Always specify installed data with a File object. Closes #858.
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 12 | ||||
-rw-r--r-- | mesonbuild/build.py | 8 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 31 | ||||
-rw-r--r-- | mesonbuild/mesonlib.py | 9 | ||||
-rw-r--r-- | mesonbuild/modules/gnome.py | 5 | ||||
-rw-r--r-- | mesonbuild/modules/pkgconfig.py | 2 | ||||
-rw-r--r-- | test cases/common/12 data/fileobject_datafile.dat | 1 | ||||
-rw-r--r-- | test cases/common/12 data/installed_files.txt | 1 | ||||
-rw-r--r-- | test cases/common/12 data/meson.build | 1 |
9 files changed, 46 insertions, 24 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index fa4d5cf..2cd3724 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -682,18 +682,16 @@ int dummy; def generate_data_install(self, d): data = self.build.get_data() + srcdir = self.environment.get_source_dir() + builddir = self.environment.get_build_dir() for de in data: assert(isinstance(de, build.Data)) subdir = de.install_dir for f in de.sources: - plain_f = os.path.split(f)[1] - if de.in_sourcetree: - srcprefix = self.environment.get_source_dir() - else: - srcprefix = self.environment.get_build_dir() - srcabs = os.path.join(srcprefix, de.source_subdir, f) + assert(isinstance(f, mesonlib.File)) + plain_f = os.path.split(f.fname)[1] dstabs = os.path.join(subdir, plain_f) - i = [srcabs, dstabs] + i = [f.absolute_path(srcdir, builddir), dstabs] d.data.append(i) def generate_subdir_install(self, d): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 42cdc57..0e23777 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1393,11 +1393,13 @@ class ConfigurationData(): # A bit poorly named, but this represents plain data files to copy # during install. class Data(): - def __init__(self, in_sourcetree, source_subdir, sources, install_dir): - self.in_sourcetree = in_sourcetree - self.source_subdir = source_subdir + def __init__(self, sources, install_dir): self.sources = sources self.install_dir = install_dir + if not isinstance(self.sources, list): + self.sources = [self.sources] + for s in self.sources: + assert(isinstance(s, File)) class InstallScript: def __init__(self, cmd_arr): diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 6becdb6..ac04b1a 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -483,15 +483,11 @@ class Headers(InterpreterObject): return self.custom_install_dir class DataHolder(InterpreterObject): - def __init__(self, in_sourcetree, source_subdir, sources, kwargs): + def __init__(self, sources, install_dir): super().__init__() - kwsource = mesonlib.stringlistify(kwargs.get('sources', [])) - sources += kwsource - check_stringlist(sources) - install_dir = kwargs.get('install_dir', None) if not isinstance(install_dir, str): raise InterpreterException('Custom_install_dir must be a string.') - self.held_object = build.Data(in_sourcetree, source_subdir, sources, install_dir) + self.held_object = build.Data(sources, install_dir) def get_source_subdir(self): return self.held_object.source_subdir @@ -2208,9 +2204,19 @@ requirements use the version keyword argument instead.''') self.evaluate_codeblock(codeblock) self.subdir = prev_subdir - @stringArgs def func_install_data(self, node, args, kwargs): - data = DataHolder(True, self.subdir, args, kwargs) + kwsource = mesonlib.stringlistify(kwargs.get('sources', [])) + raw_sources = args + kwsource + sources = [] + source_strings = [] + for s in raw_sources: + if isinstance(s, mesonlib.File): + sources.append(s) + else: + source_strings.append(s) + sources += self.source_strings_to_files(source_strings) + install_dir = kwargs.get('install_dir', None) + data = DataHolder(sources, install_dir) self.build.data.append(data.held_object) return data @@ -2240,11 +2246,12 @@ requirements use the version keyword argument instead.''') raise InterpreterException('Output must be a string.') if os.path.split(output)[0] != '': raise InterpreterException('Output file name must not contain a subdirectory.') + (ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output)) + ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname) if 'configuration' in kwargs: conf = kwargs['configuration'] if not isinstance(conf, ConfigurationDataHolder): raise InterpreterException('Argument "configuration" is not of type configuration_data') - ofile_abs = os.path.join(self.environment.build_dir, self.subdir, output) if inputfile is not None: # Normalize the path of the conffile to avoid duplicates # This is especially important to convert '/' to '\' on Windows @@ -2266,8 +2273,10 @@ requirements use the version keyword argument instead.''') (res.stdout, res.stderr)) else: raise InterpreterException('Configure_file must have either "configuration" or "command".') - if isinstance(kwargs.get('install_dir', None), str): - self.build.data.append(DataHolder(False, self.subdir, [output], kwargs).held_object) + idir = kwargs.get('install_dir', None) + if isinstance(idir, str): + cfile = mesonlib.File.from_built_file(ofile_path, ofile_fname) + self.build.data.append(DataHolder([cfile], idir).held_object) return mesonlib.File.from_built_file(self.subdir, output) @stringArgs diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 943a23e..b92be5f 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -58,6 +58,12 @@ class File: else: return os.path.join(build_to_src, self.subdir, self.fname) + def absolute_path(self, srcdir, builddir): + if self.is_built: + return os.path.join(builddir, self.subdir, self.fname) + else: + return os.path.join(srcdir, self.subdir, self.fname) + def endswith(self, ending): return self.fname.endswith(ending) @@ -70,6 +76,9 @@ class File: def __hash__(self): return hash((self.fname, self.subdir, self.is_built)) + def relative_name(self): + return os.path.join(self.subdir, self.fname) + def get_compiler_for_source(compilers, src): for comp in compilers: if comp.can_compile(src): diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index e15147a..114114d 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -921,13 +921,13 @@ can not be used with the current version of glib-compiled-resources, due to vapi_args = ret + self._vapi_args_to_command('--pkg=', 'packages', kwargs, accept_vapi=True) return vapi_args, vapi_depends, vapi_packages, vapi_includes - def _generate_deps(self, state, library, packages, indir): + def _generate_deps(self, state, library, packages, install_dir): outdir = state.environment.scratch_dir fname = os.path.join(outdir, library + '.deps') with open(fname, 'w') as ofile: for package in packages: ofile.write(package + '\n') - return build.Data(False, outdir, [fname], indir) + return build.Data(mesonlib.File(True, outdir, fname), install_dir) def _get_vapi_link_with(self, target): link_with = [] @@ -993,6 +993,7 @@ can not be used with the current version of glib-compiled-resources, due to # We shouldn't need this locally but we install it deps_target = self._generate_deps(state, library, vapi_packages, install_dir) + # XXX WRONG, state objects must not be modified! Fix this! state.data.append(deps_target) vapi_target = VapiTarget(vapi_output, state.subdir, custom_kwargs) diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 3ecb40d..9f50b0e 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -138,7 +138,7 @@ class PkgConfigModule: self.generate_pkgconfig_file(state, libs, subdirs, name, description, url, version, pcfile, pub_reqs, priv_reqs, conflicts, priv_libs) - return build.Data(False, state.environment.get_scratch_dir(), [pcfile], pkgroot) + return build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), pcfile), pkgroot) def initialize(): return PkgConfigModule() diff --git a/test cases/common/12 data/fileobject_datafile.dat b/test cases/common/12 data/fileobject_datafile.dat new file mode 100644 index 0000000..872aa5a --- /dev/null +++ b/test cases/common/12 data/fileobject_datafile.dat @@ -0,0 +1 @@ +This is a data file that is installed via a File object. diff --git a/test cases/common/12 data/installed_files.txt b/test cases/common/12 data/installed_files.txt index 3d4b12c..8651e3a 100644 --- a/test cases/common/12 data/installed_files.txt +++ b/test cases/common/12 data/installed_files.txt @@ -1,4 +1,5 @@ usr/share/progname/datafile.dat +usr/share/progname/fileobject_datafile.dat usr/share/progname/vanishing.dat usr/share/progname/vanishing2.dat etc/etcfile.dat diff --git a/test cases/common/12 data/meson.build b/test cases/common/12 data/meson.build index 80f3835..7494abc 100644 --- a/test cases/common/12 data/meson.build +++ b/test cases/common/12 data/meson.build @@ -1,6 +1,7 @@ project('data install test', 'c') install_data(sources : 'datafile.dat', install_dir : 'share/progname') install_data(sources : 'etcfile.dat', install_dir : '/etc') +install_data(files('fileobject_datafile.dat'), install_dir : 'share/progname') subdir('vanishing') |