Module: QCloudHive

Defined in:
lib/qcloudhive.rb,
lib/qcloudhive/repo.rb,
lib/qcloudhive/config.rb,
lib/qcloudhive/gitlab.rb,
lib/qcloudhive/module.rb,
lib/qcloudhive/feature.rb,
lib/qcloudhive/product.rb,
lib/qcloudhive/project.rb,
lib/qcloudhive/version.rb,
lib/qcloudhive/manifest.rb,
lib/qcloudhive/framework.rb,
lib/qcloudhive/xcodeproj.rb,
lib/qcloudhive/git_helper.rb,
lib/qcloudhive/pod_helper.rb,
lib/qcloudhive/spec_helper.rb

Defined Under Namespace

Modules: CodeOA, Config, HiveModule, HivePod, Project Classes: BuildShell, GITURLDecoder, HiveSpec, Manifest, ManifestDefault, ManifestProject, ManifestRemote, ProjectFeature, QCloudHiveFeature, Repo, XCodeProject

Constant Summary collapse

CODE_OA_GROUDP =
"CodeOA"
CODE_OA_CONFIG_PRIVATE_TOKEN =
"private_token"
CODE_OA_TEAM_NAME =
"team"
REPO_ROOT_NAME =
".repo"
VERSION =
"0.1.0"
HIVE_MODULES_FILE_NAME =
".hivemodules"
@@xcodeprojectvar =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.addCMD(origin, cmd) ⇒ Object



66
67
68
# File 'lib/qcloudhive/project.rb', line 66

def QCloudHive.addCMD(origin , cmd)
  return origin + "\n" + cmd + "\n"
end

.beginShell(path, shell) ⇒ Object



35
36
37
# File 'lib/qcloudhive/framework.rb', line 35

def QCloudHive.beginShell(path, shell)
  Rake::sh "cd #{path}\n #{shell}"
end

.BuildFramework(cmd, opts) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/qcloudhive/framework.rb', line 70

def QCloudHive.BuildFramework(cmd, opts)
  name = opts[:i_name]
  if name == nil
    L.error "ERROR! no project name, please input one"
    L.error cmd.help
    exit(1)
  end
  buildSimArch = opts[:i_build_sim]
  if buildSimArch.nil?
    buildSimArch = true
  end
  L.info "build sim #{buildSimArch}"
  unlinked = opts[:i_unlinked_frameworks]
  if unlinked.nil?
    unlinked = []
  end
  L.info "un linked frameworks #{unlinked}"
  output = Dir.pwd
  rootShellPath = Config.scriptesDirectory
  Rake::sh "#{rootShellPath}HiveFramework #{name}"

  projectDir = "#{output}/#{name}"
  project = Xcodeproj::Project.open("#{output}/#{name}/#{name}.xcodeproj")
  project.targets.each do |target|
    if target.name == name
      target.build_configurations.each do |config|
        config.build_settings['ENABLE_BITCODE'] = 'NO'
        puts "set bitcode NO"
      end
    end
    puts "target name #{name}"
  end

  project.save

  Rake::sh "cd #{name} \n" +
  "pod update\n"
  # delete unlinked frameworks
  project = Xcodeproj::Project.open("#{output}/#{name}/#{name}.xcodeproj")
  xcconfigFiles = project.files.select{ |f|
    L.info "file #{f.path}"
    f.path.end_with?(".xcconfig")
  }
  L.info("config files #{xcconfigFiles}")
  hiveXcodeProject = QCloudHive.xcodeprojectByPath(Pathname.new("#{output}/#{name}").realpath.to_s)
  xcconfigFiles.each { |f|
    path = Pathname.new(projectDir).join(f.path)
    config = Xcodeproj::Config.new(path)
    linked = config.other_linker_flags[:libraries].to_a
    L.info "#{config.other_linker_flags}"
    frameworkLinked = config.other_linker_flags[:frameworks].to_a
    L.info "linked #{linked}"
    # unlinked.each { |e|
    #   linked.delete e
    #   willUnlink = UnlinkedModule(e, hiveXcodeProject)
    #   L.info "will unlink #{willUnlink}"
    #   linked -= willUnlink
    #   frameworkLinked -= willUnlink
    # }
    linked = linked.compact
    frameworkLinked = frameworkLinked.compact
    config.other_linker_flags[:libraries] = linked.to_set
    config.other_linker_flags[:frameworks] = frameworkLinked.to_set
    L.info "final linked #{linked}"
    config.save_as(path)
  }
  #

  productsDir = "Products"
  productsDir = "#{projectDir}/#{productsDir}"
  if not Pathname.new(productsDir).exist?
    Pathname.new(productsDir).mkdir
  end



  buildCMD = BuildShell.new()
  buildCMD.config = "Release"
  buildCMD.productsDir = productsDir
  buildCMD.other_cflags = "\"-fembed-bitcode\""
  buildCMD.name = name
  buildCMD.sdk = "iphoneos"
  beginShell(name,buildCMD.to_cmd)


  deviceFramework="#{productsDir}/Build/Products/#{buildCMD.config}-iphoneos/#{name}.framework"

  if buildSimArch == true
    buildCMD = BuildShell.new()
    buildCMD.config = "Release"
    buildCMD.productsDir = productsDir
    buildCMD.other_cflags = "\"-fembed-bitcode\""
    buildCMD.name = name
    buildCMD.sdk = "iphonesimulator"

    beginShell(name,buildCMD.to_cmd)
    simFramework="#{productsDir}/Build/Products/#{buildCMD.config}-iphonesimulator/#{name}.framework"
    Rake::sh " lipo -create #{deviceFramework}/#{name} #{simFramework}/#{name} -output #{deviceFramework}/#{name}"

  end

  puts "Copy frameworks"
  outputFramework = "#{name}.framework"
  outputFrameworkPath = Pathname.new(outputFramework)
  if outputFrameworkPath.exist?
    FileUtils.rm_rf(outputFrameworkPath.to_path)
  end
  Rake::sh "cp -rvf #{deviceFramework} #{outputFramework}"
  Rake::sh "cp #{name}/.hivemodules #{outputFramework}/"
  headersPath = Pathname.new("#{outputFramework}/Headers/")
  if not headersPath.exist?
    headersPath.mkdir
  end
  if Pathname("#{name}/Pods/Headers/Public").exist?
    shell = "find #{name}/Pods/Headers/Public -name \"*.h\" -exec cp {}  #{outputFramework}/Headers/  \\;"
    Rake::sh shell
  end
  willRmBuild = opts[:i_rm_build]
  if willRmBuild != false
    FileUtils.rm_rf("#{name}")
  end
