-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recording: record stage packages installed in the snap #1293
Changes from all commits
e385059
c7a75e9
102a72c
a7b70ab
4c2c0b5
d2cf3b8
d2dd6b0
0911f86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: basic | ||
version: 0.1 | ||
summary: Summary of the most simple snap | ||
description: Description of the most simple snap | ||
confinement: strict | ||
|
||
parts: | ||
dummy-part: | ||
plugin: nil |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
name: stage-package | ||
name: stage-package-missing-dependency | ||
version: '0.1' | ||
summary: install a stage package | ||
description: | | ||
Install a stage package. | ||
This package has one dependency: gcc-6-base. | ||
|
||
grade: stable | ||
confinement: strict | ||
|
||
parts: | ||
hello: | ||
part-with-stage-package: | ||
plugin: nil | ||
stage-packages: ['hello'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: stage-packages-without-dependencies | ||
version: '0.1' | ||
summary: install stage packages | ||
description: | | ||
Install stage packages. | ||
These packages don't require any additional dependency. | ||
|
||
grade: stable | ||
confinement: strict | ||
|
||
parts: | ||
part-with-stage-packages: | ||
plugin: nil | ||
stage-packages: [gcc-6-base, hello] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,11 @@ | |
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import copy | ||
import contextlib | ||
import os | ||
import configparser | ||
import logging | ||
import os | ||
import re | ||
import shlex | ||
import shutil | ||
|
@@ -32,6 +33,7 @@ | |
from snapcraft.internal.errors import MissingGadgetError | ||
from snapcraft.internal.deprecations import handle_deprecation_notice | ||
from snapcraft.internal.sources import get_source_handler_from_type | ||
from snapcraft.internal.states import get_state | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -137,7 +139,17 @@ def _record_snapcraft(self): | |
if os.environ.get('SNAPCRAFT_BUILD_INFO'): | ||
os.makedirs(record_dir, exist_ok=True) | ||
with open(record_file_path, 'w') as record_file: | ||
yaml.dump(self._config_data, record_file) | ||
annotated_snapcraft = self._annotate_snapcraft( | ||
copy.deepcopy(self._config_data)) | ||
yaml.dump(annotated_snapcraft, record_file) | ||
|
||
def _annotate_snapcraft(self, data): | ||
for part in data['parts']: | ||
pull_state = get_state( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't this be better handled in the pull_stage = get_state(part_name, state) IOW, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes a lot of sense, but that IMO is a different branch because it will touch many other files. @sergiusens would you like it as a prerequisite of this one, or can I add it to my pile and do it after all the existing ones are merged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, after is fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all right, I fixed the typos and merged with master. Thanks for the review. |
||
os.path.join(self._parts_dir, part, 'state'), 'pull') | ||
data['parts'][part]['stage-packages'] = ( | ||
pull_state.assets.get('stage-packages', [])) | ||
return data | ||
|
||
def write_snap_directory(self): | ||
# First migrate the snap directory. It will overwrite any conflicting | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright (C) 2015-2016 Canonical Ltd | ||
# Copyright (C) 2015-2017 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
|
@@ -14,14 +14,15 @@ | |
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import collections | ||
import contextlib | ||
from functools import partial | ||
import io | ||
import os | ||
import sys | ||
import threading | ||
from types import ModuleType | ||
import urllib.parse | ||
from functools import partial | ||
from types import ModuleType | ||
from unittest import mock | ||
from subprocess import CalledProcessError | ||
|
||
|
@@ -553,3 +554,50 @@ def setUp(self): | |
revno = call_with_output(['hg', 'id']).split()[0] | ||
|
||
self.commit = revno | ||
|
||
|
||
class FakeAptCache(fixtures.Fixture): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the most simple fake to get this working. |
||
|
||
def __init__(self, packages): | ||
super().__init__() | ||
self.packages = packages | ||
|
||
def setUp(self): | ||
super().setUp() | ||
temp_dir = fixtures.TempDir() | ||
self.useFixture(temp_dir) | ||
patcher = mock.patch('snapcraft.repo._deb.apt.Cache') | ||
mock_apt_cache = patcher.start() | ||
self.addCleanup(patcher.stop) | ||
|
||
cache = collections.OrderedDict() | ||
for package, version in self.packages: | ||
cache[package] = FakeAptCachePackage( | ||
temp_dir.path, package, version) | ||
|
||
mock_apt_cache().__getitem__.side_effect = ( | ||
lambda item: cache[item]) | ||
|
||
mock_apt_cache().get_changes.return_value = cache.values() | ||
|
||
|
||
class FakeAptCachePackage(): | ||
|
||
def __init__(self, temp_dir, name, version): | ||
super().__init__() | ||
self.temp_dir = temp_dir | ||
self.name = name | ||
self.version = version | ||
self.versions = {version: self} | ||
self.candidate = self | ||
|
||
def __str__(self): | ||
return '{}={}'.format(self.name, self.version) | ||
|
||
def mark_install(self): | ||
pass | ||
|
||
def fetch_binary(self, dir_, progress): | ||
path = os.path.join(self.temp_dir, self.name) | ||
open(path, 'w').close() | ||
return path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to stage the folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, sorry. Added :)