autobuild 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b7ade4cfb6600c6240d0e6cbb23ed19340e7c3a43b7811aab49236e1d81b1f0
4
- data.tar.gz: 72fade1f3c6de16fd4988c9d132452aed5a7684f4e1978872ea3e18933c8c0ac
3
+ metadata.gz: 43869aed86ff761f4f091a8c5dbd4d27cdb481cd2b60bf4843bd259366d2a88b
4
+ data.tar.gz: c62531880b13b4401323193c8bbbc1d095ae1f0201aecf16646c5f316f7aff03
5
5
  SHA512:
6
- metadata.gz: 3b63871e342d7a5b7bdf7bb0ab28c1aa6bb4e808f95a08ada2c9d56ba74c2ce95207883348b8e5727bfac65932d6c8f5cd2473f62bf2445ed6b4110d95331a17
7
- data.tar.gz: 1a53537790164887e430742c5314e1f22685f2b50102874b33556f2153fa03e4d69f68cf95d89602c799bda420c878985c2f5600122077b84917221f8408ac89
6
+ metadata.gz: 47a3d57e94becd1e6e96ccf36902e5cb908d56d3faf0ee0f18904c041caae1940eaa959b51ae641c9de826c6cf211a42953a81268a61d4bf60efce9173bf373f
7
+ data.tar.gz: e6edd90897e22b8dd0e89e490027ebb2c2632bc3c201355a787bf83413b8958a5ee97a3aab6da0e6dbe96fde093d453032244fcca7145af99f578ad3c425874d
@@ -1,9 +1,13 @@
1
- # Disable git-lfs at checkout time, we run install --local and pull later
1
+ # Disable git-lfs at checkout time, we run install --local and pull later
2
2
  Autobuild::Git.default_config['filter.lfs.smudge'] = 'git-lfs smudge --skip -- %f'
3
3
  Autobuild::Git.default_config['filter.lfs.required'] = 'false'
4
4
 
5
5
  module Autobuild
6
6
  Git.add_post_hook(always: true) do |importer, package|
7
+ if importer.options[:lfs] != false && importer.uses_lfs?(package) && !Git.lfs_installed?
8
+ Autobuild.warn "#{package.name} uses git LFS but it is not installed, files may be missing from checkout"
9
+ end
10
+
7
11
  lfs_dir = File.join(package.srcdir, '.git', 'lfs')
8
12
  if File.directory?(lfs_dir)
9
13
  importer.run_git(package, 'lfs', 'install', '--force', '--local', '--skip-smudge')
@@ -2,6 +2,7 @@
2
2
  require 'autobuild/subcommand'
3
3
  require 'autobuild/importer'
4
4
  require 'utilrb/kernel/options'
5
+ require 'open3'
5
6
 
6
7
  module Autobuild
7
8
  class Git < Importer
@@ -54,7 +55,7 @@ def self.version
54
55
  # Helper method to compare two (partial) versions represented as array
55
56
  # of integers
56
57
  #
57
- # @return [Integer] -1 if actual is greater than required,
58
+ # @return [Integer] -1 if actual is greater than required,
58
59
  # 0 if equal, and 1 if actual is smaller than required
59
60
  def self.compare_versions(actual, required)
60
61
  if actual.size > required.size
@@ -82,7 +83,7 @@ def self.at_least_version(*version)
82
83
  # Creates an importer which tracks a repository and branch.
83
84
  #
84
85
  # This importer uses the 'git' tool to perform the import. It defaults
85
- # to 'git' and can be configured by doing
86
+ # to 'git' and can be configured by doing
86
87
  #
87
88
  # Autobuild.programs['git'] = 'my_git_tool'
88
89
  #
@@ -128,6 +129,8 @@ def initialize(repository, branch = nil, options = {})
128
129
  gitopts, common = Kernel.filter_options options,
129
130
  push_to: nil,
130
131
  branch: nil,
132
+ local_branch: nil,
133
+ remote_branch: nil,
131
134
  tag: nil,
132
135
  commit: nil,
133
136
  repository_id: nil,
