Skip to content
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

Add option to include whole repository #443

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/tito/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ def __init__(self, name=None, tag=None, build_dir=None,
self.tgz_dir = tgz_base
self.artifacts = []

# Details of how to make the tar repo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain these options in man tito.props?

self.tgz_method = self.config.get('archiver', 'method', fallback='git')
self.tgz_include_git = self.config.getboolean('archiver', 'include_git', fallback=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the situations when

  • building a tarball from the last commit is useful
  • building a tarball from the code as is, even with uncommitted changes, is useful

but I can't imagine a situation when using a tarball from the last commit but also containing the .git directory is needed. Do you have a use-case for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this was my problems when building scikit-build-core. It uses setuptools_scm that can detect the tags from the .git folder. They offer an alternative via .gitattributes and generating a .git_archival.txt file, but that also fails without #445. There could be similar projects, in which case that would be the easiest for prototyping or quickly setting up a build system.

Of course these would be discouraged for production releases.


# A copy of the git code from commit we're building:
self.rpmbuild_gitcopy = os.path.join(self.rpmbuild_sourcedir,
self.tgz_dir)
Expand Down Expand Up @@ -605,7 +609,8 @@ def _setup_sources(self):
self.git_commit_id))
create_tgz(self.git_root, self.tgz_dir, self.git_commit_id,
self.relative_project_dir,
os.path.join(self.rpmbuild_sourcedir, self.tgz_filename))
os.path.join(self.rpmbuild_sourcedir, self.tgz_filename),
self.tgz_method, self.tgz_include_git)

# Extract the source so we can get at the spec file, etc.
debug("Copying git source to: %s" % self.rpmbuild_gitcopy)
Expand Down Expand Up @@ -746,7 +751,8 @@ def _setup_sources(self):
self.git_commit_id))
create_tgz(self.git_root, self.tgz_dir, self.git_commit_id,
self.relative_project_dir,
os.path.join(self.rpmbuild_sourcedir, self.tgz_filename))
os.path.join(self.rpmbuild_sourcedir, self.tgz_filename),
self.tgz_method, self.tgz_include_git)

# Extract the source so we can get at the spec file, etc.
debug("Copying git source to: %s" % self.rpmbuild_gitcopy)
Expand Down Expand Up @@ -844,7 +850,8 @@ def tgz(self):
tgz_fullpath = os.path.join(self.rpmbuild_sourcedir, tgz_filename)
print("Creating %s from git tag: %s..." % (tgz_filename, commit))
create_tgz(self.git_root, prefix, commit, relative_dir,
tgz_fullpath)
tgz_fullpath,
self.tgz_method, self.tgz_include_git)
self.ran_tgz = True
self.sources.append(tgz_fullpath)

Expand Down Expand Up @@ -1077,7 +1084,8 @@ def tgz(self):
"No Maven generated tarball found.",
"Please set up the assembly plugin in your pom.xml to generate a .tar.gz"])
full_path = os.path.join(self.rpmbuild_sourcedir, self.tgz_filename)
create_tgz(self.git_root, self.tgz_dir, self.git_commit_id, self.relative_project_dir, full_path)
create_tgz(self.git_root, self.tgz_dir, self.git_commit_id, self.relative_project_dir, full_path,
self.tgz_method, self.tgz_include_git)
print("Creating %s from git tag: %s..." % (self.tgz_filename, self.build_tag))
shutil.copy(full_path, destination_file)

Expand Down
5 changes: 3 additions & 2 deletions src/tito/builder/submodule_aware_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _setup_sources(self):
self.git_commit_id,
self.relative_project_dir,
os.path.join(self.rpmbuild_sourcedir, self.tgz_filename),
self.tgz_method, self.tgz_include_git
)

# Extract the source so we can get at the spec file, etc.
Expand Down Expand Up @@ -137,7 +138,7 @@ def _submodule_archives(self, relative_git_dir, prefix, commit, initial_tar):
)
yield (submodule_tar_file)