end

.checkDependencies(cmd, opts) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/qcloudhive/feature.rb', line 61

def QCloudHive.checkDependencies(cmd, opts)
  Config.manifest.projects.each { |p|
    L.info("#{p.path} exist #{p.exsitLocal?}")
    if  p.exsitLocal? and (not p.podspec.nil?)
      L.info("#{p.path}")
      version = Versionomy.parse(p.podspec.version.version)
      versionNumber = version.major*1000*1000 + version.minor*1000 + version.tiny
      str = "
#ifndef #{p.moduleName}ModuleVersion_h
#define #{p.moduleName}ModuleVersion_h
#define #{p.moduleName}ModuleVersionNumber #{versionNumber}
FOUNDATION_EXTERN NSString * const #{p.moduleName}ModuleVersion;
FOUNDATION_EXTERN NSString * const #{p.moduleName}ModuleName;
#endif
      "
      file = Pathname(p.localPath).join("Pod/Classes/#{p.moduleName}Version.h")
      File.open(file, "w") { |f|
        f.write str
      }

      file = Pathname(p.localPath).join("Pod/Classes/#{p.moduleName}Version.m")
      File.open(file, "w") { |f|
        f.write "
#import \"#{p.moduleName}Version.h\"
NSString * const #{p.moduleName}ModuleVersion = @\"#{p.podspec.version.version}\";
NSString * const #{p.moduleName}ModuleName = @\"#{p.moduleName}\";
        "
      }
    end
  }
end

.commitFeature(cmd, opts) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/qcloudhive/feature.rb', line 45

def QCloudHive.commitFeature(cmd, opts)
  message = GetOptValue(cmd, opts, :i_message)
  Config.manifest.projects.each { |p|
    if p.exsitLocal?
      git = p.gitRepo
      if (not git.nil?) and (not git.clean?)
        L.info("#{git.dir} commit clean #{git.clean?}")
        git.add(:all=>true)
        git.commit_all(message)
      else
        L.info("#{git.dir} is clean")
      end
    end
  }
end

.CreateAPP(cmd, opts) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/qcloudhive/product.rb', line 5