@@ -370,7 +373,7 @@ def delta_between_tags(package, from_tag, to_tag)
370
373
  # @param [Package] package
371
374
  # @option options [Boolean] only_local (false) whether the tags should
372
375
  # be fetch from the remote first, or if one should only list tags that
373
- # are already known locally
376
+ # are already known locally
374
377
  # @return [Hash<String,String>] a mapping from a tag name to its commit
375
378
  # ID
376
379
  def tags(package, options = Hash.new)
@@ -443,7 +446,7 @@ def setup_remote(package, remote_name, repository, push_to = repository)
443
446
  run_git_bare(package, 'config', '--replace-all', "remote.#{remote_name}.fetch", "+refs/heads/*:refs/remotes/#{remote_name}/*")
444
447
 
445
448
  if remote_branch && local_branch
446
- run_git_bare(package, 'config', '--replace-all', "remote.#{remote_name}.push", "refs/heads/#{local_branch}:refs/heads/#{remote_branch}")
449
+ run_git_bare(package, 'config', '--replace-all', "remote.#{remote_name}.push", "refs/heads/#{local_branch}:#{remote_branch_to_ref(remote_branch)}")
447
450
  else
448
451
  run_git_bare(package, 'config', '--replace-all', "remote.#{remote_name}.push", "refs/heads/*:refs/heads/*")
449
452
  end
@@ -471,7 +474,7 @@ def update_remotes_configuration(package)
471
474
 
472
475
  if local_branch
473
476
  run_git_bare(package, 'config', '--replace-all', "branch.#{local_branch}.remote", remote_name)
474
- run_git_bare(package, 'config', '--replace-all', "branch.#{local_branch}.merge", "refs/heads/#{local_branch}")
477
+ run_git_bare(package, 'config', '--replace-all', "branch.#{local_branch}.merge", remote_branch_to_ref(local_branch))
475
478
  end
476
479
  end
477
480
 
@@ -578,12 +581,16 @@ def current_remote_commit(package, options = Hash.new)
578
581
  end
579
582
  only_local = options.delete(:only_local)
580
583
 
581
-
582
584
  if only_local
583
585
  refspec = options[:refspec] ||
584
586
  ("refs/tags/#{tag}" if tag) ||
585
- "refs/remotes/#{remote_name}/#{remote_branch}"
586
- refspec = Array(refspec).first
587
+ ("refs/remotes/#{remote_name}/#{remote_branch}" \
588
+ unless remote_branch.start_with?("refs/"))
589
+ unless (refspec = Array(refspec).first)
590
+ raise ArgumentError, "cannot use only_local with no tag,"\
591
+ " and an absolute remote ref"
592
+ end
593
+
587
594
  begin
588
595
  run_git_bare(package, 'show-ref', '-s', refspec).first.strip
589
596
  rescue SubcommandFailed
@@ -592,7 +599,7 @@ def current_remote_commit(package, options = Hash.new)
592
599
  else
593
600
  refspec = options[:refspec] ||
594
601
  ("refs/tags/#{tag}" if tag) ||
595
- "refs/heads/#{remote_branch}"
602
+ remote_branch_to_ref(remote_branch)
596
603
  begin fetch_remote(package, refspec: refspec)
597
604
  rescue Exception => e
598
605
  return fallback(e, package, :status, package, only_local)
@@ -635,7 +642,7 @@ def has_commit?(package, commit_id)
635
642
  end
636
643
 
637
644
  def has_branch?(package, branch_name)
638
- run_git_bare(package, 'show-ref', '-q', '--verify', "refs/heads/#{branch_name}")
645
+ run_git_bare(package, 'show-ref', '-q', '--verify', remote_branch_to_ref(branch_name))
639
646
  true
640
647
  rescue SubcommandFailed => e
641
648
  if e.status == 1
@@ -652,6 +659,14 @@ def detached_head?(package)
652
659
  current_branch(package).nil?
653
660
  end
654
661
 
