This is an archive of the discontinued LLVM Phabricator instance.

[clang][cmake] Add options to pass in vcs repo and revision info
ClosedPublic

Authored by zhuhan0 on Apr 13 2023, 11:32 AM.

Details

Summary

Clang may be built in an environment where Git is not available. In our case,
Clang is part of a larger monorepo which is not Git-based, and
GenerateVersionFromVCS was not able to get source info.

Provide options to pass in repo and revision info from cmake.

cmake \
  -DCLANG_VC_REPOSITORY=abc://repo.url.com \
  -DCLANG_VC_REVISION=abcd1234 \
  ...

This would allow us to prepare the source info beforehand and pass it to the
clang binary.

Diff Detail

Event Timeline

zhuhan0 created this revision.Apr 13 2023, 11:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2023, 11:32 AM
zhuhan0 requested review of this revision.Apr 13 2023, 11:32 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 13 2023, 11:32 AM
drodriguez requested changes to this revision.Apr 14 2023, 1:57 PM
drodriguez added inline comments.
clang/lib/Basic/CMakeLists.txt
16–21

I imagine you do not need it, but maybe LLVM should have the same changes? There's a for loop in GenerateVersionFromVCS.cmake that is already going to try to look into LLVM_VC_REPOSITORY/REVISION.

llvm/cmake/modules/GenerateVersionFromVCS.cmake
20–21

While I agree that repository and then revision makes more sense, the existing get_source_info receives them in the opposite order.

22–24

Nit: Looks like tabs were added?

48–50

Tabs?

51

I would recommend changing the flow a little bit:

  • Remove path argument from append_info. Leave name, revision, and repository.
  • Remove the if(path) get_source_info() endif() part.
  • Change this foreach to the following:
foreach(name IN LISTS NAMES)
  if(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
   set(revision ${${name}_VC_REVISION})
   set(repository ${${name}_VC_REPOSITORY})
  elseif(DEFINED ${name}_SOURCE_DIR)
    get_source_info(${${name}_SOURCE_DIR} revision repository)
  else()
    message(FATAL_ERROR "${name}_SOURCE_DIR is not defined")
  endif()
  append_info(${name} ${revision} ${repository})
endforeach()
This revision now requires changes to proceed.Apr 14 2023, 1:57 PM
zhuhan0 added inline comments.Apr 14 2023, 2:40 PM
llvm/cmake/modules/GenerateVersionFromVCS.cmake
22–24

These are not tabs but spaces. The arrow just means it's further indented.

zhuhan0 added inline comments.Apr 14 2023, 2:52 PM
llvm/cmake/modules/GenerateVersionFromVCS.cmake
51

Looks much better!

zhuhan0 updated this revision to Diff 513753.Apr 14 2023, 2:52 PM

Address comments.

drodriguez accepted this revision.Apr 15 2023, 2:42 PM
This revision is now accepted and ready to land.Apr 15 2023, 2:42 PM
This revision was landed with ongoing or failed builds.Apr 17 2023, 9:50 AM
This revision was automatically updated to reflect the committed changes.

The patch failed a build bot which sets LLVM_APPEND_VC_REV=OFF. Fixed with https://reviews.llvm.org/rGee68f612ba682ddb911c5621e63df56039ec5824.