def QCloudHive.CreateAPP(cmd, opts)
  name = opts[:c_name]
  if name == nil
    puts "ERROR! no name, please input one"
    puts cmd.help
    exit(1)
  end
  Rake::sh "#{Config.scriptesDirectory}HiveApp.sh #{name}"
  Rake::sh "cd #{name} \n" +
  "pod install \n" +
  "open #{name}.xcworkspace"


  url = opts[:c_url]
  if url == nil
    puts "您没有设置URL,将不会进行Git 远端仓库配置"
  else
    Rake::sh "cd #{name} \n" +
    '''
    git init
    git add .
    git commit -m "init"
    ''' + "git remote add origin #{url} \n " +
    " git push -u origin master \n"
  end
end

.FindRepoRoot(path) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/qcloudhive/config.rb', line 151

def QCloudHive.FindRepoRoot(path)
  pwd = Pathname(path)
  if pwd.to_path == "/"
    return nil
  end
  if pwd.to_path == '.repo'
    return pwd
  end
  aimPath = nil
  pwd.entries.each { |x|
    if x.to_path == REPO_ROOT_NAME
      aimPath = pwd.join(x)
      break
    end
  }
  if aimPath != nil
    return aimPath
  else
    parentDir = pwd.dirname
    if parentDir.to_path == REPO_ROOT_NAME
      return nil
    end
    return FindRepoRoot(parentDir)
  end
end

.findXcodeProject(path) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/qcloudhive/xcodeproj.rb', line 103

def QCloudHive.findXcodeProject(path)
  dirPath = Pathname.new(path)
  if not dirPath.directory?
    return []
  end
  projects = dirPath.each_child.select{|f|
    f.extname == ".xcodeproj"
  }
  if projects.count != 0
    return [dirPath.to_path]
  else
    subProjects = []
    dirPath.each_child { |file|
      if file.basename.to_path == ".git"
        next
      end
      if file.basename.to_path == ".repo"
        next
      end
      subDir = dirPath.join(file)
      if subDir.directory?
         subProjects+=findXcodeProject(subDir)
      end
    }
    return subProjects
  end
end

.listFeature(cmd, opts) ⇒ Object



14
15
# File 'lib/qcloudhive/feature.rb', line 14

def QCloudHive.listFeature(cmd, opts)
end

.pushFeature(cmd, opts) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/qcloudhive/feature.rb', line 17

def QCloudHive.pushFeature(cmd, opts)
  Config.manifest.projects.each { |p|
    if not p.gitRepo.clean?
      Error("模块:#{p.path} 在本地有未提交的修改,请检查并提交后再进行PUSH操作")
    end
  }

  Config.manifest.projects.each { |p|
    currentBranch = p.gitRepo.branches[p.gitRepo.current_branch]
    currentFreature = ProjectFeature.new(p, currentBranch)
    if currentFreature.remoteBranch.nil?
      puts "#{p.path} 提交 #{currentBranch.name}"
      L.info("#{p.gitRepo} git repo xxxxxx")
      p.gitRepo.push('origin', currentBranch.name, {"--set-upstream"=>currentBranch.name})
    else
      compareRet = currentFreature.compareRemote
      if compareRet == 1
        puts "#{p.path} 提交 #{currentBranch.name}"
        L.info("#{p.gitRepo} git repo")
        p.gitRepo.push('origin', currentBranch.name, {"--set-upstream"=>currentBranch.name})
      elsif compareRet == -1
        puts "#{p.path} 没有进行push操作 远端有新的修改,请及时Pull⬇️⬇️⬇️".blue
      else
      end
    end
  }
end

.RemapProduct(cmd, opts) ⇒ Object



14
15
16
17
# File 'lib/qcloudhive/repo.rb', line 14

def QCloudHive.RemapProduct(cmd, opts)
  pods = HivePod.podspecs
  Repo.addChildSpec("xxxx",pods[3])
end

.startFeature(cmd, opts) ⇒ Object



11
12
# File 'lib/qcloudhive/feature.rb', line 11

def QCloudHive.startFeature(cmd, opts)
end

.syncManifestObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/qcloudhive/manifest.rb', line 330