def create_tgz(self, git_root, prefix, commit, relative_dir, dest_tgz):
def create_tgz(self, git_root, prefix, commit, relative_dir, dest_tgz, method='git', add_git_folder=False):
"""
Create a .tar.gz from a projects source in git.
And include submodules
Expand All @@ -149,7 +150,7 @@ def create_tgz(self, git_root, prefix, commit, relative_dir, dest_tgz):
# if .gitmodules does not exist, just call the existing create_tgz function
# as there is nothing to see here.
if not os.path.exists(gitmodules_path):
return create_tgz(git_root, prefix, commit, relative_dir, dest_tgz)
return create_tgz(git_root, prefix, commit, relative_dir, dest_tgz, method, add_git_folder)

os.chdir(git_root_abspath)
timestamp = get_commit_timestamp(commit)
Expand Down
24 changes: 17 additions & 7 deletions src/tito/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,25 +852,35 @@ def get_commit_timestamp(sha1_or_tag):


def create_tgz(git_root, prefix, commit, relative_dir,
dest_tgz):
dest_tgz, method='git', add_git_folder=False):
"""
Create a .tar.gz from a projects source in git.
"""
os.chdir(os.path.abspath(git_root))
timestamp = get_commit_timestamp(commit)

# Accomodate standalone projects with specfile i root of git repo:
# Accommodate standalone projects with specfile in root of git repo:
relative_git_dir = "%s" % relative_dir
if relative_git_dir in ['/', './']:
relative_git_dir = ""
if relative_git_dir in ['/', '']:
relative_git_dir = "./"

basename = os.path.splitext(dest_tgz)[0]
initial_tar = "%s.initial" % basename

# command to generate a git-archive
git_archive_cmd = 'git archive --format=tar --prefix=%s/ %s:%s --output=%s' % (
prefix, commit, relative_git_dir, initial_tar)
run_command(git_archive_cmd)
if method == 'git':
git_archive_cmd = 'git archive --format=tar --prefix=%s/ %s:%s --output=%s' % (
prefix, commit, relative_git_dir, initial_tar)
run_command(git_archive_cmd)
if add_git_folder:
tar_append_cmd = f"tar --append -f {initial_tar} --transform 's|^{relative_git_dir}|{prefix}/|' {relative_git_dir}/.git"
run_command(tar_append_cmd)
elif method == 'tar':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some issues when using

[archiver]
method = tar

Traceback:

Traceback (most recent call last):
  File "/home/jkadlcik/git/tito/src/tito/cli.py", line 919, in <module>
    main()
  File "/home/jkadlcik/git/tito/src/tito/cli.py", line 910, in main
    CLI().main(sys.argv[1:])
  File "/home/jkadlcik/git/tito/src/tito/cli.py", line 209, in main
    return module.main(argv)
           ^^^^^^^^^^^^^^^^^
  File "/home/jkadlcik/git/tito/src/tito/cli.py", line 392, in main
    return builder.run(self.options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jkadlcik/git/tito/src/tito/builder/main.py", line 160, in run
    self.tgz()
  File "/home/jkadlcik/git/tito/src/tito/builder/main.py", line 577, in tgz
    self._setup_sources()
  File "/home/jkadlcik/git/tito/src/tito/builder/main.py", line 610, in _setup_sources
    create_tgz(self.git_root, self.tgz_dir, self.git_commit_id,
  File "/home/jkadlcik/git/tito/src/tito/common.py", line 895, in create_tgz
    tarfixer.fix()
  File "/home/jkadlcik/git/tito/src/tito/tar.py", line 325, in fix
    self.process_chunk(chunk)
  File "/home/jkadlcik/git/tito/src/tito/tar.py", line 292, in process_chunk
    chunk_props[member] = int(chunk_props[member], 8)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 8: ''

Reproducible when you run tito build --tgz within this project.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's where I wanted some help because I don't understand what the tarfixer does and why it fails like that.

# Assuming no folder paths contain '|' so we don't need to create escaped versions
git_archive_cmd = f"tar --create -f {initial_tar} --transform 's|^{relative_git_dir}|{prefix}/|' {relative_git_dir}"
run_command(git_archive_cmd)
else:
raise Exception(f"Unknown tar create method passed: {method}")

# Run git-archive separately if --debug was specified.
# This allows us to detect failure early.
Expand Down