Phil Dawson pushed to branch phil/source-checkout-options at BuildStream / buildstream
Commits:
-
0c530782
by Phil Dawson at 2018-11-22T11:56:04Z
-
502ab152
by Phil Dawson at 2018-11-22T11:56:40Z
-
4fd2c848
by Phil Dawson at 2018-11-22T14:28:23Z
-
9116016a
by Phil Dawson at 2018-11-22T15:46:09Z
-
05c8bdbc
by Phil Dawson at 2018-11-22T17:10:50Z
3 changed files:
Changes:
... | ... | @@ -2,6 +2,17 @@ |
2 | 2 |
buildstream 1.3.1
|
3 | 3 |
=================
|
4 | 4 |
|
5 |
+ o BREAKING CHANGE: The bst source-bundle command has been removed. The
|
|
6 |
+ functionality it provided has been replaced by the `--include-build-scripts`
|
|
7 |
+ option of the `bst source-checkout` command. To produce a tarball containing
|
|
8 |
+ an element's sources and generated build scripts you can do the command
|
|
9 |
+ `bst source-checkout --include-build-scripts --tar foo.bst some-file.tar`
|
|
10 |
+ |
|
11 |
+ o A `bst source-checkout` command has been added. This command allows an
|
|
12 |
+ element's sources to be checkout out into a user specified location. For
|
|
13 |
+ example, `bst source-checkout foo.bst some/path/` will collect the sources
|
|
14 |
+ of `foo.bst` and place them in the directory `some/path`.
|
|
15 |
+ |
|
5 | 16 |
o BREAKING CHANGE: The 'manual' element lost its default 'MAKEFLAGS' and 'V'
|
6 | 17 |
environment variables. There is already a 'make' element with the same
|
7 | 18 |
variables. Note that this is a breaking change, it will require users to
|
... | ... | @@ -678,11 +678,11 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar): |
678 | 678 |
help='The dependencies whose sources to checkout (default: none)')
|
679 | 679 |
@click.option('--fetch', 'fetch_', default=False, is_flag=True,
|
680 | 680 |
help='Fetch elements if they are not fetched')
|
681 |
-@click.option('--tar', 'tar_', default=False, is_flag=True,
|
|
681 |
+@click.option('--tar', 'tar', default=False, is_flag=True,
|
|
682 | 682 |
help='Create a tarball from the element\'s sources instead of a '
|
683 |
- 'file tree. If LOCATION is \'-\', the tarball will be dumped '
|
|
684 |
- 'to the standard output.')
|
|
685 |
-@click.option('--include-build-scripts', 'build_scripts', is_flag=True)
|
|
683 |
+ 'file tree.')
|
|
684 |
+@click.option('--include-build-scripts', 'build_scripts', is_flag=True,
|
|
685 |
+ help='Include the elements\' build scripts which can be manually executed')
|
|
686 | 686 |
@click.argument('element',
|
687 | 687 |
type=click.Path(readable=False))
|
688 | 688 |
@click.argument('location', type=click.Path())
|
... | ... | @@ -698,7 +698,7 @@ def source_checkout(app, element, location, force, deps, fetch_, except_, |
698 | 698 |
deps=deps,
|
699 | 699 |
fetch=fetch_,
|
700 | 700 |
except_targets=except_,
|
701 |
- tar=tar_,
|
|
701 |
+ tar=tar,
|
|
702 | 702 |
include_build_scripts=build_scripts)
|
703 | 703 |
|
704 | 704 |
|
... | ... | @@ -1060,12 +1060,31 @@ class Stream(): |
1060 | 1060 |
tar=False,
|
1061 | 1061 |
include_build_scripts=False):
|
1062 | 1062 |
location = os.path.abspath(location)
|
1063 |
+ |
|
1064 |
+ # Stage all our sources in a temporary directory. The this
|
|
1065 |
+ # directory can be used to either construct a tarball or moved
|
|
1066 |
+ # to the final desired location.
|
|
1067 |
+ temp_source_dir = self._create_temp_source_dir(elements, include_build_scripts)
|
|
1063 | 1068 |
if tar:
|
1064 |
- self._create_source_tarball(location, elements, include_build_scripts)
|
|
1069 |
+ self._create_tarball(temp_source_dir.name, location)
|
|
1065 | 1070 |
else:
|
1066 |
- self._write_element_sources(location, elements)
|
|
1067 |
- if include_build_scripts:
|
|
1068 |
- self._write_build_scripts(location, elements)
|
|
1071 |
+ os.rename(temp_source_dir.name, location)
|
|
1072 |
+ |
|
1073 |
+ # Ensure the temporary directory is cleaned up. If it has been
|
|
1074 |
+ # moved temp_source_dir will no longer exist with it's
|
|
1075 |
+ # original name. This is expected.
|
|
1076 |
+ try:
|
|
1077 |
+ temp_source_dir.cleanup()
|
|
1078 |
+ except FileNotFoundError:
|
|
1079 |
+ pass
|
|
1080 |
+ |
|
1081 |
+ # Construct a TemporaryDirectory containing the sources of elements.
|
|
1082 |
+ def _create_temp_source_dir(self, elements, include_build_scripts):
|
|
1083 |
+ tempdir = TemporaryDirectory()
|
|
1084 |
+ self._write_element_sources(tempdir.name, elements)
|
|
1085 |
+ if include_build_scripts:
|
|
1086 |
+ self._write_build_scripts(tempdir.name, elements)
|
|
1087 |
+ return tempdir
|
|
1069 | 1088 |
|
1070 | 1089 |
# Write the element build script to the given directory
|
1071 | 1090 |
def _write_element_script(self, directory, element):
|
... | ... | @@ -1083,17 +1102,8 @@ class Stream(): |
1083 | 1102 |
os.makedirs(element_source_dir)
|
1084 | 1103 |
element._stage_sources_at(element_source_dir)
|
1085 | 1104 |
|
1086 |
- # Create a tarball containing the sources of each element in elements
|
|
1087 |
- def _create_source_tarball(self, tar_name, elements, include_build_scripts):
|
|
1088 |
- # Stage sources into a temporary directory then create a tarball from this
|
|
1089 |
- with TemporaryDirectory() as tmpdir:
|
|
1090 |
- self._write_element_sources(tmpdir, elements)
|
|
1091 |
- if include_build_scripts:
|
|
1092 |
- self._write_build_scripts(tmpdir, elements)
|
|
1093 |
- self._create_tar_from_directory(tar_name, tmpdir)
|
|
1094 |
- |
|
1095 | 1105 |
# Create a tarball from the content of directory
|
1096 |
- def _create_tar_from_directory(self, tar_name, directory):
|
|
1106 |
+ def _create_tarball(self, directory, tar_name):
|
|
1097 | 1107 |
try:
|
1098 | 1108 |
with tarfile.open(name=tar_name, mode='w') as tf:
|
1099 | 1109 |
for item in os.listdir(str(directory)):
|
... | ... | @@ -1101,9 +1111,11 @@ class Stream(): |
1101 | 1111 |
tf.add(file_to_add, arcname=item)
|
1102 | 1112 |
except OSError as e:
|
1103 | 1113 |
# If we have a partially constructed tar file, clean up after ourselves
|
1104 |
- if os.path.exists(tar_name):
|
|
1114 |
+ try:
|
|
1105 | 1115 |
os.remove(tar_name)
|
1106 |
- raise StreamError("Failed to create tar archieve: {}".format(e)) from e
|
|
1116 |
+ except OSError:
|
|
1117 |
+ pass
|
|
1118 |
+ raise StreamError("Failed to create tar archive: {}".format(e)) from e
|
|
1107 | 1119 |
|
1108 | 1120 |
# Write all the build_scripts for elements in the directory location
|
1109 | 1121 |
def _write_build_scripts(self, location, elements):
|