def QCloudHive.syncManifest
  repoRootPath = Config.repoRoot
  manifestsPath=repoRootPath+"./manifests/"
  cmd = ""
  cmd = addCMD(cmd,"cd #{manifestsPath}")
  cmd = addCMD(cmd, "git add .")
  cmd = addCMD(cmd, "git commit -m \"Project Edited\"")
  cmd = addCMD(cmd, "git checkout default")
  cmd = addCMD(cmd, "git push origin HEAD:default")
  cmd = addCMD(cmd, "git checkout master")
  cmd = addCMD(cmd, "git merge default")
  cmd = addCMD(cmd, "git push origin HEAD:master")
  cmd = addCMD(cmd, "git checkout default")
  L.debug cmd
  Rake::sh cmd
end

.UnlinkedModule(name, hiveXcodeProject) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/qcloudhive/framework.rb', line 39

def QCloudHive.UnlinkedModule(name, hiveXcodeProject)
  podspec = hiveXcodeProject.hiveSpecModules.select { |s|
    s.name == name
  }.first
  if podspec.nil?
    Error "您不想链接的模块#{name}, 不存在本地"
  end
  unlinked = []
  L.info "$$$$$$$$#{podspec.path}"
  if not podspec.path.nil?
    pod = Pod::Specification.from_file(podspec.path)
    vendored_libraries = pod.attributes_hash["vendored_libraries"]
    vendoredFrameworks = pod.attributes_hash["vendored_frameworks"]
    if not vendoredFrameworks.nil?
      vendoredFrameworks.each { |e|
        unlinked << Pathname.new(e).fileName
      }
    end
    if not vendored_libraries.nil?
      vendored_libraries.each { |e|
        name = Pathname.new(e).fileName
        if name.start_with?("lib")
          name = name[3..-1]
        end
        unlinked << name
      }
    end
    L.info "Unlinked #{unlinked}"
    return unlinked
  end
end

.updateAllProductsObject



157
158
159
160
161
162
# File 'lib/qcloudhive/xcodeproj.rb', line 157

def QCloudHive.updateAllProducts
  QCloudHive.xcodeprojects.each { |hive|
    L.debug "codeproject #{hive.path}"
    Rake::sh "cd #{Pathname(hive.path).to_path};pod update"
  }
end

.UpdateProducts(cmd, opts) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/qcloudhive/xcodeproj.rb', line 148

def QCloudHive.UpdateProducts(cmd, opts)
  name = opts[:i_name]
  Config.dumpShareConfig
  if name.nil?
    updateAllProducts
  end

end

.xcodeprojectByPath(path) ⇒ Object



144
145
146
# File 'lib/qcloudhive/xcodeproj.rb', line 144

def QCloudHive.xcodeprojectByPath(path)
  QCloudHive.xcodeprojects.select{|p| p.path == path}.first
end

.xcodeprojectsObject



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/qcloudhive/xcodeproj.rb', line 130

def QCloudHive.xcodeprojects
  if @@xcodeprojectvar.nil?
    root = Config.projectRootDirectory
    L.info("find xcode projects")
    projects = findXcodeProject(root)
    xcodePojects = []
    projects.each { |xcp|
        xcodePojects << XCodeProject.new(xcp)
    }
    @@xcodeprojectvar = xcodePojects
  end
  return @@xcodeprojectvar
end

Instance Method Details

#InitEmptyProject(cmd, opts) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/qcloudhive/project.rb', line 71

def InitEmptyProject(cmd, opts)
  name = opts[:i_name]
  url = opts[:i_url]
  if name == nil
    puts "ERROR! no project name, please input one"
    puts cmd.help
    exit(1)
  end
  if url == nil
    puts "ERROR! no git url"
    puts cmd.help
    exit(1)
  end
  if File.exist?(name)
    puts "ERROR! the project exist, can not cover it. please check"
    exit(1)
  end

  emptyProjectPath = CURRENT_PATH+name+"/"
  templatePath = CDM_RES_PATH + "manifests/"
  DZCopyFile(templatePath, emptyProjectPath, true)
  Rake::sh "cd #{emptyProjectPath} \n" +'''
  git init .
  git add .
  git commit -m "init project"
  ''' + "git remote add origin #{url} \n " +
  " git push -u origin master \n" +
  "cd .. \n" +
  "rm -rf #{name}\n" +
  "mkdir #{name}\n" +
  "cd #{name}\n" +
  '''
  echo "产品初始化完成,将使用下述命令从您常用的源码目录,checkout该项目:"
  ''' + "repo init -u #{url}"

end