662
+ private def remote_branch_to_ref(branch)
663
+ if branch.start_with?("refs/")
664
+ branch
665
+ else
666
+ "refs/heads/#{branch}"
667
+ end
668
+ end
669
+
655
670
  # Returns the branch HEAD is pointing to
656
671
  #
657
672
  # @return [String,nil] the full ref HEAD is pointing to (i.e.
@@ -733,7 +748,7 @@ def rev_parse(package, name, object_type = "commit")
733
748
  raise PackageException.new(package, 'import'), "failed to resolve #{name}. Are you sure this commit, branch or tag exists ?"
734
749
  end
735
750
 
736
- # Returns the file's conents at a certain commit
751
+ # Returns the file's conents at a certain commit
737
752
  #
738
753
  # @param [Package] package
739
754
  # @param [String] commit
@@ -758,7 +773,7 @@ def commit_present_in?(package, rev, reference)
758
773
  begin
759
774
  merge_base = run_git_bare(package, 'merge-base', commit, reference).first
760
775
  merge_base == commit
761
-
776
+
762
777
  rescue Exception
763
778
  raise PackageException.new(package, 'import'), "failed to find the merge-base between #{rev} and #{reference}. Are you sure these commits exist ?"
764
779
  end
@@ -780,7 +795,7 @@ def describe_commit_on_remote(package, rev = 'HEAD', options = Hash.new)
780
795
  commit_id = rev_parse(package, rev)
781
796
 
782
797
  remote_refs = Hash[*each_remote_ref(package).to_a.flatten]
783
- remote_branch_ref = "refs/heads/#{remote_branch}"
798
+ remote_branch_ref = remote_branch_to_ref(remote_branch)
784
799
  remote_branch_id = remote_refs.delete(remote_branch_ref)
785
800
  begin
786
801
  if commit_present_in?(package, commit_id, remote_branch_id)
@@ -932,7 +947,14 @@ def reset_head_to_commit(package, target_commit, fetch_commit, options = Hash.ne
932
947
  # repository. We'll refuse resetting if there are uncommitted
933
948
  # changes
934
949
  if !commit_present_in?(package, current_head, fetch_commit)
935
- raise ImporterCannotReset.new(package, 'import'), "branch #{local_branch} of #{package.name} contains commits that do not seem to be present on the branch #{remote_branch} of the remote repository. I can't go on as it could make you loose some stuff. Update the remote branch in your overrides, push your changes or reset to the remote commit manually before trying again"
950
+ raise ImporterCannotReset.new(package, 'import'),
951
+ "branch #{local_branch} of #{package.name} contains"\
952
+ " commits that do not seem to be present on the branch"\
953
+ " #{remote_branch} of the remote repository. I can't"\
954
+ " go on as it could make you lose some stuff. Update"\
955
+ " the remote branch in your overrides, push your"\
956
+ " changes or reset to the remote commit manually"\
957
+ " before trying again"
936
958
  end
937
959
  end
938
960
 
@@ -951,7 +973,7 @@ def reset_head_to_commit(package, target_commit, fetch_commit, options = Hash.ne
951
973
  rescue ::Exception
952
974
  run_git(package, 'symbolic-ref', "HEAD", target_commit)
953
975
  run_git(package, 'update-ref', "refs/heads/#{local_branch}", current_head)
954
- run_git(package, 'checkout', local_branch)
976
+ run_git(package, 'checkout', "refs/heads/#{local_branch}")
955
977
  raise
956
978
  end
957
979
  true
@@ -968,7 +990,7 @@ def determine_target_state(package, only_local: false)
968
990
  fetch_commit = current_remote_commit(
969
991
  package,
970
992
  only_local: only_local,
971
- refspec: [remote_branch, tag])
993
+ refspec: [remote_branch_to_ref(remote_branch), tag])
972
994
  end
973
995
  target_commit = pinned_state = rev_parse(package, pinned_state)
974
996
  else
@@ -985,7 +1007,7 @@ def update(package, options = Hash.new)
985
1007
  validate_importdir(package)
986
1008
  only_local = options.fetch(:only_local, false)
987
1009
  reset = options.fetch(:reset, false)
988
-
1010
+
989
1011
  # This is really really a hack to workaround how broken the
990
1012
  # importdir thing is
991
1013
  if package.importdir == package.srcdir
@@ -1005,7 +1027,8 @@ def update(package, options = Hash.new)
1005
1027
 
1006
1028
  unless pin_is_uptodate
1007
1029
  fetch_commit ||= current_remote_commit(
1008
- package, only_local: only_local, refspec: [remote_branch, tag])
1030
+ package, only_local: only_local,
1031
+ refspec: [remote_branch_to_ref(remote_branch), tag])
1009
1032
  did_update =
1010
1033
  if reset
1011
1034
  reset_head_to_commit(package, target_commit, fetch_commit,
@@ -1073,6 +1096,22 @@ def each_alternate_path(package)
1073
1096
  nil
1074
1097
  end
1075
1098
 
1099
+ def uses_lfs?(package)
1100
+ git_files = run_git(package, 'ls-files').join("\n")
1101
+ git_attrs = run_git(
1102
+ package, 'check-attr', '--all', '--stdin',
1103
+ input_streams: [StringIO.new(git_files)]
1104
+ ).join("\n")
1105
+
1106
+ /(.*): filter: lfs/.match(git_attrs)
1107
+ end
1108
+
1109
+ def self.lfs_installed?
1110
+ return @lfs_installed unless @lfs_installed.nil?
1111
+ _, _, status = Open3.capture3('git lfs env')
1112
+ @lfs_installed = status.success?
1113
+ end
1114
+
1076
1115
  def checkout(package, options = Hash.new)
1077
1116
  base_dir = File.expand_path('..', package.importdir)
1078
1117
  if !File.directory?(base_dir)
@@ -1084,6 +1123,10 @@ def checkout(package, options = Hash.new)
1084
1123
  clone_options << '--recurse-submodules'
1085
1124
  end
1086
1125
  if single_branch?
1126
+ if remote_branch.start_with?("refs/")
1127
+ raise ArgumentError, "you cannot provide a full ref for"\
1128
+ " the remote branch while cloning a single branch"
1129
+ end
1087
1130
  clone_options << "--branch=#{remote_branch}" << "--single-branch"
1088
1131
  end
1089
1132
  each_alternate_path(package) do |path|
@@ -1096,7 +1139,7 @@ def checkout(package, options = Hash.new)
1096
1139
  Autobuild.tool('git'), 'clone', '-o', remote_name, *clone_options, repository, package.importdir, retry: true)
1097
1140
 
1098
1141
  update_remotes_configuration(package)
1099
- update(package, only_local: true, reset: true)
1142
+ update(package, only_local: !remote_branch.start_with?("refs/"), reset: true)
1100
1143
  if with_submodules?
1101
1144
  run_git(package, "submodule", "update", '--init')
1102
1145
  end
@@ -1106,9 +1149,14 @@ def checkout(package, options = Hash.new)
1106
1149
  def relocate(repository, options = Hash.new)
1107
1150
  options = Hash[options.map { |k, v| [k.to_sym, v] }]
1108
1151
 
1109
- @push_to = options[:push_to] || @push_to
1110
1152
  local_branch = options[:local_branch] || options[:branch] || self.local_branch || 'master'
1111
1153
  remote_branch = options[:remote_branch] || options[:branch] || self.remote_branch || 'master'
1154
+ if local_branch.start_with?("refs/")
1155
+ raise ArgumentError, "you cannot provide a full ref for"\
1156
+ " the local branch, only for the remote branch"
1157
+ end
1158
+
1159
+ @push_to = options[:push_to] || @push_to
1112
1160
  @branch = @local_branch = @remote_branch = nil
1113
1161
  if local_branch == remote_branch
1114
1162
  @branch = local_branch
@@ -132,6 +132,9 @@ def initialize(spec = Hash.new)
132
132
  @in_dir_stack = Array.new
133
133
  @utilities = Hash.new
134
134
  @env = Array.new
135
+ @imported = false
136
+ @prepared = false
137
+ @built = false
135
138
 
136
139
  if Hash === spec
137
140
  name, depends = spec.to_a.first
@@ -153,18 +156,20 @@ def initialize(spec = Hash.new)
153
156
  # Define the default tasks
154
157
  task "#{name}-import" do
155
158
  isolate_errors { import }
159
+ @imported = true
156
160
  end
157
161
  task :import => "#{name}-import"
158
162
 
159
163
  # Define the prepare task
160
164
  task "#{name}-prepare" => "#{name}-import" do
161
165
  isolate_errors { prepare }
166
+ @prepared = true
162
167
  end
163
168
  task :prepare => "#{name}-prepare"
164
169
 
165
170
  task "#{name}-build"
166
- task :build => "#{name}-build"
167
171
 
172
+ task :build => "#{name}-build"
168
173
  task(name) do
169
174
  Rake::Task["#{name}-import"].invoke
170
175
  Rake::Task["#{name}-prepare"].invoke
@@ -185,6 +190,30 @@ def checked_out?
185
190
  File.directory?(srcdir)
186
191
  end
187
192
 
193
+ def prepare_invoked?
194
+ task("#{name}-prepare").already_invoked?
195
+ end
196
+
197
+ def prepared?
198
+ @prepared
199
+ end
200
+
201
+ def import_invoked?
202
+ task("#{name}-import").already_invoked?
203
+ end
204
+
205
+ def imported?
206
+ @imported
207
+ end
208
+
209
+ def build_invoked?
210
+ task("#{name}-build").already_invoked?
211
+ end
212
+
213
+ def built?
214
+ @built
215
+ end
216
+
188
217
  def to_s
189
218
  "#<#{self.class} name=#{name}>"
190
219
  end
@@ -422,6 +451,7 @@ def import(options = Hash.new)
422
451
 
423
452
  if @importer
424
453
  result = @importer.import(self, options)
454
+ @imported = true
425
455
  elsif update?
426
456
  message "%s: no importer defined, doing nothing"
427
457
  end
@@ -443,6 +473,8 @@ def prepare
443
473
  isolate_errors { install }
444
474
  end
445
475
  task "#{name}-build" => installstamp
476
+
477
+ @prepared = true
446
478
  end
447
479
 
448
480
  def process_formatting_string(msg, *prefix_style)
@@ -522,6 +554,8 @@ def install
522
554
  progress_done
523
555
 
524
556
  Autobuild.touch_stamp(installstamp)
557
+
558
+ @built = true
525
559
  end
526
560
 
527
561
  def run(*args, &block)
@@ -348,12 +348,17 @@ def self.run(target, phase, *command)
348
348
  end
349
349
  end
350
350
 
351
+ readbuffer = StringIO.new
352
+
351
353
  # Feed the input
352
354
  if !input_streams.empty?
353
355
  pread.close
354
356
  begin
355
357
  input_streams.each do |instream|
356
- instream.each_line { |line| pwrite.write(line) }
358
+ instream.each_line do |line|
359
+ readbuffer.write(outread.readpartial(128)) while IO.select([outread], nil, nil, 0)
360
+ pwrite.write(line)
361
+ end
357
362
  end
358
363
  rescue Errno::ENOENT => e
359
364
  raise Failed.new(nil, false),
@@ -387,6 +392,14 @@ def self.run(target, phase, *command)
387
392
  # If the caller asked for process output, provide it to him
388
393
  # line-by-line.
389
394
  outwrite.close
395
+
396
+ if !input_streams.empty?
397
+ readbuffer.write(outread.read)
398
+ readbuffer.seek(0)
399
+ outread.close
400
+ outread = readbuffer
401
+ end
402
+
390
403
  outread.each_line do |line|
391
404
  line.force_encoding(options[:encoding])
392
405
  line = line.chomp
@@ -1,3 +1,3 @@
1
1
  module Autobuild
2
- VERSION = "1.16.0" unless defined? Autobuild::VERSION
2
+ VERSION = "1.17.0" unless defined? Autobuild::VERSION
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autobuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Joyeux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-22 00:00:00.000000000 Z
11
+ date: 2019-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake